Skip to content

Commit

Permalink
Fixes #21592 - uses headless chrome instead of phantomjs
Browse files Browse the repository at this point in the history
parent aa3c697
author Sebastian Gräßl <mail@bastilian.me> 1530709547 +0200
committer Ondřej Ezr <oezr@redhat.com> 1557217245 +0200
  • Loading branch information
bastilian authored and tbrisker committed Jul 9, 2019
1 parent 4bfee78 commit 475cdc3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 83 deletions.
65 changes: 20 additions & 45 deletions test/integration/host_js_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,9 @@ class HostJSTest < IntegrationTestWithJavascript
visit new_host_path
select2(original_hostgroup.name, :from => 'host_hostgroup_id')
wait_for_ajax

click_on_inherit('environment')
select2(overridden_hostgroup.name, :from => 'host_hostgroup_id')
wait_for_ajax

environment = find("#s2id_host_environment_id .select2-chosen").text
assert_equal overridden_hostgroup.environment.name, environment
assert page.find('#s2id_host_environment_id .select2-chosen').has_text? overridden_hostgroup.environment.name
end

test 'choosing a hostgroup with compute resource works' do
Expand Down Expand Up @@ -238,7 +234,6 @@ class HostJSTest < IntegrationTestWithJavascript
find(:css, '#host_tab').click
click_on_inherit('compute_profile')
select2(compute_profile.name, :from => 'host_compute_profile_id')
wait_for_ajax

click_link('Virtual Machine')
cpus_field = page.find_field('host_compute_attributes_cpus')
Expand All @@ -262,23 +257,20 @@ class HostJSTest < IntegrationTestWithJavascript
select2 'Location 1', :from => 'host_location_id'
wait_for_ajax
select2 env.name, :from => 'host_environment_id'

click_link 'Operating System'
wait_for_ajax
select2 os.architectures.first.name, :from => 'host_architecture_id'
wait_for_ajax
select2 os.title, :from => 'host_operatingsystem_id'
uncheck('host_build')
wait_for_ajax
select2 os.media.first.name, :from => 'host_medium_id'
wait_for_ajax
select2 os.ptables.first.name, :from => 'host_ptable_id'
fill_in 'host_root_pass', :with => '12345678'

click_link 'Interfaces'
click_button 'Edit'
select2 domains(:unuseddomain).name, :from => 'host_interfaces_attributes_0_domain_id'
wait_for_ajax
fill_in 'host_interfaces_attributes_0_mac', :with => '00:11:11:11:11:11'
wait_for_ajax
fill_in 'host_interfaces_attributes_0_ip', :with => '1.1.1.1'
close_interfaces_modal
click_on_submit
Expand All @@ -302,31 +294,25 @@ class HostJSTest < IntegrationTestWithJavascript
select2 'Location 1', :from => 'host_location_id'
wait_for_ajax
select2 env1.name, :from => 'host_environment_id'
wait_for_ajax
select2 hg.name, :from => 'host_hostgroup_id'
wait_for_ajax

click_link 'Operating System'
wait_for_ajax
select2 os.architectures.first.name, :from => 'host_architecture_id'
wait_for_ajax
select2 os.title, :from => 'host_operatingsystem_id'
uncheck('host_build')
wait_for_ajax

select2 os.media.first.name, :from => 'host_medium_id'
wait_for_ajax
select2 os.ptables.first.name, :from => 'host_ptable_id'
fill_in 'host_root_pass', :with => '12345678'

click_link 'Interfaces'
click_button 'Edit'
select2 domains(:mydomain).name, :from => 'host_interfaces_attributes_0_domain_id'
wait_for_ajax
fill_in 'host_interfaces_attributes_0_mac', :with => '00:11:11:11:11:11'
wait_for_ajax
fill_in 'host_interfaces_attributes_0_ip', :with => '2.3.4.44'
wait_for_ajax

close_interfaces_modal

wait_for_ajax
click_on_submit

host = Host::Managed.search_for('name ~ "myhost1"').first
Expand All @@ -337,11 +323,11 @@ class HostJSTest < IntegrationTestWithJavascript
hostgroup = FactoryBot.create(:hostgroup, :with_parameter)
visit new_host_path
select2(hostgroup.name, :from => 'host_hostgroup_id')
wait_for_ajax

assert page.has_link?('Parameters', :href => '#params')
click_link 'Parameters'
assert page.has_selector?("#inherited_parameters #name_#{hostgroup.group_parameters.first.name}")

assert page.has_selector?("#inherited_parameters #name_#{hostgroup.group_parameters.first.name}", visible: false)
end

test 'new parameters can be edited and removed' do
Expand Down Expand Up @@ -385,7 +371,7 @@ class HostJSTest < IntegrationTestWithJavascript
describe "hosts index multiple actions" do
test 'show action buttons' do
visit hosts_path
page.find('#check_all').trigger('click')
check 'check_all'

