From 32cd6c78921afe2c9d2fa993e8610e699149806c Mon Sep 17 00:00:00 2001 From: Cmcmahon Date: Mon, 8 Dec 2014 09:20:42 -0700 Subject: [PATCH] QA: WIP update tests for RSpec3 syntax etc. Add back a sleep to make the test pass * make a Then statement with no assertion into a When * remove Then statements assertions from Given steps * prefer single quotes per rubocop * use strings instead of regexes where appropriate for match operator * use appropriate wait_until syntax * remove redundant steps that call a single other step * sort invisible selection criteria from steps to Feature input * add when_present polling because test is now much faster Change-Id: I24435362836945833942e87d7caee49c9b34368d --- tests/browser/features/mmv.download.feature | 50 +++++------ .../step_definitions/mmv_download_steps.rb | 86 +++++++------------ .../features/step_definitions/mmv_steps.rb | 2 +- 3 files changed, 55 insertions(+), 83 deletions(-) diff --git a/tests/browser/features/mmv.download.feature b/tests/browser/features/mmv.download.feature index cc70839a1..dbe222012 100644 --- a/tests/browser/features/mmv.download.feature +++ b/tests/browser/features/mmv.download.feature @@ -9,47 +9,47 @@ Feature: Download menu Then the download menu should appear Scenario: Clicking the image closes the download menu - Given I open the download menu - When I click the image + When I click the download icon + And I click the image Then the download menu should disappear Scenario: Image size defaults to original - When I open the download menu - Then the download image size label should match the original + When I click the download icon + Then the original beginning download image size label should be "4000 × 3000 px jpg" And the download links should be the original image Scenario: Attribution area is collapsed by default - When I open the download menu + When I click the download icon Then the attribution area should be collapsed Scenario: Attribution area can be opened - Given I open the download menu - When I click on the attribution area + When I click the download icon + And I click on the attribution area Then the attribution area should be open Scenario: Attribution area can be closed - Given I open the download menu - And the attribution area is open - When I click on the attribution area close icon + When I click the download icon + And I click on the attribution area + And I click on the attribution area close icon Then the attribution area should be collapsed Scenario: The small download option has the correct information - Given I open the download dropdown - When I click the small download size - Then the download size options should disappear - And the download image size label should match the small size - And the download links should be the small thumbnail + When I open the download dropdown + And I click the small download size + And the download size options disappears + Then the download image size label should be "193 × 145 px jpg" + And the download links should be the 193 thumbnail Scenario: The medium download option has the correct information - Given I open the download dropdown - When I click the medium download size - Then the download size options should disappear - And the download image size label should match the medium size - And the download links should be the medium thumbnail + When I open the download dropdown + And I click the medium download size + And the download size options disappears + Then the download image size label should be "640 × 480 px jpg" + And the download links should be the 640 thumbnail Scenario: The large download option has the correct information - Given I open the download dropdown - When I click the large download size - Then the download size options should disappear - And the download image size label should match the large size - And the download links should be the large thumbnail \ No newline at end of file + When I open the download dropdown + And I click the large download size + And the download size options disappears + Then the download image size label should be "1200 × 900 px jpg" + And the download links should be the 1200 thumbnail \ No newline at end of file diff --git a/tests/browser/features/step_definitions/mmv_download_steps.rb b/tests/browser/features/step_definitions/mmv_download_steps.rb index dc2188aa3..97ef9db59 100644 --- a/tests/browser/features/step_definitions/mmv_download_steps.rb +++ b/tests/browser/features/step_definitions/mmv_download_steps.rb @@ -1,32 +1,21 @@ # encoding: utf-8 -Given /^I open the download menu$/ do +When /^I open the download dropdown$/ do step "I click the download icon" - step "the download menu should appear" -end - -Given /^the attribution area is open$/ do - step "I click on the attribution area" -end - -Given /^I open the download dropdown$/ do - step "I open the download menu" - step "the download image size label should match the original" - step "the download links should be the original image" step "I click the download down arrow icon" - step "the download size options should appear" end When /^I click the download icon$/ do - on(E2ETestPage).mmv_download_icon_element.click + on(E2ETestPage).mmv_download_icon_element.when_present.click end When /^I click the download down arrow icon$/ do - on(E2ETestPage).mmv_download_down_arrow_icon_element.click + sleep 1 + on(E2ETestPage).mmv_download_down_arrow_icon_element.when_present.click end When /^I click on the attribution area$/ do - on(E2ETestPage).mmv_download_attribution_area_element.click + on(E2ETestPage).mmv_download_attribution_area_element.when_present.click end When /^I click on the attribution area close icon$/ do @@ -50,72 +39,55 @@ When /^I click the (.*) download size$/ do |size_option| end end +When /^the download size options disappears$/ do + on(E2ETestPage).mmv_download_size_menu_element.when_not_present +end + Then /^the download menu should appear$/ do - on(E2ETestPage).mmv_download_menu_element.when_present.should be_visible + expect(on(E2ETestPage).mmv_download_menu_element.when_present).to be_visible end Then /^the download menu should disappear$/ do - on(E2ETestPage).mmv_download_menu_element.should_not be_visible + expect(on(E2ETestPage).mmv_download_menu_element).not_to be_visible end -Then /^the download image size label should match the original$/ do - on(E2ETestPage).mmv_download_size_label_element.when_present.text.should eq "4000 × 3000 px jpg" +Then /^the original beginning download image size label should be "(.*)"$/ do |size_in_pixels| + expect(on(E2ETestPage).mmv_download_size_label_element.when_present.text).to eq size_in_pixels end -Then /^the download image size label should match the small size$/ do - on(E2ETestPage).mmv_download_size_label_element.when_present.text.should eq "193 × 145 px jpg" -end - -Then /^the download image size label should match the medium size$/ do - on(E2ETestPage).mmv_download_size_label_element.when_present.text.should eq "640 × 480 px jpg" -end - -Then /^the download image size label should match the large size$/ do - on(E2ETestPage).mmv_download_size_label_element.when_present.text.should eq "1200 × 900 px jpg" +Then /^the download image size label should be "(.*)"$/ do |size_in_pixels| + on(E2ETestPage) do |page| + page.mmv_download_size_options_elements[0].when_not_present + expect(page.mmv_download_size_label_element.when_present.text).to eq size_in_pixels + end end Then /^the download size options should appear$/ do - on(E2ETestPage).mmv_download_size_menu_element.when_present.should be_visible -end - -Then /^the download size options should disappear$/ do - on(E2ETestPage).mmv_download_size_menu_element.when_not_present + expect(on(E2ETestPage).mmv_download_size_menu_element.when_present).to be_visible end Then /^the download links should be the original image$/ do on(E2ETestPage) do |page| - page.mmv_download_link_element.attribute('href').should match /^?download$/ - page.mmv_download_preview_link_element.attribute('href').should_not match /^?download$/ - page.mmv_download_link_element.attribute('href').should_not match /\/thumb\// - page.mmv_download_preview_link_element.attribute('href').should_not match /\/thumb\// + expect(page.mmv_download_link_element.attribute('href')).to match /^?download$/ + expect(page.mmv_download_preview_link_element.attribute('href')).not_to match /^?download$/ + expect(page.mmv_download_link_element.attribute('href')).not_to match /\/thumb\// + expect(page.mmv_download_preview_link_element.attribute('href')).not_to match /\/thumb\// end end Then /^the download links should be the (\d+) thumbnail$/ do |thumb_size| on(E2ETestPage) do |page| - Watir::Wait.until { page.mmv_download_link_element.attribute('href').match thumb_size } - page.mmv_download_link_element.attribute('href').should match /^?download$/ - page.mmv_download_preview_link_element.attribute('href').should_not match /^?download$/ - page.mmv_download_preview_link_element.attribute('href').should match thumb_size + page.wait_until { page.mmv_download_link_element.attribute('href').match thumb_size } + expect(page.mmv_download_link_element.attribute('href')).to match /^?download$/ + expect(page.mmv_download_preview_link_element.attribute('href')).not_to match /^?download$/ + expect(page.mmv_download_preview_link_element.attribute('href')).to match thumb_size end end -Then /^the download links should be the small thumbnail$/ do - step "the download links should be the 193 thumbnail" -end - -Then /^the download links should be the medium thumbnail$/ do - step "the download links should be the 640 thumbnail" -end - -Then /^the download links should be the large thumbnail$/ do - step "the download links should be the 1200 thumbnail" -end - Then /^the attribution area should be collapsed$/ do - on(E2ETestPage).mmv_download_attribution_area_element.attribute('class').should match /mw-mmv-download-attribution-collapsed/ + expect(on(E2ETestPage).mmv_download_attribution_area_element.when_present.attribute('class')).to match 'mw-mmv-download-attribution-collapsed' end Then /^the attribution area should be open$/ do - on(E2ETestPage).mmv_download_attribution_area_element.attribute('class').should_not match /mw-mmv-download-attribution-collapsed/ + expect(on(E2ETestPage).mmv_download_attribution_area_element.when_present.attribute('class')).not_to match 'mw-mmv-download-attribution-collapsed' end \ No newline at end of file diff --git a/tests/browser/features/step_definitions/mmv_steps.rb b/tests/browser/features/step_definitions/mmv_steps.rb index c3731017c..0a6e77e91 100644 --- a/tests/browser/features/step_definitions/mmv_steps.rb +++ b/tests/browser/features/step_definitions/mmv_steps.rb @@ -40,7 +40,7 @@ When /^I close MMV$/ do end When /^I click the image$/ do - on(E2ETestPage).mmv_image_div_element.click + on(E2ETestPage).mmv_image_div_element.when_present.click end Then /^the image metadata and the image itself should be there$/ do