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:
parent
6e48f5acb5
commit
c9197cf9d8
|
@ -280,6 +280,33 @@ RSpec.configure do |config|
|
||||||
)
|
)
|
||||||
end
|
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']
|
if ENV['ELEVATED_UPLOADS_ID']
|
||||||
DB.exec "SELECT setval('uploads_id_seq', 10000)"
|
DB.exec "SELECT setval('uploads_id_seq', 10000)"
|
||||||
else
|
else
|
||||||
|
@ -342,9 +369,11 @@ RSpec.configure do |config|
|
||||||
last_driven_by = nil
|
last_driven_by = nil
|
||||||
config.before(:each, type: :system) do |example|
|
config.before(:each, type: :system) do |example|
|
||||||
if example.metadata[:js]
|
if example.metadata[:js]
|
||||||
driver = "selenium_chrome"
|
driver = [:selenium]
|
||||||
driver += "_headless" unless ENV["SELENIUM_HEADLESS"] == "0"
|
driver << :mobile if example.metadata[:mobile]
|
||||||
driven_by driver.to_sym
|
driver << :chrome
|
||||||
|
driver << :headless unless ENV["SELENIUM_HEADLESS"] == "0"
|
||||||
|
driven_by driver.join("_").to_sym
|
||||||
end
|
end
|
||||||
setup_system_test
|
setup_system_test
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue