Port Popups browser tests to selenium

Bug: T177262
Change-Id: Ie77cf7bc79f454904983ed5cf65dc9fe2b1ececc
This commit is contained in:
jdlrobson 2017-09-01 10:35:04 -04:00
parent 48da56b1b4
commit cf774be88b
17 changed files with 139 additions and 288 deletions

View file

@ -1,6 +0,0 @@
source 'https://rubygems.org'
gem 'chunky_png', '~> 1.3.4'
gem 'mediawiki_selenium', '~> 1.7', '>= 1.7.1'
gem 'rake', '~> 10.4', '>= 10.4.2'
gem 'rubocop', '~> 0.29.1', require: false

View file

@ -1,124 +0,0 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.3.0)
astrolabe (1.3.1)
parser (~> 2.2)
builder (3.2.2)
childprocess (0.5.9)
ffi (~> 1.0, >= 1.0.11)
chunky_png (1.3.8)
cucumber (1.3.20)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.12)
multi_json (>= 1.7.5, < 2.0)
multi_test (>= 0.1.2)
data_magic (1.0)
faker (>= 1.1.2)
yml_reader (>= 0.6)
diff-lcs (1.2.5)
dimensions (1.2.0)
domain_name (0.5.20161129)
unf (>= 0.0.5, < 1.0.0)
faker (1.6.6)
i18n (~> 0.5)
faraday (0.10.0)
multipart-post (>= 1.2, < 3)
faraday-cookie_jar (0.0.6)
faraday (>= 0.7.4)
http-cookie (~> 1.0.0)
faraday_middleware (0.10.1)
faraday (>= 0.7.4, < 1.0)
ffi (1.9.14)
gherkin (2.12.2)
multi_json (~> 1.3)
headless (2.3.1)
http-cookie (1.0.3)
domain_name (~> 0.5)
i18n (0.7.0)
jsduck (5.3.4)
dimensions (~> 1.2.0)
json (~> 1.8.0)
parallel (~> 0.7.1)
rdiscount (~> 2.1.6)
rkelly-remix (~> 0.0.4)
json (1.8.3)
mediawiki_api (0.7.0)
faraday (~> 0.9, >= 0.9.0)
faraday-cookie_jar (~> 0.0, >= 0.0.6)
faraday_middleware (~> 0.10, >= 0.10.0)
mediawiki_selenium (1.7.3)
cucumber (~> 1.3, >= 1.3.20)
headless (~> 2.0, >= 2.1.0)
json (~> 1.8, >= 1.8.1)
mediawiki_api (~> 0.7, >= 0.7.0)
page-object (~> 1.0)
rest-client (~> 1.6, >= 1.6.7)
rspec-core (~> 2.14, >= 2.14.4)
rspec-expectations (~> 2.14, >= 2.14.4)
selenium-webdriver (< 3)
syntax (~> 1.2, >= 1.2.0)
thor (~> 0.19, >= 0.19.1)
mime-types (2.99.3)
multi_json (1.12.1)
multi_test (0.1.2)
multipart-post (2.0.0)
net-http-persistent (2.9.4)
netrc (0.11.0)
page-object (1.2.2)
net-http-persistent (~> 2.9.4)
page_navigation (>= 0.9)
selenium-webdriver (>= 2.53.0)
watir-webdriver (>= 0.6.11, < 0.9.9)
page_navigation (0.10)
data_magic (>= 0.22)
parallel (0.7.1)
parser (2.3.3.1)
ast (~> 2.2)
powerpack (0.1.1)
rainbow (2.1.0)
rake (10.5.0)
rdiscount (2.1.8)
rest-client (1.8.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rkelly-remix (0.0.7)
rspec-core (2.99.2)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0)
rubocop (0.29.1)
astrolabe (~> 1.3)
parser (>= 2.2.0.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4)
ruby-progressbar (1.8.1)
rubyzip (1.2.0)
selenium-webdriver (2.53.4)
childprocess (~> 0.5)
rubyzip (~> 1.0)
websocket (~> 1.0)
syntax (1.2.1)
thor (0.19.4)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
watir-webdriver (0.9.3)
selenium-webdriver (>= 2.46.2)
websocket (1.2.3)
yml_reader (0.7)
PLATFORMS
ruby
DEPENDENCIES
chunky_png (~> 1.3.4)
jsduck (~> 5.3.4)
mediawiki_selenium (~> 1.7, >= 1.7.1)
rake (~> 10.4, >= 10.4.2)
rubocop (~> 0.29.1)
BUNDLED WITH
1.12.5

View file

@ -1,51 +0,0 @@
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

@ -1,45 +0,0 @@
# 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: https://en.m.wikipedia.beta.wmflabs.org/wiki/
mediawiki_user: Selenium_user
# mediawiki_password: SET THIS IN THE ENVIRONMENT!
test2:
mediawiki_url: https://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