# Ensure and wait for all hosts to be checked, and that no unchecked hosts remain
assert page.has_no_selector?('input.host_select_boxes:not(:checked)')
Expand Down Expand Up @@ -414,7 +400,7 @@ class HostJSTest < IntegrationTestWithJavascript

test 'redirect js' do
visit hosts_path
page.find('#check_all').trigger('click')
check 'check_all'

# Ensure and wait for all hosts to be checked, and that no unchecked hosts remain
assert page.has_no_selector?('input.host_select_boxes:not(:checked)')
Expand All @@ -437,7 +423,6 @@ class HostJSTest < IntegrationTestWithJavascript
visit edit_host_path(host)

select2 env1.name, :from => 'host_environment_id'
wait_for_ajax
click_on_submit

host.reload
Expand Down Expand Up @@ -496,19 +481,16 @@ class HostJSTest < IntegrationTestWithJavascript

visit edit_host_path(@host)
select2(original_hostgroup.name, :from => 'host_hostgroup_id')
wait_for_ajax

assert_equal original_hostgroup.puppet_proxy.name, find("#s2id_host_puppet_proxy_id .select2-chosen").text

click_on_inherit('puppet_proxy')
select2(overridden_hostgroup.name, :from => 'host_hostgroup_id')
wait_for_ajax

environment = find("#s2id_host_environment_id .select2-chosen").text
assert_equal original_hostgroup.environment.name, environment
assert find("#s2id_host_environment_id .select2-chosen", visible: false).has_text? original_hostgroup.environment.name

# On host group change, the disabled select will be reset to an empty value
assert_equal '', find("#s2id_host_puppet_proxy_id .select2-chosen").text
assert find("#s2id_host_puppet_proxy_id .select2-chosen", visible: false).has_text? ''
end

test 'class parameters and overrides are displayed correctly for booleans' do
Expand Down Expand Up @@ -542,7 +524,6 @@ class HostJSTest < IntegrationTestWithJavascript

click_link 'Host'
select2(hostgroup2.name, :from => 'host_hostgroup_id')
wait_for_ajax

click_link 'Parameters'
assert page.has_no_selector?("#inherited_parameters #name_#{hostgroup1.group_parameters.first.name}")
Expand Down Expand Up @@ -630,7 +611,6 @@ class HostJSTest < IntegrationTestWithJavascript

subnet_and_domain_are_selected(modal, domain)

wait_for_ajax
modal.find(:button, "Ok").click

assert table.find('td.fqdn').has_content?('name.' + domain.name)
Expand All @@ -640,21 +620,15 @@ class HostJSTest < IntegrationTestWithJavascript
end

test "selecting domain updates subnet list" do
domain = domains(:mydomain)
disable_orchestration
go_to_interfaces_tab

table.first(:button, 'Edit').click

domain = domains(:mydomain)
wait_for_modal
select2 domain.name, :from => 'host_interfaces_attributes_0_domain_id'
subnet_and_domain_are_selected(modal, domain)

subnet_id = modal.find('#host_interfaces_attributes_0_subnet_id',
:visible => false).value
subnet_label = modal.find('#s2id_host_interfaces_attributes_0_subnet_id span.select2-chosen').text

assert_equal '', subnet_id
assert_equal '', subnet_label
assert page.find('#host_interfaces_attributes_0_subnet_id option[selected="selected"]', visible: false).has_text? ""
end

test "selecting domain updates puppetclass parameters" do
Expand All @@ -676,7 +650,6 @@ class HostJSTest < IntegrationTestWithJavascript
table.first(:button, 'Edit').click

select2 domain.name, :from => 'host_interfaces_attributes_0_domain_id'
wait_for_ajax
modal.find(:button, "Ok").click

assert page.has_link?('Parameters', :href => '#params')
Expand Down Expand Up @@ -714,7 +687,9 @@ class HostJSTest < IntegrationTestWithJavascript
add_interface

flag_cols = table.all('td.flags')
flag_cols[1].find('.provision-flag').click
wait_for do
flag_cols[1].find('.provision-flag').click
end

# only one flag switcher is active
table.has_css?('.provision-flag.active', :count => 1)
Expand All @@ -730,7 +705,7 @@ class HostJSTest < IntegrationTestWithJavascript
add_interface

assert_interface_change(-1) do
table.all(:button, "Delete").last.click
table.first('tr:nth-child(2) td:last-child').find('button', :text => 'Delete').click
end
end
end
Expand Down
6 changes: 2 additions & 4 deletions test/integration/shared/host_finders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ def go_to_interfaces_tab

def add_interface
page.find(:button, '+ Add Interface').click

modal = page.find('#interfaceModal')
modal.find(:button, "Ok").click
page.find('#interfaceModal')
close_interfaces_modal
end

