2014-10-03 12:55:42 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
Given /^I am at a wiki article with at least two embedded pictures$/ do
|
2015-12-23 23:56:05 +00:00
|
|
|
api.create_page 'MediaViewerE2ETest', File.read('samples/MediaViewerE2ETest.wikitext')
|
2014-10-03 12:55:42 +00:00
|
|
|
visit(E2ETestPage)
|
2015-01-29 00:46:27 +00:00
|
|
|
on(E2ETestPage).image1_in_article_element.when_present.should be_visible
|
2014-10-03 12:55:42 +00:00
|
|
|
end
|
|
|
|
|
2015-12-23 23:56:05 +00:00
|
|
|
Given /^the MMV has loaded$/ do
|
|
|
|
on(E2ETestPage) do |page|
|
|
|
|
page.wait_until do
|
|
|
|
# Wait for JS to hijack standard link
|
|
|
|
# TODO: If this approach works well, we should implement general
|
|
|
|
# `wait_for_resource` and `resource_ready?` helper methods in
|
|
|
|
# mw-selenium, and document this pattern on mw.org
|
|
|
|
browser.execute_script("return mw.loader.getState('mmv.bootstrap') === 'ready'")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-10-03 12:55:42 +00:00
|
|
|
Given /^I am viewing an image using MMV$/ do
|
2015-12-09 16:21:54 +00:00
|
|
|
step 'I am at a wiki article with at least two embedded pictures'
|
2015-12-23 23:56:05 +00:00
|
|
|
step 'the MMV has loaded'
|
2015-12-09 16:21:54 +00:00
|
|
|
step 'I click on the second image in the article'
|
|
|
|
step 'the image metadata and the image itself should be there'
|
2014-10-03 12:55:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
When /^I click on the first image in the article$/ do
|
|
|
|
on(E2ETestPage) do |page|
|
|
|
|
# We store the offset of the image as the scroll position and scroll to it, because cucumber/selenium
|
|
|
|
# sometimes automatically scrolls to it when we ask it to click on it (seems to depend on timing)
|
2015-12-23 23:56:05 +00:00
|
|
|
@article_scroll_top = page.execute_script("var scrollTop = Math.round($('a[href$=\"File:Sunrise_over_fishing_boats_in_Kerala.jpg\"]').first().find('img').offset().top); window.scrollTo(0, scrollTop); return scrollTop;")
|
2014-10-03 12:55:42 +00:00
|
|
|
# Scrolls to the image and clicks on it
|
|
|
|
page.image1_in_article
|
|
|
|
# This is a global variable that can be used to measure performance
|
|
|
|
@image_click_time = Time.now.getutc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
When /^I click on the second image in the article$/ do
|
|
|
|
on(E2ETestPage) do |page|
|
|
|
|
# We store the offset of the image as the scroll position and scroll to it, because cucumber/selenium
|
|
|
|
# sometimes automatically scrolls to it when we ask it to click on it (seems to depend on timing)
|
2015-12-23 23:56:05 +00:00
|
|
|
@article_scroll_top = page.execute_script("var scrollTop = Math.round($('a[href$=\"File:Wikimedia_Foundation_2013_All_Hands_Offsite_-_Day_2_-_Photo_24.jpg\"]').first().find('img').offset().top); window.scrollTo(0, scrollTop); return scrollTop;")
|
2014-10-03 12:55:42 +00:00
|
|
|
# Scrolls to the image and clicks on it
|
|
|
|
page.image2_in_article
|
|
|
|
# This is a global variable that can be used to measure performance
|
|
|
|
@image_click_time = Time.now.getutc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
When /^I close MMV$/ do
|
|
|
|
on(E2ETestPage).mmv_close_button_element.when_present(30).click
|
|
|
|
end
|
|
|
|
|
|
|
|
When /^I click the image$/ do
|
2015-12-09 15:54:58 +00:00
|
|
|
on(E2ETestPage) do
|
2015-02-13 11:18:27 +00:00
|
|
|
# Clicking the top-left corner of the image is necessary for the test to work on IE
|
|
|
|
# A plain click on the image element ends up hitting the dialog, which means it won't close
|
2015-02-16 15:37:22 +00:00
|
|
|
begin
|
2015-11-25 15:35:52 +00:00
|
|
|
browser.driver.action.move_to(browser.driver.find_element(:class, 'mw-mmv-image'), 10, 10).click.perform
|
2015-02-16 15:37:22 +00:00
|
|
|
rescue
|
|
|
|
# Plain click for web drivers that don't support mouse moves (Safari, currently)
|
|
|
|
on(E2ETestPage).mmv_image_div_element.when_present.click
|
|
|
|
end
|
2015-02-13 11:18:27 +00:00
|
|
|
end
|
2014-10-03 12:55:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Then /^the image metadata and the image itself should be there$/ do
|
|
|
|
on(E2ETestPage) do |page|
|
|
|
|
# MMV was launched, article is not visible now
|
|
|
|
page.image1_in_article_element.should_not be_visible
|
|
|
|
check_elements_in_viewer_for_image2 page
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Helper function that verifies the presence of various elements in viewer
|
|
|
|
# while looking at image1 (Kerala)
|
|
|
|
def check_elements_in_viewer_for_image1(page)
|
|
|
|
# Check basic MMV elements are present
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_overlay_element.when_present).to be_visible
|
|
|
|
expect(page.mmv_wrapper_element.when_present).to be_visible
|
|
|
|
expect(page.mmv_image_div_element).to be_visible
|
2014-10-03 12:55:42 +00:00
|
|
|
|
|
|
|
# Check image content
|
2015-03-18 08:41:48 +00:00
|
|
|
expect(page.mmv_final_image_element.when_present.attribute('src')).to match /Kerala/
|
2014-10-03 12:55:42 +00:00
|
|
|
|
|
|
|
# Check basic metadata is present
|
|
|
|
|
|
|
|
# Title
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_metadata_title_element.when_present.text).to match /^Sunrise over fishing boats$/
|
2014-10-03 12:55:42 +00:00
|
|
|
# License
|
2015-12-09 16:06:51 +00:00
|
|
|
expect(page.mmv_metadata_license_element.when_present.attribute('href')).to match %r{^http://creativecommons.org/licenses/by-sa/3.0$}
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_metadata_license_element.when_present.text).to match 'CC BY-SA 3.0'
|
2014-10-03 12:55:42 +00:00
|
|
|
# Credit
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_metadata_credit_element.when_present).to be_visible
|
|
|
|
expect(page.mmv_metadata_source_element.when_present.text).to match 'Own work'
|
2014-10-03 12:55:42 +00:00
|
|
|
|
|
|
|
# Image metadata
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_image_metadata_wrapper_element.when_present).to be_visible
|
2014-10-03 12:55:42 +00:00
|
|
|
# Description
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_image_metadata_desc_element.when_present.text).to match 'Sunrise over fishing boats on the beach south of Kovalam'
|
2014-10-03 12:55:42 +00:00
|
|
|
# Image metadata links
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_image_metadata_links_wrapper_element.when_present).to be_visible
|
2014-10-03 12:55:42 +00:00
|
|
|
# Details link
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_details_page_link_element.when_present.text).to match 'More details'
|
|
|
|
expect(page.mmv_details_page_link_element.when_present.attribute('href')).to match /boats_in_Kerala.jpg$/
|
2014-10-03 12:55:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Helper function that verifies the presence of various elements in viewer
|
|
|
|
# while looking at image2 (Aquarium)
|
|
|
|
def check_elements_in_viewer_for_image2(page)
|
|
|
|
# Check basic MMV elements are present
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_overlay_element.when_present).to be_visible
|
|
|
|
expect(page.mmv_wrapper_element.when_present).to be_visible
|
|
|
|
expect(page.mmv_image_div_element).to be_visible
|
2014-10-03 12:55:42 +00:00
|
|
|
|
|
|
|
# Check image content
|
2015-04-06 12:19:53 +00:00
|
|
|
expect(page.mmv_final_image_element.when_present(30).attribute('src')).to match 'Offsite'
|
2014-10-03 12:55:42 +00:00
|
|
|
|
|
|
|
# Check basic metadata is present
|
|
|
|
|
|
|
|
# Title
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_metadata_title_element.when_present.text).to match /^Tropical Fish Aquarium$/
|
2014-10-03 12:55:42 +00:00
|
|
|
# License
|
2015-12-09 16:06:51 +00:00
|
|
|
expect(page.mmv_metadata_license_element.when_present(10).attribute('href')).to match %r{^http://creativecommons.org/licenses/by-sa/3.0$}
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_metadata_license_element.when_present.text).to match 'CC BY-SA 3.0'
|
2014-10-03 12:55:42 +00:00
|
|
|
# Credit
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_metadata_credit_element.when_present).to be_visible
|
|
|
|
expect(page.mmv_metadata_source_element.when_present.text).to match 'Wikimedia Foundation'
|
2014-10-03 12:55:42 +00:00
|
|
|
|
|
|
|
# Image metadata
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_image_metadata_wrapper_element.when_present).to be_visible
|
2014-10-03 12:55:42 +00:00
|
|
|
# Description
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_image_metadata_desc_element.when_present.text).to match 'Photo from Wikimedia Foundation'
|
2014-10-03 12:55:42 +00:00
|
|
|
# Image metadata links
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_image_metadata_links_wrapper_element.when_present).to be_visible
|
2014-10-03 12:55:42 +00:00
|
|
|
# Details link
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_details_page_link_element.when_present.text).to match 'More details'
|
|
|
|
expect(page.mmv_details_page_link_element.when_present.attribute('href')).to match /All_Hands_Offsite.*\.jpg$/
|
2014-10-03 12:55:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Helper function that verifies the presence of various elements in viewer
|
|
|
|
# while looking at image3 (Hong Kong)
|
|
|
|
def check_elements_in_viewer_for_image3(page)
|
|
|
|
# Check basic MMV elements are present
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_overlay_element.when_present).to be_visible
|
|
|
|
expect(page.mmv_wrapper_element.when_present).to be_visible
|
|
|
|
expect(page.mmv_image_div_element).to be_visible
|
2014-10-03 12:55:42 +00:00
|
|
|
|
|
|
|
# Check image content
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_image_div_element.image_element.attribute('src')).to match 'Hong_Kong'
|
2014-10-03 12:55:42 +00:00
|
|
|
|
|
|
|
# Check basic metadata is present
|
|
|
|
|
|
|
|
# Title
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_metadata_title_element.when_present.text).to match /^Hong Kong Harbor at night$/
|
2014-10-03 12:55:42 +00:00
|
|
|
# License
|
2015-12-09 16:06:51 +00:00
|
|
|
expect(page.mmv_metadata_license_element.when_present.attribute('href')).to match %r{^http://creativecommons.org/licenses/by-sa/3.0$}
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_metadata_license_element.when_present.text).to match 'CC BY-SA 3.0'
|
2014-10-03 12:55:42 +00:00
|
|
|
# Credit
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_metadata_credit_element.when_present).to be_visible
|
|
|
|
expect(page.mmv_metadata_source_element.when_present.text).to match 'Wikimedia Foundation'
|
2014-10-03 12:55:42 +00:00
|
|
|
|
|
|
|
# Image metadata
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_image_metadata_wrapper_element.when_present).to be_visible
|
2014-10-03 12:55:42 +00:00
|
|
|
# Description
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_image_metadata_desc_element.when_present.text).to match /Photos from our product team's talks at Wikimania 2013 in Hong Kong./
|
2014-10-03 12:55:42 +00:00
|
|
|
# Image metadata links
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_image_metadata_links_wrapper_element.when_present).to be_visible
|
2014-10-03 12:55:42 +00:00
|
|
|
# Details link
|
2014-12-17 21:54:51 +00:00
|
|
|
expect(page.mmv_details_page_link_element.when_present.text).to match 'More details'
|
|
|
|
expect(page.mmv_details_page_link_element.when_present.attribute('href')).to match /Wikimania_2013_-_Hong_Kong_-_Photo_090\.jpg$/
|
2014-10-03 12:55:42 +00:00
|
|
|
end
|