DEV: Add remove debugging URLs to system spec helper (#29722)

These URLs allow the state of a headless browser to be viewed and debugged using any other browser, without needing to restart the test with `SELENIUM_HEADLESS=0`.
This commit is contained in:
David Taylor 2024-11-13 09:27:48 +00:00 committed by GitHub
parent f1edc20a50
commit 86a2558f5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 4 deletions

View File

@ -1030,6 +1030,7 @@ def apply_base_chrome_options(options)
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--mute-audio")
options.add_argument("--remote-allow-origins=*")
# A file that contains just a list of paths like so:
#

View File

@ -5,11 +5,23 @@ module SystemHelpers
PLATFORM_KEY_MODIFIER = RUBY_PLATFORM =~ /darwin/i ? :meta : :control
def pause_test
result =
ask(
"\n\e[33mTest paused, press enter to resume, type `d` and press enter to start debugger.\e[0m",
)
msg = "Test paused. Press enter to resume, or `d` + enter to start debugger.\n\n"
msg += "Browser inspection URLs:\n"
# Fetch devtools urls
base_url = page.driver.browser.send(:devtools_address)
uri = URI(base_url)
response = Net::HTTP.get(uri.hostname, "/json/list", uri.port)
JSON
.parse(response)
.each do |result|
msg +=
" - (#{result["type"]}) #{base_url}#{result["devtoolsFrontendUrl"]} (#{URI(result["url"]).path})\n"
end
result = ask("\n\e[33m#{msg}\e[0m")
binding.pry if result == "d" # rubocop:disable Lint/Debugger
puts "\e[33mResuming...\e[0m"
self
end