def modal
Expand All @@ -24,7 +23,6 @@ def table
end

def assert_interface_change(change, &block)
table = page.find("table#interfaceList")
original_interface_count = table.all('tr', :visible => true).count
yield
assert_equal original_interface_count + change, table.all('tr', :visible => true).count
Expand Down
78 changes: 44 additions & 34 deletions test/integration_test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ENV["RAILS_ENV"] = "test"
require File.expand_path('../config/environment', __dir__)
require 'rails/test_help'
require 'mocha/mini_test'
require 'mocha/minitest'
require 'capybara/rails'
require 'capybara/minitest'
require 'factory_bot_rails'
Expand All @@ -19,33 +19,17 @@
Rails.logger.error("DO NOT IGNORE - Consistent failure - #{klass} #{test_name}")
end

if ENV["JS_TEST_DRIVER"] == 'selenium_chrome'
Selenium::WebDriver::Chrome.driver_path = ENV['TESTDRIVER_PATH'] || File.join(Rails.root, 'node_modules', '.bin', 'chromedriver')
Capybara.register_driver :selenium_chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.args << '--disable-gpu'
options.args << '--no-sandbox'
options.args << '--window-size=1024,768'
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
Capybara.javascript_driver = :selenium_chrome
else
Capybara.register_driver :poltergeist do |app|
opts = {
# To enable debugging uncomment `:inspector => true` and
# add `page.driver.debug` in code to open webkit inspector
# :inspector => true
:js_errors => true,
:timeout => 30,
:extensions => ["#{Rails.root}/test/integration/support/poltergeist_onload_extensions.js"],
:phantomjs => File.join(Rails.root, 'node_modules', '.bin', 'phantomjs')
}
Capybara::Poltergeist::Driver.new(app, opts)
end
Capybara.javascript_driver = :poltergeist
Selenium::WebDriver::Chrome.driver_path = ENV['TESTDRIVER_PATH'] || File.join(Rails.root, 'node_modules', '.bin', 'chromedriver')
Capybara.register_driver :selenium_chrome do |app|
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_TEST'] == '1'
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end

Capybara.default_max_wait_time = 30
Capybara.javascript_driver = ENV["JS_TEST_DRIVER"]&.to_sym || :selenium_chrome
Capybara.default_max_wait_time = 20

class ActionDispatch::IntegrationTest
# Make the Capybara DSL available in all integration tests
Expand All @@ -69,7 +53,7 @@ def assert_index_page(index_path, title_text, new_link_text = nil, has_search =

def assert_new_button(index_path, new_link_text, new_path)
visit index_path
first(:link, new_link_text).click
click_on new_link_text, class: 'btn'
assert_current_path new_path
end

Expand Down Expand Up @@ -109,23 +93,48 @@ def fix_mismatches

def select2(value, attrs)
find("#s2id_#{attrs[:from]}").click
find(".select2-input").set(value)
wait_for { find('.select2-input').visible? rescue false }
wait_for { find(".select2-input").set(value) }
wait_for { find('.select2-results').visible? rescue false }
within ".select2-results" do
wait_for { find(".select2-results span", text: value).visible? rescue false }
find("span", text: value).click
end
wait_for do
page.find("#s2id_#{attrs[:from]} .select2-chosen").has_text? value
end
end

def wait_for_ajax
def wait_for
Timeout.timeout(Capybara.default_max_wait_time) do
sleep 0.15 until ([page.evaluate_script('jQuery.active'), page.evaluate_script('window.axiosActive')] - [0, nil]).empty?
sleep 0.15 until (result = yield)
result
end
end

def wait_for_ajax
wait_for do
([page.evaluate_script('jQuery.active'), page.evaluate_script('window.axiosActive')] - [0, nil]).empty?
end
end

def wait_for_modal
wait_for do
find(:css, '#interfaceModal').visible?
end
end

def wait_for_element(*args)
wait_for do
find(*args).visible? rescue false
end
end

def close_interfaces_modal
click_button 'Ok' # close interfaces
# wait for the dialog to close
Timeout.timeout(Capybara.default_max_wait_time) do
loop while find(:css, '#interfaceModal', :visible => false).visible?
wait_for do
find(:css, '#interfaceModal', visible: false)
end
end

Expand Down Expand Up @@ -239,6 +248,7 @@ def database_cleaner_strategy
end

def login_admin
visit('/users/login') if Capybara.current_driver == :selenium_chrome
SSO.register_method(TestSSO)
visit('/users/login') if Capybara.current_driver == :selenium_chrome
set_request_user(:admin)
Expand Down Expand Up @@ -266,7 +276,7 @@ def database_cleaner_strategy
:truncation
end

def login_admin
def before_setup
Capybara.current_driver = Capybara.javascript_driver
super
end
Expand Down

0 comments on commit 475cdc3

Please sign in to comment.