Skip to content

Commit cbffbee

Browse files
authored
DEV: allows to set timezone and color scheme (#33144)
As defined in: https://playwright.dev/docs/emulation Example: ```ruby context "xxxx", color_scheme: "dark", timezone: "Australia/Brisbane" do # ... end ```
1 parent 7227d71 commit cbffbee

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

spec/rails_helper.rb

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -457,47 +457,6 @@ def synchronize(seconds = nil, errors: nil)
457457
end
458458
end
459459

460-
driver_options = {
461-
browser_type: :chromium,
462-
channel: :chromium,
463-
headless: (ENV["PLAYWRIGHT_HEADLESS"].presence || ENV["SELENIUM_HEADLESS"].presence) != "0",
464-
args: apply_base_chrome_args,
465-
acceptDownloads: true,
466-
downloadsPath: Downloads::FOLDER,
467-
slowMo: ENV["PLAYWRIGHT_SLOW_MO_MS"].to_i, # https://playwright.dev/docs/api/class-browsertype#browser-type-launch-option-slow-mo
468-
playwright_cli_executable_path: "./node_modules/.bin/playwright",
469-
logger: Logger.new(IO::NULL),
470-
}
471-
472-
if ENV["CAPYBARA_REMOTE_DRIVER_URL"].present?
473-
driver_options[:browser] = :remote
474-
driver_options[:url] = ENV["CAPYBARA_REMOTE_DRIVER_URL"]
475-
end
476-
477-
Capybara.register_driver(:playwright_chrome) do |app|
478-
Capybara::Playwright::Driver.new(
479-
app,
480-
**driver_options,
481-
viewport: ENV["PLAYWRIGHT_NO_VIEWPORT"] == "1" ? nil : { width: 1400, height: 1400 },
482-
)
483-
end
484-
485-
Capybara.register_driver(:playwright_mobile_chrome) do |app|
486-
Capybara::Playwright::Driver.new(
487-
app,
488-
**driver_options,
489-
deviceScaleFactor: 3,
490-
isMobile: true,
491-
hasTouch: true,
492-
userAgent:
493-
"Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.4 Mobile/15E148 Safari/604.1",
494-
defaultBrowserType: "webkit",
495-
viewport: ENV["PLAYWRIGHT_NO_VIEWPORT"] == "1" ? nil : { width: 390, height: 664 },
496-
)
497-
end
498-
499-
Capybara.default_driver = :playwright_chrome
500-
501460
[
502461
[PostAction, :post_action_type_id],
503462
[Reviewable, :target_id],
@@ -682,6 +641,49 @@ def using_session_with_localhost_resolution(name, &block)
682641
system_tests_initialized = true
683642
end
684643

644+
driver_options = {
645+
browser_type: :chromium,
646+
channel: :chromium,
647+
headless: (ENV["PLAYWRIGHT_HEADLESS"].presence || ENV["SELENIUM_HEADLESS"].presence) != "0",
648+
args: apply_base_chrome_args,
649+
acceptDownloads: true,
650+
downloadsPath: Downloads::FOLDER,
651+
slowMo: ENV["PLAYWRIGHT_SLOW_MO_MS"].to_i, # https://playwright.dev/docs/api/class-browsertype#browser-type-launch-option-slow-mo
652+
playwright_cli_executable_path: "./node_modules/.bin/playwright",
653+
logger: Logger.new(IO::NULL),
654+
timezoneId: example.metadata[:timezone],
655+
colorScheme: example.metadata[:color_scheme],
656+
}
657+
658+
if ENV["CAPYBARA_REMOTE_DRIVER_URL"].present?
659+
driver_options[:browser] = :remote
660+
driver_options[:url] = ENV["CAPYBARA_REMOTE_DRIVER_URL"]
661+
end
662+
663+
Capybara.register_driver(:playwright_mobile_chrome) do |app|
664+
Capybara::Playwright::Driver.new(
665+
app,
666+
**driver_options,
667+
deviceScaleFactor: 3,
668+
isMobile: true,
669+
hasTouch: true,
670+
userAgent:
671+
"Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.4 Mobile/15E148 Safari/604.1",
672+
defaultBrowserType: "webkit",
673+
viewport: ENV["PLAYWRIGHT_NO_VIEWPORT"] == "1" ? nil : { width: 390, height: 664 },
674+
)
675+
end
676+
677+
Capybara.register_driver(:playwright_chrome) do |app|
678+
Capybara::Playwright::Driver.new(
679+
app,
680+
**driver_options,
681+
viewport: ENV["PLAYWRIGHT_NO_VIEWPORT"] == "1" ? nil : { width: 1400, height: 1400 },
682+
)
683+
end
684+
685+
Capybara.default_driver = :playwright_chrome
686+
685687
driver = [:playwright]
686688
driver << :mobile if example.metadata[:mobile]
687689
driver << :chrome

0 commit comments

Comments
 (0)