DEV: adds native support for mobile in system tests (#19400)

Will make your test run in an emulated iPhone 12 Pro view. It means you can now use `click(delay: 0.5)` to emulate some long press or that `mobile_view=1` will be set automatically.

Usage:

```
it "works", mobile: true do
  visit("/")
end
```

Note: `window-size=390,950` is different than native iPhone 12 Pro size, but due to minimum browser size and the automated browser alert at the top of the view, this was the best size I could find.
This commit is contained in:
Joffrey JAFFEUX 2022-12-11 23:12:33 +01:00 committed by GitHub
parent 6e48f5acb5
commit c9197cf9d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 3 deletions

View File

@ -280,6 +280,33 @@ RSpec.configure do |config|
)
end
mobile_chrome_browser_options =
Selenium::WebDriver::Chrome::Options
.new(logging_prefs: { "browser" => "ALL", "driver" => "ALL" })
.tap do |options|
options.add_argument("--window-size=390,950")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_emulation(device_name: "iPhone 12 Pro")
end
Capybara.register_driver :selenium_mobile_chrome do |app|
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
capabilities: mobile_chrome_browser_options,
)
end
Capybara.register_driver :selenium_mobile_chrome_headless do |app|
mobile_chrome_browser_options.add_argument("--headless")
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
capabilities: mobile_chrome_browser_options,
)
end
if ENV['ELEVATED_UPLOADS_ID']
DB.exec "SELECT setval('uploads_id_seq', 10000)"
else
@ -342,9 +369,11 @@ RSpec.configure do |config|
last_driven_by = nil
config.before(:each, type: :system) do |example|
if example.metadata[:js]
driver = "selenium_chrome"
driver += "_headless" unless ENV["SELENIUM_HEADLESS"] == "0"
driven_by driver.to_sym
driver = [:selenium]
driver << :mobile if example.metadata[:mobile]
driver << :chrome
driver << :headless unless ENV["SELENIUM_HEADLESS"] == "0"
driven_by driver.join("_").to_sym
end
setup_system_test
end