From 38d358fb9a8adf63f9336f45ecb1a14e53c6bc25 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 24 May 2023 18:59:12 +0200 Subject: [PATCH] FIX: flakey spec in sidebar with new font size (#21728) This commit also includes two changes to the rails helper which make tests more consistent on different devices. With this change the failure was reproducible locally and not only on CI: ``` options.add_argument("--force-device-scale-factor=1") ``` The fix itself is quite simple and attempts to find safe click coordinates, the previous solution could fail depending on the size of the sidebar. --- spec/rails_helper.rb | 2 ++ .../system/page_objects/components/sidebar_header_dropdown.rb | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 6e61d24b9cb..076bab8fcc4 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -289,6 +289,7 @@ RSpec.configure do |config| options.add_argument("--no-sandbox") options.add_argument("--disable-dev-shm-usage") options.add_argument("--mute-audio") + options.add_argument("--force-device-scale-factor=1") end Capybara.register_driver :selenium_chrome do |app| @@ -310,6 +311,7 @@ RSpec.configure do |config| options.add_argument("--disable-dev-shm-usage") options.add_emulation(device_name: "iPhone 12 Pro") options.add_argument("--mute-audio") + options.add_argument("--force-device-scale-factor=1") end Capybara.register_driver :selenium_mobile_chrome do |app| diff --git a/spec/system/page_objects/components/sidebar_header_dropdown.rb b/spec/system/page_objects/components/sidebar_header_dropdown.rb index 9f481b5cc8b..d07cbc669c4 100644 --- a/spec/system/page_objects/components/sidebar_header_dropdown.rb +++ b/spec/system/page_objects/components/sidebar_header_dropdown.rb @@ -42,8 +42,8 @@ module PageObjects end def click_outside - dropdown = page.find(SIDEBAR_HAMBURGER_DROPDOWN) - dropdown.click(x: dropdown.rect.width + 1, y: 1) + width = page.evaluate_script("document.body.clientWidth") + page.find("body").click(x: width - 1, y: 1) end end end