Merge "Add browser test for hovering link"

This commit is contained in:
Phuedx 2016-04-19 13:28:04 +00:00 committed by Gerrit Code Review
commit def7e41192
12 changed files with 189 additions and 0 deletions

7
Gemfile Normal file
View file

@ -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

View file

@ -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=<username here> # Linux/Unix/Mac
set MEDIAWIKI_USER=<username here> # Windows
export MEDIAWIKI_PASSWORD=<password here> # Linux/Unix/Mac
set MEDIAWIKI_PASSWORD=<password here> # 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

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,3 @@
require 'mediawiki_selenium/cucumber'
require 'mediawiki_selenium/pages'
require 'mediawiki_selenium/step_definitions'

View file

@ -0,0 +1,6 @@
# Needed for cucumber --dry-run -f stepdefs
require_relative 'env'
Before('@skip') do |scenario|
scenario.skip_invoke!
end

View file

@ -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

View file

@ -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

Binary file not shown.

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,7 @@
=Popups test page=
==Valid links==
* [[Main Page]]
==Invalid links==
# blah