diff --git a/tests/browser/features/popups_core.feature b/tests/browser/features/popups_core.feature index aa243ce1d..13b089330 100644 --- a/tests/browser/features/popups_core.feature +++ b/tests/browser/features/popups_core.feature @@ -5,6 +5,7 @@ Feature: Popups core And I am logged in And HoverCards is enabled as a beta feature And I am on the "Popups test page" page + And the Hovercards JavaScript module has loaded Scenario: Hover card is visible on mouse over And I hover over the first valid link diff --git a/tests/browser/features/support/pages/special_preferences_page.rb b/tests/browser/features/support/pages/special_preferences_page.rb index 897851e68..cff4fa576 100644 --- a/tests/browser/features/support/pages/special_preferences_page.rb +++ b/tests/browser/features/support/pages/special_preferences_page.rb @@ -5,11 +5,16 @@ class SpecialPreferencesPage a(:beta_features_tab, css: '#preftab-betafeatures') text_field(:hovercards_checkbox, css: '#mw-input-wppopups') button(:submit_button, css: '#prefcontrol') + div(:notification, css: ".mw-notification") def enable_hovercards beta_features_tab_element.when_present.click return unless hovercards_checkbox_element.attribute('checked').nil? hovercards_checkbox_element.click submit_button_element.when_present.click + + # Note well that Element#wait_until_present is more semantic but is + # deprecated. Fortunately, #when_present simply wraps #wait_until_present. + notification_element.when_present end -end \ No newline at end of file +end diff --git a/tests/browser/features/support/step_definitions/common_steps.rb b/tests/browser/features/support/step_definitions/common_steps.rb index 0ad6985d2..008b7bfde 100644 --- a/tests/browser/features/support/step_definitions/common_steps.rb +++ b/tests/browser/features/support/step_definitions/common_steps.rb @@ -9,3 +9,11 @@ end Then(/^HoverCards is enabled as a beta feature$/) do visit(SpecialPreferencesPage).enable_hovercards end + +Given(/^the Hovercards JavaScript module has loaded$/) do + on(ArticlePage) do |page| + page.wait_until do + browser.execute_script("return mw.loader.getState('ext.popups.desktop') === 'ready'") + end + end +end diff --git a/tests/browser/features/support/step_definitions/popups_core.rb b/tests/browser/features/support/step_definitions/popups_core.rb index 23f061b12..d1374c10d 100644 --- a/tests/browser/features/support/step_definitions/popups_core.rb +++ b/tests/browser/features/support/step_definitions/popups_core.rb @@ -1,17 +1,17 @@ When(/^I hover over the page header$/) do on(ArticlePage).page_header_element.hover - sleep 1 # and dwell on it for a sec to give time for the visible hover card hide itself end When(/^I hover over the first valid link$/) do on(ArticlePage).first_valid_link_element.hover - sleep 1 # and dwell on it for a sec to give time for hover card to appear end Then(/^I should see a hover card$/) do - expect(on(ArticlePage).hovercard_element).to be_visible + expect(on(ArticlePage).hovercard_element.when_present(5)).to be_visible end Then(/^I should not see a hover card$/) do + # Requesting a hovercard hits API so wait time before asserting it did not show + sleep 5 expect(on(ArticlePage).hovercard_element).not_to be_visible end