Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #36978 - Add possibility to use remote webdriver #9952

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/integration/compute_profile_js_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ComputeProfileJSTest < IntegrationTestWithJavascript
test "create compute profile" do
visit compute_profiles_path()
click_on("Create Compute Profile")
work_around_selenium_file_detector_bug
fill_in('compute_profile_name', :with => 'test')
click_on("Submit")
assert click_link(compute_resources(:ovirt).to_s)
Expand Down
1 change: 1 addition & 0 deletions test/integration/search_bar_js_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class SearchBarTest < IntegrationTestWithJavascript
test "backslash key clicked should opens the search" do
visit bookmarks_path
work_around_selenium_file_detector_bug
# needs to be interactive element
find('table thead').find('a', text: 'Name').send_keys("/")
assert_includes(page.evaluate_script("document.activeElement.classList"), "pf-c-text-input-group__text-input")
Expand Down
67 changes: 59 additions & 8 deletions test/integration_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,63 @@
end

Selenium::WebDriver::Chrome::Service.driver_path = ENV['TESTDRIVER_PATH'] || Foreman::Util.which('chromedriver', Rails.root.join('node_modules', '.bin'))
Capybara.register_driver :selenium_chrome do |app|

javascript_driver = ENV.fetch("JS_TEST_DRIVER") { ENV['DEBUG_JS_TEST'] ? :selenium_chrome : :selenium_chrome_headless }.to_sym

def chrome_options
options = Selenium::WebDriver::Chrome::Options.new
options.args << '--disable-gpu'
options.args << '--no-sandbox'
options.args << '--window-size=1024,768'
options.args << '--headless' unless ENV['DEBUG_JS_TEST'] == '1'
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
options.args += ENV.fetch('ADDITIONAL_CHROME_OPTIONS', '').split(';')
options
end

if javascript_driver == :selenium_chrome_remote
ShowMeTheCookies.register_adapter(:selenium_chrome_remote, ShowMeTheCookies::SeleniumChrome)

Capybara.register_driver :selenium_chrome_remote do |app|
selenium_remote_host = ENV.fetch('SELENIUM_REMOTE_HOST')
selenium_remote_port = ENV.fetch('SELENIUM_REMOTE_PORT', 4444)
Capybara::Selenium::Driver.new(
dosas marked this conversation as resolved.
Show resolved Hide resolved
app,
browser: :remote,
url: "http://#{selenium_remote_host}:#{selenium_remote_port}/wd/hub",
options: chrome_options)
end
elsif javascript_driver == :selenium_chrome_headless
options = chrome_options
options.args << '--headless'
dosas marked this conversation as resolved.
Show resolved Hide resolved
Capybara.register_driver :selenium_chrome_headless do |app|
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
options: options)
end
dosas marked this conversation as resolved.
Show resolved Hide resolved
else
Capybara.register_driver javascript_driver do |app|
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
options: chrome_options)
end
end

Capybara.configure do |config|
config.javascript_driver = ENV["JS_TEST_DRIVER"]&.to_sym || :selenium_chrome
config.default_max_wait_time = 20
config.javascript_driver = javascript_driver
config.default_max_wait_time = 20
config.enable_aria_label = true
if ENV.fetch("JS_TEST_DRIVER", nil) == 'selenium_chrome_remote'
app_host = ENV.fetch('APP_SERVER_HOST') do
Socket.ip_address_list
.find(&:ipv4_private?)
.ip_address
end
app_port = ENV.fetch('APP_SERVER_PORT', "8080")
dosas marked this conversation as resolved.
Show resolved Hide resolved
config.server_port = app_port
# application server
config.server_host = "0.0.0.0"
# address used by selenium host to connect to application server
config.app_host = "http://#{app_host}:#{app_port}"
dosas marked this conversation as resolved.
Show resolved Hide resolved
end
end

class ActionDispatch::IntegrationTest
Expand All @@ -47,6 +92,12 @@ class << self
# Stop ActiveRecord from wrapping tests in transactions
self.use_transactional_tests = false

# see: https://stackoverflow.com/questions/70441796/selenium-webdriver-for-aws-device-farm-error-when-sending-period-keystroke-t

def work_around_selenium_file_detector_bug
page.driver.browser.file_detector = nil if page.driver.browser.respond_to?(:file_detector=)
end

def assert_index_page(index_path, title_text, new_link_text = nil, has_search = true, has_pagination = true)
visit index_path
assert_breadcrumb_text(title_text)
Expand Down Expand Up @@ -299,7 +350,7 @@ def database_cleaner_strategy
end

def login_admin
visit('/users/login') if Capybara.current_driver == :selenium_chrome
visit('/users/login') if Capybara.current_driver.to_s.include? "selenium"
SSO.register_method(TestSSO)
set_request_user(:admin)
end
Expand Down
6 changes: 5 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
FactoryBot.use_parent_strategy = false

# Do not allow network connections and external processes
WebMock.disable_net_connect!(allow_localhost: true)
if ENV.fetch('SELENIUM_REMOTE_HOST', nil)
WebMock.disable_net_connect!(allow_localhost: true, allow: ENV['SELENIUM_REMOTE_HOST'])
else
WebMock.disable_net_connect!(allow_localhost: true)
end

# Configure shoulda
Shoulda::Matchers.configure do |config|
Expand Down
Loading