From 3e78503e8e4b7e6387f8ac9fd6a35c6ea4244456 Mon Sep 17 00:00:00 2001 From: Baha Date: Wed, 13 Apr 2016 17:21:38 -0400 Subject: [PATCH] Add browser test for hovering link Basic feature of browsing a page, hovering a link, and showing/hiding a hovercard. Depends-On: Ie94fa399512be041f12b2f7cada20d4206ddaf82 Bug: T133019 Change-Id: Idf39e7e2a3b343babd6d0538225b4ef9002e8ac1 --- Gemfile | 7 +++ tests/browser/README.mediawiki | 51 ++++++++++++++++++ tests/browser/environments.yml | 45 ++++++++++++++++ tests/browser/features/popups_core.feature | 16 ++++++ tests/browser/features/support/env.rb | 3 ++ tests/browser/features/support/hooks.rb | 6 +++ .../features/support/pages/article_page.rb | 11 ++++ .../support/pages/special_preferences_page.rb | 15 ++++++ .../features/support/permissions.sqlite | Bin 0 -> 65536 bytes .../support/step_definitions/common_steps.rb | 11 ++++ .../support/step_definitions/popups_core.rb | 17 ++++++ tests/browser/samples/links.wikitext | 7 +++ 12 files changed, 189 insertions(+) create mode 100644 Gemfile create mode 100644 tests/browser/README.mediawiki create mode 100644 tests/browser/environments.yml create mode 100644 tests/browser/features/popups_core.feature create mode 100644 tests/browser/features/support/env.rb create mode 100644 tests/browser/features/support/hooks.rb create mode 100644 tests/browser/features/support/pages/article_page.rb create mode 100644 tests/browser/features/support/pages/special_preferences_page.rb create mode 100644 tests/browser/features/support/permissions.sqlite create mode 100644 tests/browser/features/support/step_definitions/common_steps.rb create mode 100644 tests/browser/features/support/step_definitions/popups_core.rb create mode 100644 tests/browser/samples/links.wikitext diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..53577ea77 --- /dev/null +++ b/Gemfile @@ -0,0 +1,7 @@ +source 'https://rubygems.org' + +gem 'chunky_png', '~> 1.3.4' +gem 'jsduck', '~> 5.3.4' +gem 'mediawiki_selenium', '~> 1.6.5' +gem 'rake', '~> 10.4', '>= 10.4.2' +gem 'rubocop', '~> 0.29.1', require: false diff --git a/tests/browser/README.mediawiki b/tests/browser/README.mediawiki new file mode 100644 index 000000000..e3c2a6d93 --- /dev/null +++ b/tests/browser/README.mediawiki @@ -0,0 +1,51 @@ +To run the Selenium tests you will have to install Ruby (for the exact +version see Gemfile), the latest versions of RubyGems and Firefox. + +The easiest way to install Ruby on *nix is RVM (https://rvm.io/) and on +Windows RubyInstaller (http://rubyinstaller.org/). + +Open terminal in tests/browser. Update RubyGems and install required +gems with: + + gem update --system + gem install bundler # on Mac OS X Yosemite append ` --user-install -n~/bin`, + # where ~/bin is the install folder + bundle install + +Environment variables MEDIAWIKI_USER and MEDIAWIKI_PASSWORD are required for +tests that require a logged in user. For local testing, create a test user on your local wiki +and export the user and password as the values for those variables. +For example: + + export MEDIAWIKI_USER= # Linux/Unix/Mac + set MEDIAWIKI_USER= # Windows + + export MEDIAWIKI_PASSWORD= # Linux/Unix/Mac + set MEDIAWIKI_PASSWORD= # Windows + +In addition to this create another user which will be reserved for new uploads +"Selenium_newuser". The password for this user should be the same as +MEDIAWIKI_PASSWORD + +Tests that use the "Given I create a random page using the API" step need to set +the MEDIAWIKI_API_URL environment variable, e.g. +export MEDIAWIKI_API_URL=http://en.wikipedia.beta.wmflabs.org/w/api.php + +Run the tests from the Popups directory with: + + make cucumber + +If you want to run a single set of tests, go to the tests/browser directory and +call 'bundle exec cucumber' with the path to the test file. For example, to run +only the watchlist tests: + + bundle exec cucumber features/watchstar.feature + +XML report (for Jenkins) is created at tests/browser/reports/junit. + +Jenkins is hosted at https://wmf.ci.cloudbees.com/ and it drives +browsers at http://saucelabs.com/ + +For more information about running Selenium tests please see +https://github.com/wikimedia/mediawiki-selenium + diff --git a/tests/browser/environments.yml b/tests/browser/environments.yml new file mode 100644 index 000000000..120c9ffba --- /dev/null +++ b/tests/browser/environments.yml @@ -0,0 +1,45 @@ +# Customize this configuration as necessary to provide defaults for various +# test environments. +# +# The set of defaults to use is determined by the MEDIAWIKI_ENVIRONMENT +# environment variable. +# +# export MEDIAWIKI_ENVIRONMENT=mw-vagrant-host +# bundle exec cucumber +# +# Additional variables set by the environment will override the corresponding +# defaults defined here. +# +# export MEDIAWIKI_ENVIRONMENT=mw-vagrant-host +# export MEDIAWIKI_USER=Selenium_user2 +# bundle exec cucumber +# +mw-vagrant-host: &default + mediawiki_url: http://127.0.0.1:8080/wiki/ + user_factory: true + +barry: + browser: phantomjs + user_factory: false + # mediawiki_url: Will be set manually + +mw-vagrant-guest: + mediawiki_url: http://127.0.0.1/wiki/ + user_factory: true + +beta: + mediawiki_url: http://en.m.wikipedia.beta.wmflabs.org/wiki/ + mediawiki_user: Selenium_user + # mediawiki_password: SET THIS IN THE ENVIRONMENT! + +test2: + mediawiki_url: http://test2.wikipedia.org/wiki/ + mediawiki_user: Selenium_user + # mediawiki_password: SET THIS IN THE ENVIRONMENT! + +integration: + browser: chrome + user_factory: true + # mediawiki_url: THIS WILL BE SET BY JENKINS + +default: *default diff --git a/tests/browser/features/popups_core.feature b/tests/browser/features/popups_core.feature new file mode 100644 index 000000000..aa243ce1d --- /dev/null +++ b/tests/browser/features/popups_core.feature @@ -0,0 +1,16 @@ +@chrome @en.m.wikipedia.beta.wmflabs.org @firefox @test2.m.wikipedia.org @vagrant @integration +Feature: Popups core + Background: + Given the hover cards test page is installed + And I am logged in + And HoverCards is enabled as a beta feature + And I am on the "Popups test page" page + + Scenario: Hover card is visible on mouse over + And I hover over the first valid link + Then I should see a hover card + + Scenario: Hover card is not visible on mouse out + And I hover over the first valid link + And I hover over the page header + Then I should not see a hover card diff --git a/tests/browser/features/support/env.rb b/tests/browser/features/support/env.rb new file mode 100644 index 000000000..c1072b26a --- /dev/null +++ b/tests/browser/features/support/env.rb @@ -0,0 +1,3 @@ +require 'mediawiki_selenium/cucumber' +require 'mediawiki_selenium/pages' +require 'mediawiki_selenium/step_definitions' diff --git a/tests/browser/features/support/hooks.rb b/tests/browser/features/support/hooks.rb new file mode 100644 index 000000000..56f159bc3 --- /dev/null +++ b/tests/browser/features/support/hooks.rb @@ -0,0 +1,6 @@ +# Needed for cucumber --dry-run -f stepdefs +require_relative 'env' + +Before('@skip') do |scenario| + scenario.skip_invoke! +end diff --git a/tests/browser/features/support/pages/article_page.rb b/tests/browser/features/support/pages/article_page.rb new file mode 100644 index 000000000..c27d6c8c6 --- /dev/null +++ b/tests/browser/features/support/pages/article_page.rb @@ -0,0 +1,11 @@ +# Standard article page +class ArticlePage + include PageObject + + page_url '<%= URI.encode(params[:article_name]) %>'\ + '<%= URI.encode(params[:query_string]) if params[:query_string] %>'\ + '<%= params[:hash] %>' + div(:page_header, css: '#mw-head') + a(:first_valid_link, css: 'ul a', index: 0) + div(:hovercard, css: '.mwe-popups') +end diff --git a/tests/browser/features/support/pages/special_preferences_page.rb b/tests/browser/features/support/pages/special_preferences_page.rb new file mode 100644 index 000000000..897851e68 --- /dev/null +++ b/tests/browser/features/support/pages/special_preferences_page.rb @@ -0,0 +1,15 @@ +class SpecialPreferencesPage + include PageObject + page_url 'Special:Preferences' + + a(:beta_features_tab, css: '#preftab-betafeatures') + text_field(:hovercards_checkbox, css: '#mw-input-wppopups') + button(:submit_button, css: '#prefcontrol') + + 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 + end +end \ No newline at end of file diff --git a/tests/browser/features/support/permissions.sqlite b/tests/browser/features/support/permissions.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..06d20318dfbb6e6e5edad230761bf2296953e051 GIT binary patch literal 65536 zcmeI*J#W)M9LMoL zm%s)S2#Fo>4w!fcEKKaoNF5NDIx&G(rL5>{CCb_U{e5>IU*@}YbH-1lRf&_(O|3KH zsW1$2#j=DDp8gi}w{sY}(c3xEzpeA0uJg5;o+y4D>TiXc=Y;-nAbdpr;jGx@S7pqj|jl$%tGhTA6()h%TW965vdXzd z%B_-fyEL3WuF9-cl}YF;<;PK{WLQ3``iU&HBJHPiF8SfFOK!C~op&?rtLbPWiEBzG zjvlLw(oXGAzkV+R^$Vi;rTL-RXihbEE`45lyOb`CHGVWcHC{I2#>K|A`nUSW`iuI5 z`Yj#hKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{ z1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0009IL zKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~ zfi(mM223%y*X+|r5PNRW+QEE5#)tNqqL^K-BzDce?^k8nckMV?(06r#IFsE?rAkk) z3fOy0aWe~eaTvytT8V@!&zP5~YuCa`;LfY|1BZ5-Vk*nasOxEKL=WxCNA_DZ8`;U7 zrZ_cZ8k_q1+;X|quimxY4}z7ESKL79;krp$OuW&8G4XmNzH@TN1}l`?t~lOrim}5+ zi>%#;SB~<2BAMzfWBKf6Q(Vj@ zR;$(Qg*aXaWYLY>;Bo4E%GN8Z8zg(9M=yOpyD6_zD%fb<WNYS literal 0 HcmV?d00001 diff --git a/tests/browser/features/support/step_definitions/common_steps.rb b/tests/browser/features/support/step_definitions/common_steps.rb new file mode 100644 index 000000000..0ad6985d2 --- /dev/null +++ b/tests/browser/features/support/step_definitions/common_steps.rb @@ -0,0 +1,11 @@ +Given(/^the hover cards test page is installed$/) do + api.create_page 'Popups test page', File.read('samples/links.wikitext') +end + +Given(/^I am on the "(.*?)" page$/) do |page| + visit(ArticlePage, using_params: { article_name: page }) +end + +Then(/^HoverCards is enabled as a beta feature$/) do + visit(SpecialPreferencesPage).enable_hovercards +end diff --git a/tests/browser/features/support/step_definitions/popups_core.rb b/tests/browser/features/support/step_definitions/popups_core.rb new file mode 100644 index 000000000..23f061b12 --- /dev/null +++ b/tests/browser/features/support/step_definitions/popups_core.rb @@ -0,0 +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 +end + +Then(/^I should not see a hover card$/) do + expect(on(ArticlePage).hovercard_element).not_to be_visible +end diff --git a/tests/browser/samples/links.wikitext b/tests/browser/samples/links.wikitext new file mode 100644 index 000000000..c89b4cbbf --- /dev/null +++ b/tests/browser/samples/links.wikitext @@ -0,0 +1,7 @@ +=Popups test page= + +==Valid links== +* [[Main Page]] + +==Invalid links== +# blah