mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
Enable selenium service in devcontainer for system tests (#1340)
Co-authored-by: Pedro J. Aramburu <pedro@joakin.dev>
This commit is contained in:
committed by
GitHub
parent
246cd00cbb
commit
616c363b3e
@@ -1,11 +1,38 @@
|
||||
require "test_helper"
|
||||
require "socket"
|
||||
|
||||
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
||||
setup do
|
||||
Capybara.default_max_wait_time = 5
|
||||
|
||||
if ENV["SELENIUM_REMOTE_URL"].present?
|
||||
server_port = ENV.fetch("CAPYBARA_SERVER_PORT", 30_000 + (Process.pid % 1000)).to_i
|
||||
app_host = ENV["CAPYBARA_APP_HOST"].presence || IPSocket.getaddress(Socket.gethostname)
|
||||
|
||||
Capybara.server_host = "0.0.0.0"
|
||||
Capybara.server_port = server_port
|
||||
Capybara.always_include_port = true
|
||||
Capybara.app_host = "http://#{app_host}:#{server_port}"
|
||||
end
|
||||
end
|
||||
|
||||
driven_by :selenium, using: ENV["CI"].present? ? :headless_chrome : ENV.fetch("E2E_BROWSER", :chrome).to_sym, screen_size: [ 1400, 1400 ]
|
||||
if ENV["SELENIUM_REMOTE_URL"].present?
|
||||
Capybara.register_driver :selenium_remote_chrome do |app|
|
||||
options = Selenium::WebDriver::Chrome::Options.new
|
||||
options.add_argument("--window-size=1400,1400")
|
||||
|
||||
Capybara::Selenium::Driver.new(
|
||||
app,
|
||||
browser: :remote,
|
||||
url: ENV["SELENIUM_REMOTE_URL"],
|
||||
capabilities: options
|
||||
)
|
||||
end
|
||||
|
||||
driven_by :selenium_remote_chrome, screen_size: [ 1400, 1400 ]
|
||||
else
|
||||
driven_by :selenium, using: ENV["CI"].present? ? :headless_chrome : ENV.fetch("E2E_BROWSER", :chrome).to_sym, screen_size: [ 1400, 1400 ]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ class SettingsTest < ApplicationSystemTestCase
|
||||
click_button "Generate new code"
|
||||
assert_selector 'span[data-clipboard-target="source"]', visible: true, count: 1 # invite code copy widget
|
||||
copy_button = find('button[data-action="clipboard#copy"]', match: :first) # Find the first copy button (adjust if needed)
|
||||
page.execute_script("Object.defineProperty(navigator, 'clipboard', { value: { writeText: () => Promise.resolve() }, writable: true, configurable: true })") # Mock clipboard API due to browser security restrictions in tests
|
||||
copy_button.click
|
||||
assert_selector 'span[data-clipboard-target="iconSuccess"]', visible: true, count: 1 # text copied and icon changed to checkmark
|
||||
end
|
||||
|
||||
@@ -23,11 +23,26 @@ require "minitest/autorun"
|
||||
require "mocha/minitest"
|
||||
require "aasm/minitest"
|
||||
require "webmock/minitest"
|
||||
require "uri"
|
||||
|
||||
VCR.configure do |config|
|
||||
config.cassette_library_dir = "test/vcr_cassettes"
|
||||
config.hook_into :webmock
|
||||
config.ignore_localhost = true
|
||||
config.ignore_request do |request|
|
||||
selenium_remote_url = ENV["SELENIUM_REMOTE_URL"]
|
||||
next false if selenium_remote_url.blank?
|
||||
|
||||
request_uri = URI(request.uri)
|
||||
selenium_uri = URI(selenium_remote_url)
|
||||
|
||||
request_uri.host.present? &&
|
||||
selenium_uri.host.present? &&
|
||||
request_uri.host == selenium_uri.host &&
|
||||
request_uri.port == selenium_uri.port
|
||||
rescue URI::InvalidURIError
|
||||
false
|
||||
end
|
||||
config.default_cassette_options = { erb: true }
|
||||
config.filter_sensitive_data("<OPENAI_ACCESS_TOKEN>") { ENV["OPENAI_ACCESS_TOKEN"] }
|
||||
config.filter_sensitive_data("<OPENAI_ORGANIZATION_ID>") { ENV["OPENAI_ORGANIZATION_ID"] }
|
||||
|
||||
Reference in New Issue
Block a user