@ -1,13 +0,0 @@
@chrome @en.m.wikipedia.beta.wmflabs.org @firefox @test2.m.wikipedia.org @vagrant @integration
Feature: Previews
Background:
Given I am on the test page
Scenario: Dwelling on a valid link shows a preview
When I dwell on the first valid link
Then I should see a preview
Scenario: Abandoning the link hides the preview
When I dwell on the first valid link
And I abandon the link
Then I should not see a preview

View file

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

View file

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

View file

@ -1,11 +0,0 @@
# 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

@ -1,9 +0,0 @@
TEST_PAGE_TITLE = 'Popups test page'
Given(/^I am on the test page$/) do
api.create_page TEST_PAGE_TITLE, File.read('fixtures/test_page.wikitext')
visit(ArticlePage, using_params: { article_name: TEST_PAGE_TITLE }) do |page|
page.wait_until_rl_module_ready('ext.popups')
end
end

View file

@ -1,20 +0,0 @@
When(/^I dwell on the first valid link$/) do
on(ArticlePage).first_valid_link_element.hover
end
When(/^I abandon the link$/) do
on(ArticlePage).page_header_element.hover
end
Then(/^I should see a preview$/) do
expect(on(ArticlePage).hovercard_element.when_present(5)).to be_visible
end
Then(/^I should not see a preview$/) do
# Requesting a preview hits the API so wait some time before asserting it did
# not show.
sleep 5
expect(on(ArticlePage).hovercard_element).not_to be_visible
end

View file

@ -0,0 +1,17 @@
{
"extends": "../../.eslintrc.json",
"env": {
"es6": true,
"mocha": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 6
},
"globals": {
"browser": false
},
"rules": {
"no-console": 0
}
}

32
tests/selenium/README.md Normal file
View file

@ -0,0 +1,32 @@
# Selenium tests
Please see tests/selenium/README.md file in mediawiki/core repository.
## Usage
Set up MediaWiki-Vagrant:
cd mediawiki/vagrant
vagrant up
vagrant roles enable popups
vagrant provision
From mediawiki/core folder:
echo 'include_once "$IP/extensions/Popups/tests/browser/LocalSettings.php";' >> LocalSettings.php
Run both mediawiki/core and Popups tests from mediawiki/core folder:
npm run selenium
To run only Popups tests in one terminal window or tab start Chromedriver:
chromedriver --url-base=/wd/hub --port=4444
In another terminal tab or window go to mediawiki/core folder:
./node_modules/.bin/wdio tests/selenium/wdio.conf.js --spec extensions/Popups/tests/selenium/specs/*.js
Run only one Popups test file from mediawiki/core:
./node_modules/.bin/wdio tests/selenium/wdio.conf.js --spec extensions/Popups/tests/selenium/specs/file-name.js

View file

@ -0,0 +1,66 @@
'use strict';
const Page = require( '../../../../../tests/selenium/pageobjects/page' );
const TEST_PAGE_TITLE = 'Popups test page';
const POPUPS_SELECTOR = '.mwe-popups';
const POPUPS_MODULE_NAME = 'ext.popups';
const fs = require('fs');
const EditPage = require( '../../../../../tests/selenium/pageobjects/edit.page' );
class PopupsPage extends Page {
setup() {
browser.call( function () {
return new Promise( function ( resolve ) {
fs.readFile(`${__dirname}/../fixtures/test_page.wikitext`, 'utf-8', function (err, content) {
if ( err ) {
throw err;
}
resolve( content );
} );
} ).then( function ( content ) {
return EditPage.apiEdit( TEST_PAGE_TITLE, content );
} );
} );
}
resourceLoaderModuleStatus( moduleName, moduleStatus, errMsg ) {
return browser.waitUntil( function () {
return browser.execute( function ( module ) {
return mw && mw.loader && mw.loader.getState( module.name ) === module.status;
}, { status: moduleStatus, name: moduleName } );
}, 10000, errMsg );
}
isReady() {
return this.resourceLoaderModuleStatus( POPUPS_MODULE_NAME, 'ready', 'Page previews did not load' );
}
abandonLink() {
browser.moveToObject( '#content h1' );
}
dwellLink() {
this.isReady();
browser.moveToObject( '#content h1' );
browser.moveToObject( '#content ul a' );
browser.waitForExist( POPUPS_SELECTOR );
}
doNotSeePreview() {
return browser.waitUntil( function () {
return !browser.isVisible( POPUPS_SELECTOR );
} );
}
seePreview() {
return browser.isVisible( POPUPS_SELECTOR );
}
open() {
super.open( TEST_PAGE_TITLE );
}
}
module.exports = new PopupsPage();

View file

@ -0,0 +1,24 @@
'use strict';
const assert = require( 'assert' );
const page = require( '../pageobjects/popups.page' );
describe( 'Dwelling on a valid link', function () {
before( function () {
page.setup();
} );
it( 'I should see a preview', function () {
page.open();
page.dwellLink();
assert( page.seePreview() );
} );
it( 'Abandoning link hides preview', function () {
page.open();
page.dwellLink();
page.abandonLink();
assert( page.doNotSeePreview() );
} );
} );