diff --git a/package.json b/package.json index 27e35eea260..39c01660a46 100644 --- a/package.json +++ b/package.json @@ -63,8 +63,7 @@ "webpack-stats-plugin": "^0.1.5" }, "optionalDependencies": { - "phantomjs-prebuilt": "^2.1.0", - "chromedriver": "2.43.0" + "chromedriver": "2.46.0" }, "dependencies": { "@novnc/novnc": "^1.0.0", diff --git a/test/integration/breadcrumbs_switcher_test.rb b/test/integration/breadcrumbs_switcher_test.rb index 30ce79c4b1b..b7684b29c07 100644 --- a/test/integration/breadcrumbs_switcher_test.rb +++ b/test/integration/breadcrumbs_switcher_test.rb @@ -19,8 +19,7 @@ class BreadcrumbsSwitcherTest < IntegrationTestWithJavascript click_button 'switcher' fill_in('breadcrumbs-search', :with => 'three') wait_for_ajax - all_items = page.all('.no-border.list-group-item') - assert all_items.count == 1 - assert_equal all_items[0].text, 'three' + page.assert_selector('.no-border.list-group-item', count: 1) + page.assert_selector('.no-border.list-group-item', text: 'three') end end diff --git a/test/integration/dashboard_test.rb b/test/integration/dashboard_test.rb index 9972e2ed4d1..23c5b1e7fd9 100644 --- a/test/integration/dashboard_test.rb +++ b/test/integration/dashboard_test.rb @@ -60,14 +60,8 @@ def visit_dashboard test 'has no out of sync link' do visit_dashboard within "li[data-name='Host Configuration Status for Puppet']" do - refute page.has_link?('Out of sync hosts') - end - end - - test 'good hosts link drops time' do - visit_dashboard - within "li[data-name='Host Configuration Status for Puppet']" do - refute page.has_link?('Good host reports in the last') + assert page.has_no_link?('Out of sync hosts') + assert page.has_no_link?('Good host reports in the last') assert page.has_link?('Good host with reports') end end diff --git a/test/integration/host_js_test.rb b/test/integration/host_js_test.rb index d672b4aa6f9..1e79923370b 100644 --- a/test/integration/host_js_test.rb +++ b/test/integration/host_js_test.rb @@ -225,7 +225,7 @@ class HostJSTest < IntegrationTestWithJavascript cpus_field = page.find_field('host_compute_attributes_cpus') assert_equal '1', cpus_field.value - click_link('Interfaces') + switch_form_tab_to_interfaces click_button('Edit') ipv4_field = page.find_field('host_interfaces_attributes_0_ip') refute_empty ipv4_field.value @@ -239,7 +239,7 @@ class HostJSTest < IntegrationTestWithJavascript cpus_field = page.find_field('host_compute_attributes_cpus') assert_equal '2', cpus_field.value - click_link('Interfaces') + switch_form_tab_to_interfaces click_button('Edit') bridge_field = page.find_field('host_interfaces_attributes_0_compute_attributes_bridge') assert_equal 'test', bridge_field.value @@ -267,7 +267,7 @@ class HostJSTest < IntegrationTestWithJavascript select2 os.ptables.first.name, :from => 'host_ptable_id' fill_in 'host_root_pass', :with => '12345678' - click_link 'Interfaces' + switch_form_tab_to_interfaces click_button 'Edit' select2 domains(:unuseddomain).name, :from => 'host_interfaces_attributes_0_domain_id' fill_in 'host_interfaces_attributes_0_mac', :with => '00:11:11:11:11:11' @@ -295,6 +295,7 @@ class HostJSTest < IntegrationTestWithJavascript wait_for_ajax select2 env1.name, :from => 'host_environment_id' select2 hg.name, :from => 'host_hostgroup_id' + wait_for_ajax click_link 'Operating System' select2 os.architectures.first.name, :from => 'host_architecture_id' @@ -305,7 +306,7 @@ class HostJSTest < IntegrationTestWithJavascript select2 os.ptables.first.name, :from => 'host_ptable_id' fill_in 'host_root_pass', :with => '12345678' - click_link 'Interfaces' + switch_form_tab_to_interfaces click_button 'Edit' select2 domains(:mydomain).name, :from => 'host_interfaces_attributes_0_domain_id' fill_in 'host_interfaces_attributes_0_mac', :with => '00:11:11:11:11:11' @@ -324,10 +325,12 @@ class HostJSTest < IntegrationTestWithJavascript 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}", visible: false) + assert page.has_selector?("#inherited_parameters #name_#{hostgroup.group_parameters.first.name}") end test 'new parameters can be edited and removed' do @@ -382,7 +385,7 @@ class HostJSTest < IntegrationTestWithJavascript assert multiple_actions_div.find('ul').visible? # Hosts are added to cookie - host_ids_on_cookie = JSON.parse(CGI.unescape(page.driver.cookies['_ForemanSelectedhosts'].value)) + host_ids_on_cookie = JSON.parse(CGI.unescape(get_me_the_cookie('_ForemanSelectedhosts')&.fetch(:value))) assert(host_ids_on_cookie.include?(@host.id)) # Open modal box @@ -395,7 +398,7 @@ class HostJSTest < IntegrationTestWithJavascript # remove hosts cookie on submit index_modal.find('.btn-primary').click assert_current_path hosts_path - assert_empty(page.driver.cookies['_ForemanSelectedhosts']) + assert_empty(get_me_the_cookie('_ForemanSelectedhosts')) end test 'redirect js' do @@ -406,7 +409,7 @@ class HostJSTest < IntegrationTestWithJavascript assert page.has_no_selector?('input.host_select_boxes:not(:checked)') # Hosts are added to cookie - host_ids_on_cookie = JSON.parse(CGI.unescape(page.driver.cookies['_ForemanSelectedhosts'].value)) + host_ids_on_cookie = JSON.parse(CGI.unescape(get_me_the_cookie('_ForemanSelectedhosts')&.fetch(:value))) assert(host_ids_on_cookie.include?(@host.id)) page.execute_script("tfm.hosts.table.buildRedirect('#{select_multiple_environment_hosts_path}')") @@ -482,15 +485,15 @@ class HostJSTest < IntegrationTestWithJavascript visit edit_host_path(@host) select2(original_hostgroup.name, :from => 'host_hostgroup_id') - assert_equal original_hostgroup.puppet_proxy.name, find("#s2id_host_puppet_proxy_id .select2-chosen").text + 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') - assert find("#s2id_host_environment_id .select2-chosen", visible: false).has_text? original_hostgroup.environment.name + assert find('#s2id_host_environment_id .select2-chosen').has_text? original_hostgroup.environment.name - # On host group change, the disabled select will be reset to an empty value - assert find("#s2id_host_puppet_proxy_id .select2-chosen", visible: false).has_text? '' + # On host group change, the disabled select will be reset to an empty value - disabled select2 is invisible on chrome + assert find('#s2id_host_puppet_proxy_id .select2-chosen', visible: :all).has_text? '' end test 'class parameters and overrides are displayed correctly for booleans' do @@ -646,7 +649,7 @@ class HostJSTest < IntegrationTestWithJavascript click_link 'Parameters' assert_equal class_params.find("textarea").value, "default" - click_link 'Interfaces' + switch_form_tab_to_interfaces table.first(:button, 'Edit').click select2 domain.name, :from => 'host_interfaces_attributes_0_domain_id' @@ -738,12 +741,21 @@ class HostJSTest < IntegrationTestWithJavascript private + def switch_form_tab_to_interfaces + switch_form_tab('Interfaces') + disable_interface_modal_animation + end + def subnet_and_domain_are_selected(modal, domain) - modal.has_select?('host_interfaces_attributes_0_subnet_id', - :visible => false, - :options => domain.subnets.map(&:to_label)) - modal.has_select?('host_interfaces_attributes_0_domain_id', - :visible => false, - :selected => domain.name) + modal.assert_selector("#interfaceModal #s2id_host_interfaces_attributes_0_domain_id .select2-chosen", + text: domain.name) + modal.assert_selector('#interfaceModal #host_interfaces_attributes_0_subnet_id option', + visible: false, + count: domain.subnets.count + 1) # plus one empty + domain.subnets.each do |subnet| + modal.assert_selector('#interfaceModal #host_interfaces_attributes_0_subnet_id option', + visible: false, + text: subnet.to_label) + end end end diff --git a/test/integration/host_test.rb b/test/integration/host_test.rb index 6019d46c71c..904e4ecab8d 100644 --- a/test/integration/host_test.rb +++ b/test/integration/host_test.rb @@ -120,7 +120,7 @@ class HostIntegrationTest < ActionDispatch::IntegrationTest test 'build mode is not enabled for unmanaged hosts' do host = FactoryBot.create(:host) visit clone_host_path(host) - refute page.has_checked_field?('host_build') + assert page.has_no_checked_field?('host_build') end end end diff --git a/test/integration/notifications_drawer_test.rb b/test/integration/notifications_drawer_test.rb index 6740a8048df..4fb8429dd53 100644 --- a/test/integration/notifications_drawer_test.rb +++ b/test/integration/notifications_drawer_test.rb @@ -46,14 +46,8 @@ def notifications_open_and_close_flow def navigate_somewhere_with_turbolinks # check the outside click with turbolinks - page.find('a.navbar-brand').trigger('click') - - wait_for_turbolinks - end - - def wait_for_turbolinks - Timeout.timeout(Capybara.default_max_wait_time) do - loop until page.has_no_selector?('div.spinner') - end + page.find('a.navbar-brand').click + # wait for loader to dissapear + page.has_no_selector?('div.spinner') end end diff --git a/test/integration/org_admin_js_test.rb b/test/integration/org_admin_js_test.rb index 05f99d496de..c97de09e713 100644 --- a/test/integration/org_admin_js_test.rb +++ b/test/integration/org_admin_js_test.rb @@ -2,8 +2,6 @@ class OrgAdminJSTest < IntegrationTestWithJavascript setup do - Capybara.ignore_hidden_elements = false - @org1 = FactoryBot.create(:organization) @org2 = FactoryBot.create(:organization) @org3 = FactoryBot.create(:organization) @@ -21,10 +19,6 @@ class OrgAdminJSTest < IntegrationTestWithJavascript @org_admin_of_org1 = clone_role(@org_admin, @org1) end - teardown do - Capybara.ignore_hidden_elements = true - end - context "user is org admin of single org" do def setup @user.organizations << @org1 @@ -48,28 +42,30 @@ def test_org_admins_can_work_with_resources_in_their_organization assert_form_tab('Locations') assert_form_tab('Organizations') - within('#domain_organization_ids') do + domain = FactoryBot.build_stubbed(:domain) + page.fill_in 'domain[name]', :with => domain.name, :id => 'domain_name' + + switch_form_tab('Locations') + within('#ms-domain_location_ids') do + assert page.has_content? @loc1.name + assert page.has_content? @loc2.name + assert page.has_content? @loc3.name + end + select_option_of_multiselect(@loc1.name, select_id: 'domain_location_ids') + select_option_of_multiselect(@loc2.name, select_id: 'domain_location_ids') + + switch_form_tab('Organizations') + within('#ms-domain_organization_ids') do assert page.has_content? @org1.name assert page.has_no_content? @org2.name assert page.has_no_content? @org3.name # current organization is selected - within('option[selected="selected"]') do + within('.ms-selection') do assert page.has_content? @org1.name end end - within('#domain_location_ids') do - assert page.has_content? @loc1.name - assert page.has_content? @loc2.name - assert page.has_content? @loc3.name - end - - domain = FactoryBot.build_stubbed(:domain) - page.fill_in 'domain[name]', :with => domain.name, :id => 'domain_name' - location_selector = page.find('select#domain_location_ids') - location_selector.select @loc1.name - location_selector.select @loc2.name page.click_button 'Submit' within "#domains_list" do @@ -90,12 +86,13 @@ def test_org_admin_tries_to_create_domain_when_unselect_the_organization domain = FactoryBot.build_stubbed(:domain) page.fill_in 'domain[name]', :with => domain.name, :id => 'domain_name' - organization_selector = page.find('select#domain_organization_ids') - organization_selector.unselect @org1.name - location_selector = page.find('select#domain_location_ids') - location_selector.select @loc1.name - location_selector.select @loc2.name + switch_form_tab('Locations') + select_option_of_multiselect(@loc1.name, select_id: 'domain_location_ids') + select_option_of_multiselect(@loc2.name, select_id: 'domain_location_ids') + + switch_form_tab('Organizations') + ensure_selected_option_of_multiselect(@org1.name, select_id: 'domain_organization_ids') page.click_button 'Submit' created_domain = Domain.unscoped.find_by_name(domain.name) @@ -111,12 +108,12 @@ def test_org_admins_can_not_assign_location_which_they_do_not_belong_to domain = FactoryBot.build_stubbed(:domain) page.fill_in 'domain[name]', :with => domain.name, :id => 'domain_name' - organization_selector = page.find('select#domain_organization_ids') - organization_selector.unselect @org1.name + switch_form_tab('Organizations') + ensure_selected_option_of_multiselect(@org1.name, select_id: 'domain_organization_ids') - location_selector = page.find('select#domain_location_ids') # once selection are driven by permissions only, this should not be possible - location_selector.select @loc3.name + switch_form_tab('Locations') + select_option_of_multiselect(@loc3.name, select_id: 'domain_location_ids') page.click_button 'Submit' # this is partly buggy behavior based on fact user does not belong to location @@ -150,30 +147,30 @@ def test_org_admins_can_work_with_resources_in_their_organization assert_form_tab('Locations') assert_form_tab('Organizations') - within('#domain_organization_ids') do + domain = FactoryBot.build_stubbed(:domain) + page.fill_in 'domain[name]', :with => domain.name, :id => 'domain_name' + + switch_form_tab('Organizations') + within('#ms-domain_organization_ids') do assert page.has_content? @org1.name assert page.has_content? @org2.name assert page.has_no_content? @org3.name # current context is any organization - assert page.has_no_content?('option[selected="selected"]') + assert page.has_no_content?('.ms-selection span') end + select_option_of_multiselect(@org1.name, select_id: 'domain_organization_ids') + select_option_of_multiselect(@org2.name, select_id: 'domain_organization_ids') - within('#domain_location_ids') do + switch_form_tab('Locations') + within('#ms-domain_location_ids') do assert page.has_content? @loc1.name assert page.has_content? @loc2.name assert page.has_content? @loc3.name end + select_option_of_multiselect(@loc1.name, select_id: 'domain_location_ids') + select_option_of_multiselect(@loc2.name, select_id: 'domain_location_ids') - domain = FactoryBot.build_stubbed(:domain) - page.fill_in 'domain[name]', :with => domain.name, :id => 'domain_name' - organization_selector = page.find('select#domain_organization_ids') - organization_selector.select @org1.name - organization_selector.select @org2.name - - location_selector = page.find('select#domain_location_ids') - location_selector.select @loc1.name - location_selector.select @loc2.name page.click_button 'Submit' within "#domains_list" do @@ -184,7 +181,7 @@ def test_org_admins_can_work_with_resources_in_their_organization assert page.has_no_content?(@invisible_domain_2.name) end - select_org(@org1) + select_organization(@org1.name) wait_for_ajax within "#domains_list" do @@ -195,7 +192,7 @@ def test_org_admins_can_work_with_resources_in_their_organization assert page.has_no_content?(@invisible_domain_2.name) end - select_org(@org2.name) + select_organization(@org2.name) within "#domains_list" do assert page.has_link?(domain.name) assert page.has_no_content?(@visible_domain_1.name) @@ -214,8 +211,8 @@ def test_org_admin_tries_to_create_resource_without_organization_selection domain = FactoryBot.build_stubbed(:domain) page.fill_in 'domain[name]', :with => domain.name, :id => 'domain_name' - location_selector = page.find('select#domain_location_ids') - location_selector.select @loc1.name + switch_form_tab('Locations') + select_option_of_multiselect(@loc1.name, select_id: 'domain_location_ids') page.click_button 'Submit' assert page.has_content?("Invalid organizations selection, you must select at least one of yours and have 'assign_organizations' permission") @@ -249,7 +246,11 @@ def test_org_admins_of_two_orgs_can_work_with_resources_in_their_organizations assert_form_tab('Locations') assert_form_tab('Organizations') - within('#domain_organization_ids') do + domain = FactoryBot.build_stubbed(:domain) + page.fill_in 'domain[name]', :with => domain.name, :id => 'domain_name' + + switch_form_tab('Organizations') + within('#ms-domain_organization_ids') do assert page.has_content? @org1.name assert page.has_content? @org2.name assert page.has_no_content? @org3.name @@ -257,22 +258,18 @@ def test_org_admins_of_two_orgs_can_work_with_resources_in_their_organizations # current context is any organization assert page.has_no_content?('option[selected="selected"]') end + select_option_of_multiselect(@org1.name, select_id: 'domain_organization_ids') + select_option_of_multiselect(@org2.name, select_id: 'domain_organization_ids') - within('#domain_location_ids') do + switch_form_tab('Locations') + within('#ms-domain_location_ids') do assert page.has_content? @loc1.name assert page.has_content? @loc2.name assert page.has_content? @loc3.name end + select_option_of_multiselect(@loc1.name, select_id: 'domain_location_ids') + select_option_of_multiselect(@loc2.name, select_id: 'domain_location_ids') - domain = FactoryBot.build_stubbed(:domain) - page.fill_in 'domain[name]', :with => domain.name, :id => 'domain_name' - organization_selector = page.find('select#domain_organization_ids') - organization_selector.select @org1.name - organization_selector.select @org2.name - - location_selector = page.find('select#domain_location_ids') - location_selector.select @loc1.name - location_selector.select @loc2.name page.click_button 'Submit' within "#domains_list" do @@ -283,7 +280,7 @@ def test_org_admins_of_two_orgs_can_work_with_resources_in_their_organizations assert page.has_no_content?(@invisible_domain_2.name) end - select_org(@org1.name) + select_organization(@org1.name) within "#domains_list" do assert page.has_link?(domain.name) assert page.has_link?(@visible_domain_1.name) @@ -292,7 +289,7 @@ def test_org_admins_of_two_orgs_can_work_with_resources_in_their_organizations assert page.has_no_content?(@invisible_domain_2.name) end - select_org(@org2.name) + select_organization(@org2.name) within "#domains_list" do assert page.has_link?(domain.name) assert page.has_no_content?(@visible_domain_1.name) @@ -333,53 +330,52 @@ def test_org_admins_can_assign_resources_to_both_orgs_but_cant_switch_to_its_con assert_form_tab('Locations') assert_form_tab('Organizations') - within('#domain_organization_ids') do - assert page.has_content? @org1.name - assert page.has_content? @org2.name - assert page.has_content? @org3.name - - # current context is any organization - assert page.has_no_content?('option[selected="selected"]') - end + domain = FactoryBot.build_stubbed(:domain) + page.fill_in 'domain[name]', :with => domain.name, :id => 'domain_name' - within('#domain_location_ids') do + switch_form_tab('Locations') + within('#ms-domain_location_ids') do assert page.has_content? @loc1.name assert page.has_content? @loc2.name assert page.has_content? @loc3.name end + select_option_of_multiselect(@loc1.name, select_id: 'domain_location_ids') + select_option_of_multiselect(@loc2.name, select_id: 'domain_location_ids') - domain = FactoryBot.build_stubbed(:domain) - page.fill_in 'domain[name]', :with => domain.name, :id => 'domain_name' + switch_form_tab('Organizations') + within('#ms-domain_organization_ids') do + assert page.has_content? @org1.name + assert page.has_content? @org2.name + assert page.has_content? @org3.name - location_selector = page.find('select#domain_location_ids') - location_selector.select @loc1.name - location_selector.select @loc2.name + # current context is any organization + assert page.has_no_content?('option[selected="selected"]') + end + # select_option_of_multiselect(@org1.name, select_id: 'domain_organization_ids') + select_option_of_multiselect(@org2.name, select_id: 'domain_organization_ids') - organization_selector = page.find('select#domain_organization_ids') - # organization_selector.select @org1.name - organization_selector.select @org2.name page.click_button 'Submit' # choosing only org that user does not belong to is forbidden assert page.has_content?("You don't have permission create_domains with attributes that you have specified or you don't have access to specified organizations or locations") + switch_form_tab('Organizations') # with org1 which user belongs to, submit passes but the organization selection is limited to user's list - organization_selector = page.find('select#domain_organization_ids') - organization_selector.select @org1.name + select_option_of_multiselect(@org1.name, select_id: 'domain_organization_ids') page.click_button 'Submit' within "#domains_list" do assert page.has_link?(domain.name) end - select_org(@org3.name) + select_organization(@org3.name) within "#domains_list" do assert page.has_no_content?(domain.name) end refute_available_organization(@org2.name) - select_org(@org1.name) + select_organization(@org1.name) within "#domains_list" do assert page.has_link?(domain.name) end @@ -418,30 +414,29 @@ def test_org_admins_can_assign_resources_to_both_orgs_but_cant_switch_to_its_con assert_form_tab('Locations') assert_form_tab('Organizations') - within('#domain_organization_ids') do - assert page.has_content? @org1.name - assert page.has_content? @org2.name - end - domain = FactoryBot.build_stubbed(:domain) page.fill_in 'domain[name]', :with => domain.name, :id => 'domain_name' - location_selector = page.find('select#domain_location_ids') - location_selector.select @loc1.name - location_selector.select @loc2.name + switch_form_tab('Locations') + select_option_of_multiselect(@loc1.name, select_id: 'domain_location_ids') + select_option_of_multiselect(@loc2.name, select_id: 'domain_location_ids') - organization_selector = page.find('select#domain_organization_ids') - organization_selector.select @org1.name - organization_selector.select @org2.name + switch_form_tab('Organizations') + within('#ms-domain_organization_ids') do + assert page.has_content? @org1.name + assert page.has_content? @org2.name + end + select_option_of_multiselect(@org1.name, select_id: 'domain_organization_ids') + select_option_of_multiselect(@org2.name, select_id: 'domain_organization_ids') page.click_button 'Submit' # choosing only org that user does not belong to is forbidden assert page.has_content?("You don't have permission create_domains with attributes that you have specified or you don't have access to specified organizations or locations") + switch_form_tab('Organizations') # with org1 which user belongs to, submit passes but the organization selection is limited to user's list - organization_selector = page.find('select#domain_organization_ids') - organization_selector.unselect @org1.name - organization_selector.unselect @org2.name + deselect_option_of_multiselect(@org1.name, select_id: 'domain_organization_ids') + deselect_option_of_multiselect(@org2.name, select_id: 'domain_organization_ids') page.click_button 'Submit' # can't create in any context either @@ -458,9 +453,16 @@ def clone_role(original, org, suffix = '') new_role end - def select_org(org) - within('li#organization-dropdown ul') do - find("a#select_taxonomy_#{org}").trigger('click') - end + def ensure_selected_option_of_multiselect(label, select_id: nil) + selected = page.find("#ms-#{select_id} .ms-selection").has_content?(label) + selected || select_option_of_multiselect(label, select_id: select_id) + end + + def select_option_of_multiselect(label, select_id: nil) + page.find("#ms-#{select_id} .ms-selectable").find('span', text: label).click + end + + def deselect_option_of_multiselect(label, select_id: nil) + page.find("#ms-#{select_id} .ms-selection").find('span', text: label).click end end diff --git a/test/integration/ptable_js_test.rb b/test/integration/ptable_js_test.rb index 6dd13e02876..914c70bd2d1 100644 --- a/test/integration/ptable_js_test.rb +++ b/test/integration/ptable_js_test.rb @@ -13,9 +13,11 @@ class PtableJSTest < IntegrationTestWithJavascript visit ptables_path click_link "ubuntu default" fill_in "ptable_name", :with => "debian default" - find('#editor').click - find('.ace_content').send_keys "d-i partman-auto/disk string /dev/sda\nd-i" - sleep 1 # Wait for the editor onChange debounce + + editor_text = "d-i partman-auto/disk string /dev/sda\nd-i" + fill_in_editor_field('#react-ace', editor_text) + assert has_editor_display?('#react-ace', editor_text) + assert_submit_button(ptables_path) assert page.has_link? 'debian default' end @@ -24,13 +26,15 @@ class PtableJSTest < IntegrationTestWithJavascript visit ptables_path click_link "ubuntu default" fill_in "ptable_name", :with => "debian.default /dev/sda" - find('#editor').click - find('.ace_content').send_keys "d-i partman-auto/disk string /dev/sda\nd-i" - sleep 1 # Wait for the editor onChange debounce + + editor_text = "d-i partman-auto/disk string /dev/sda\nd-i" + fill_in_editor_field('#react-ace', editor_text) + assert_submit_button(ptables_path) assert page.has_link? 'debian.default /dev/sda' click_link "debian.default /dev/sda" assert page.has_field?("ptable_name") # not 404 + assert has_editor_display?('#react-ace', editor_text) end end diff --git a/test/integration/report_template_js_test.rb b/test/integration/report_template_js_test.rb index 384cdd570ac..f3eaefdbbab 100644 --- a/test/integration/report_template_js_test.rb +++ b/test/integration/report_template_js_test.rb @@ -13,14 +13,16 @@ class ReportTemplateJSIntegrationTest < IntegrationTestWithJavascript assert page.has_link?('Create Report Template') click_link 'Create Report Template' + + template_text = "CPUs,RAM,HDD\n<%= input(\'cpus\') -%>,<%= 1024 -%> MB,N/A" + fill_in :id => 'report_template_name', :with => 'A testing report' - find('#editor').click - find('.ace_content').send_keys "CPUs,RAM,HDD\n<%= input('cpus') -%>,<%= 1024 -%> MB,N/A" - sleep 1 # Wait for the editor onChange debounce + fill_in_editor_field('#react-ace', template_text) + assert has_editor_display?('#react-ace', template_text) click_link('Inputs') within "#template_inputs" do - refute page.has_content?('Input Type') + assert page.has_no_content?('Input Type') click_link '+ Add Input' assert page.has_content?('Input Type') @@ -34,6 +36,8 @@ class ReportTemplateJSIntegrationTest < IntegrationTestWithJavascript template = ReportTemplate.find_by_name('A testing report') visit generate_report_template_path(template) + assert_equal template.template, template_text + assert page.has_content?('cpus') end @@ -44,13 +48,13 @@ class ReportTemplateJSIntegrationTest < IntegrationTestWithJavascript visit generate_report_template_path(template) within '#content' do - refute page.has_content? input.name + assert page.has_no_content? input.name click_link 'Display advanced fields' assert page.has_content? input.name click_link 'Hide advanced fields' - refute page.has_content? input.name + assert page.has_no_content? input.name end end end diff --git a/test/integration/search_bar_js_test.rb b/test/integration/search_bar_js_test.rb index 7a59f038f18..a58f0dd69f3 100644 --- a/test/integration/search_bar_js_test.rb +++ b/test/integration/search_bar_js_test.rb @@ -3,7 +3,8 @@ class SearchBarTest < IntegrationTestWithJavascript test "backslash key clicked should opens the search" do visit bookmarks_path - find('table').send_keys "/" + # needs to be interactive element + find('table thead').find('a', text: 'Name').send_keys("/") assert find('.search-input.focus') end end diff --git a/test/integration/shared/host_finders.rb b/test/integration/shared/host_finders.rb index 564b905827d..c29939a4123 100644 --- a/test/integration/shared/host_finders.rb +++ b/test/integration/shared/host_finders.rb @@ -1,11 +1,24 @@ module HostFinders extend ActiveSupport::Concern + def disable_interface_modal_animation + page.evaluate_script('document.getElementById("interfaceModal").classList.remove("fade")') + end + def go_to_interfaces_tab # go to New Host page assert_new_button(hosts_path, "Create Host", new_host_path) # switch to interfaces tab page.find(:link, "Interfaces").click + disable_interface_modal_animation + end + + def close_interfaces_modal + button = page.find(:button, 'Ok') + page.scroll_to(button) + button.click # close interfaces + # wait for the dialog to close + page.has_no_css?('#interfaceModal.in') end def add_interface @@ -15,7 +28,7 @@ def add_interface end def modal - page.find('#interfaceModal') + page.find('#interfaceModal.in') end def table diff --git a/test/integration/smart_proxy_test.rb b/test/integration/smart_proxy_test.rb index 7bda2c5b2af..15a57b27944 100644 --- a/test/integration/smart_proxy_test.rb +++ b/test/integration/smart_proxy_test.rb @@ -71,7 +71,7 @@ def teardown proxy = smart_proxies(:one) visit smart_proxy_path(proxy) assert page.has_link?("VisibleTab") - refute page.has_link?("HiddenTab") + assert page.has_no_link?("HiddenTab") end end end diff --git a/test/integration_test_helper.rb b/test/integration_test_helper.rb index ed6feb20348..47451f3ff4d 100644 --- a/test/integration_test_helper.rb +++ b/test/integration_test_helper.rb @@ -19,17 +19,19 @@ Rails.logger.error("DO NOT IGNORE - Consistent failure - #{klass} #{test_name}") end -Selenium::WebDriver::Chrome.driver_path = ENV['TESTDRIVER_PATH'] || File.join(Rails.root, 'node_modules', '.bin', 'chromedriver') +Selenium::WebDriver::Chrome::Service.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' + options.args << '--headless' unless ENV['DEBUG_JS_TEST'] == '1' Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) end -Capybara.javascript_driver = ENV["JS_TEST_DRIVER"]&.to_sym || :selenium_chrome -Capybara.default_max_wait_time = 20 +Capybara.configure do |config| + config.javascript_driver = ENV["JS_TEST_DRIVER"]&.to_sym || :selenium_chrome + config.default_max_wait_time = 20 +end class ActionDispatch::IntegrationTest # Make the Capybara DSL available in all integration tests @@ -130,12 +132,26 @@ def wait_for_element(*args) end end - def close_interfaces_modal - click_button 'Ok' # close interfaces - # wait for the dialog to close - wait_for do - find(:css, '#interfaceModal', visible: false) - end + def cookie_named(name) + page.driver.browser.manage.cookie_named(name) + end + + def cookie_value(name) + cookie_named(name) && cookie_named(name)[:value] + end + + def has_editor_display?(css_locator, text) + has_css?("#{css_locator} .ace_content", text: text) + end + + # Works only with css locator + def fill_in_editor_field(css_locator, text) + # the input is not visible for chrome driver + find("#{css_locator} .ace_editor").click + has_css?("#{css_locator} .ace_editor") + find("#{css_locator} .ace_text-input", visible: :all).set text + # wait for the debounce + has_editor_display?(css_locator, text) end def login_user(username, password) @@ -158,25 +174,25 @@ def set_default_context(user, org, loc) end def assert_available_location(location) - within('li#location-dropdown ul') do + within('li#location-dropdown ul', visible: :all) do assert page.has_link?(location) end end def refute_available_location(location) - within('li#location-dropdown ul') do + within('li#location-dropdown ul', visible: :all) do assert page.has_no_link?(location) end end def assert_available_organization(organization) - within('li#organization-dropdown ul') do + within('li#organization-dropdown ul', visible: :all) do assert page.has_link?(organization) end end def refute_available_organization(organization) - within('li#location-dropdown ul') do + within('li#location-dropdown ul', visible: :all) do assert page.has_no_link?(organization) end end @@ -194,14 +210,16 @@ def assert_current_location(location) end def select_organization(organization) - within('li#organization-dropdown ul') do - click_link organization + within('li#organization-dropdown') do + find('a.dropdown-toggle').click + find("a.organization_menuitem", text: organization).click end end def select_location(location) - within('li#location-dropdown ul') do - click_link location + within('li#location-dropdown') do + find('a.dropdown-toggle').click + find("a.organization_menuitem", text: location).click end end @@ -210,11 +228,17 @@ def assert_warning(message) end def assert_form_tab(label) - within(%(label[for="#{label.singularize.underscore}_ids"])) do + within('form .nav-tabs') do assert page.has_content?(label) end end + def switch_form_tab(name) + within('form .nav-tabs') do + click_link name + end + end + def warning_notificication_messages warning_notificications_data.map { |n| n['message'] } end @@ -250,7 +274,6 @@ def database_cleaner_strategy 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) end diff --git a/webpack/assets/javascripts/react_app/common/I18n.js b/webpack/assets/javascripts/react_app/common/I18n.js index 58299d7f94c..8285780a798 100644 --- a/webpack/assets/javascripts/react_app/common/I18n.js +++ b/webpack/assets/javascripts/react_app/common/I18n.js @@ -1,11 +1,10 @@ import Jed from 'jed'; import { addLocaleData } from 'react-intl'; import { deprecateObjectProperty } from './DeprecationService'; -import { runningInPhantomJS } from './helpers'; class IntlLoader { constructor(locale, timezone) { - this.fallbackIntl = !global.Intl || runningInPhantomJS(); + this.fallbackIntl = !global.Intl; [this.locale] = locale.split('-'); this.timezone = this.fallbackIntl ? 'UTC' : timezone; diff --git a/webpack/assets/javascripts/react_app/common/document.js b/webpack/assets/javascripts/react_app/common/document.js index 9f1b8a89085..ec54a69ff4f 100644 --- a/webpack/assets/javascripts/react_app/common/document.js +++ b/webpack/assets/javascripts/react_app/common/document.js @@ -1,11 +1,9 @@ -import { runningInPhantomJS } from './helpers'; - /** * Whether or not the page is focused (beeing used atm) * @return {boolean} */ export const doesDocumentHasFocus = () => - runningInPhantomJS() || (document.hasFocus ? document.hasFocus() : true); + document.hasFocus ? document.hasFocus() : true; /** * Update title of document diff --git a/webpack/assets/javascripts/react_app/common/helpers.js b/webpack/assets/javascripts/react_app/common/helpers.js index 46c9c28953e..6f98b0a6049 100644 --- a/webpack/assets/javascripts/react_app/common/helpers.js +++ b/webpack/assets/javascripts/react_app/common/helpers.js @@ -20,12 +20,6 @@ export const isoCompatibleDate = date => { return date; }; -/** - * Does it run in phantomjs test environment - * @return {boolean} - */ -export const runningInPhantomJS = () => window._phantom !== undefined; - /** * Add a debounce timeout for your methods. * @param {Object} context - the context where your method is running.