Merge "Rewrite browser tests for Echo"

This commit is contained in:
jenkins-bot 2015-09-28 13:05:28 +00:00 committed by Gerrit Code Review
commit 390dc4afa2
24 changed files with 159 additions and 316 deletions

11
Gemfile
View file

@ -1,7 +1,8 @@
# ruby=ruby-2.1.1
# ruby-gemset=Echo
source 'https://rubygems.org'
gem 'chunky_png', '~> 1.3.4'
gem 'csscss', '~> 1.3.3'
gem 'mediawiki_api', '~> 0.3.0'
gem 'mediawiki_selenium', '~> 0.4.2'
gem 'rubocop', '~> 0.29.0', require: false
gem 'csscss'
gem 'mediawiki_selenium', '~> 1.4.0'
gem 'rubocop', require: false

View file

@ -8,7 +8,6 @@ GEM
builder (3.2.2)
childprocess (0.5.6)
ffi (~> 1.0, >= 1.0.11)
chunky_png (1.3.4)
colorize (0.7.7)
csscss (1.3.3)
colorize
@ -40,18 +39,19 @@ GEM
domain_name (~> 0.5)
i18n (0.7.0)
json (1.8.3)
mediawiki_api (0.3.1)
mediawiki_api (0.5.0)
faraday (~> 0.9, >= 0.9.0)
faraday-cookie_jar (~> 0.0, >= 0.0.6)
mediawiki_selenium (0.4.3)
cucumber (~> 1.3, >= 1.3.10)
mediawiki_selenium (1.4.0)
cucumber (~> 1.3, >= 1.3.20)
headless (~> 1.0, >= 1.0.1)
json (~> 1.8, >= 1.8.1)
mediawiki_api (~> 0.2, >= 0.2.1)
mediawiki_api (~> 0.4, >= 0.4.1)
page-object (~> 1.0)
rest-client (~> 1.6, >= 1.6.7)
rspec-expectations (~> 2.14, >= 2.14.4)
syntax (~> 1.2, >= 1.2.0)
thor (~> 0.19, >= 0.19.1)
mime-types (2.6.2)
multi_json (1.11.2)
multi_test (0.1.2)
@ -75,9 +75,9 @@ GEM
netrc (~> 0.7)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0)
rubocop (0.29.1)
rubocop (0.34.2)
astrolabe (~> 1.3)
parser (>= 2.2.0.1, < 3.0)
parser (>= 2.2.2.5, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4)
@ -89,6 +89,7 @@ GEM
rubyzip (~> 1.0)
websocket (~> 1.0)
syntax (1.2.0)
thor (0.19.1)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.1)
@ -101,8 +102,9 @@ PLATFORMS
ruby
DEPENDENCIES
chunky_png (~> 1.3.4)
csscss (~> 1.3.3)
mediawiki_api (~> 0.3.0)
mediawiki_selenium (~> 0.4.2)
rubocop (~> 0.29.0)
csscss
mediawiki_selenium (~> 1.4.0)
rubocop
BUNDLED WITH
1.10.5

View file

@ -106,7 +106,8 @@
// The following messages can be used here:
// echo-notification-alert-text-only
// echo-notification-message-text-only
label: mw.msg( 'echo-notification-' + this.type + '-text-only' )
label: mw.msg( 'echo-notification-' + this.type + '-text-only' ),
classes: [ 'mw-echo-ui-notificationBadgeButtonPopupWidget-popup' ]
} );
// HACK: Add an icon to the popup head label
this.popupHeadIcon = new OO.ui.IconWidget();

1
tests/browser/README.md Normal file
View file

@ -0,0 +1 @@
Please see https://github.com/wikimedia/mediawiki-selenium for instructions on how to run tests.

View file

@ -0,0 +1,46 @@
# 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
user_factory: true
mediawiki_url: http://127.0.0.1:8080/wiki/
mw-vagrant-guest:
user_factory: true
mediawiki_url: http://127.0.0.1/wiki/
local:
mediawiki_user: Admin
mediawiki_password: vagrant
mediawiki_user_b: Selenium Flow user 2
mediawiki_url: http://127.0.0.1:8080/wiki/
beta:
mediawiki_url: http://en.wikipedia.beta.wmflabs.org/wiki/
mediawiki_user: Selenium_user
mediawiki_user_b: Selenium Flow user 2
# 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:
user_factory: true
# mediawiki_url: THIS WILL BE SET BY JENKINS
default: *default

View file

@ -1,17 +0,0 @@
@chrome @en.wikipedia.beta.wmflabs.org @firefox @login @test2.wikipedia.org
Feature: Flyout
Background:
Given I am on the "Selenium Echo flyout test page" page
Scenario: Flyout button not present when anon
Then I do not see the notification flyout button
Scenario: Flyout button present
Given I am logged in
Then I see the notification flyout button
Scenario: Flyout button present
Given I am logged in
When I click the notification flyout button
Then I see the notification flyout

View file

@ -1,12 +0,0 @@
@custom-browser @en.wikipedia.beta.wmflabs.org @firefox @login @test2.wikipedia.org
Feature: Flyout (nojs)
Background:
Given I am using user agent "Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)"
And I am on the "Selenium Echo flyout test page" page
Scenario: Flyout button present
Given I am logged in
When I click the notification flyout button
Then I am on the Special Notifications page
And I see the first heading on the page says Notifications

View file

@ -1,15 +0,0 @@
@chrome @en.wikipedia.beta.wmflabs.org @firefox @login @test2.wikipedia.org
Feature: Scenarios that trigger notifications
Scenario: Mark all as read
Given I am logged in with no notifications
And I have a Flow message that triggers an alert notification
And another user mentions me on the wiki
And I am on the "Selenium Echo flyout test page" page
And I have new notifications
And I click the notification flyout button
And I see the notification flyout
And I click for the Messages view
When I click the mark all as read button
And I am on the "Selenium Echo flyout test page" page
Then I have no new notifications

View file

@ -0,0 +1,11 @@
@firefox
@en.wikipedia.beta.wmflabs.org
Feature: Basic features for no-js functionality
Background:
Given I am using user agent "Mozilla/4.0 (compatible; MSIE 5.5b1; Mac_PowerPC)"
Scenario: Clicking alerts badge goes to Special:Notifications
Given I am logged in
When I click the alert badge
Then I am on Special Notifications page

View file

@ -1,40 +0,0 @@
@chrome @en.wikipedia.beta.wmflabs.org @firefox @login @test2.wikipedia.org
Feature: Notification types
# Scenarios which trigger notifications
Scenario: Someone links to a page I created
Given I am logged in with no notifications
And another user has linked to a page I created from another page
And I reload the page 5 times or until a notification shows up
When I am on the "Selenium Echo flyout test page" page
Then I have new notifications
Scenario: Mention message triggers notification
Given I am logged in with no notifications
And another user mentions me on the wiki
And I reload the page 5 times or until a notification shows up
When I am on the "Selenium Echo flyout test page" page
Then I have new notifications
Scenario: Talk page message triggers talk notification
Given I am logged in with no notifications
# And I do not have Flow boards enabled on the user talk namespace
And another user writes on my talk page
And I reload the page 5 times or until a notification shows up
When I am on the "Selenium Echo flyout test page" page
Then I have new notifications
Scenario: New user gets a sign up notification
Given I am logged in as a new user
And I am on the "Selenium Echo flyout test page" page
Then I have new notifications
Scenario: Page revert
# Too hard. Will do later.
# Scenarios which do not trigger notifications (but might be expected to)
Scenario: The @ message is not a keyword
Given I am logged in with no notifications
And another user @s me on "Talk:Echo at test"
When I am on the "Selenium Echo flyout test page" page
Then I have no new notifications

View file

@ -1,10 +0,0 @@
@chrome @firefox @login
Feature: User rights
Scenario: Change in user rights
Given I am logged in as a new user with no notifications
# This step requires user rights. Selenium user doesn't have sufficient user rights on beta labs.
When my user rights get changed
And I come back from grabbing a cup of coffee
And I am on the "Selenium Echo flyout test page" page
Then I have new notifications

View file

@ -0,0 +1,10 @@
@firefox
@en.wikipedia.beta.wmflabs.org
Feature: Basic features for no-js functionality
Background:
Given I am logged in
Scenario: Clicking alerts badge loads the alert popup
When I click the alert badge
Then I see the alert popup

View file

@ -0,0 +1,6 @@
# Steps related to clicking and interacting with the badge
# Work in both nojs and js version
Given(/^I click the alert badge$/) do
on(ArticlePage).notifications_badge_alert
end

View file

@ -0,0 +1,12 @@
# This test has no javascript
# Therefore this test has no AJAX
# Therefore it should run without any "when_present" clauses
# If you need a "when_present" to make the test run, that is a bug
Given(/^I am using user agent "(.+)"$/) do |user_agent|
browser_factory.override(browser_user_agent: user_agent)
end
Given(/^I am on Special Notifications page$/) do
expect(on(SpecialNotificationsPage).firstHeading).to match('Notifications')
end

View file

@ -0,0 +1,5 @@
Given(/^I see the alert popup$/) do
on(ArticlePage) do |page|
expect(page.popup_title(page.popup_alert_element).text).to match('Alerts')
end
end

View file

@ -1,61 +0,0 @@
def new_username
"EchoUserNew#{@random_string}"
end
def session_username
"#{ENV['MEDIAWIKI_USER']}_#{@browser.name}"
end
def session_username_b
'EchoUser'
end
Given(/^I am logged in as the user "(.*?)"$/) do |username|
step 'the user "' + username + '" exists'
visit(LoginPage).login_with(username, ENV['MEDIAWIKI_PASSWORD'])
end
# Note Echo redefines this so that the user is unique to the current browser
Given(/^I am logged in my non-shared account$/) do
username = session_username
step 'I am logged in as the user "' + username + '"'
end
Given(/^I am on the "(.+)" page$/) do |title|
on(APIPage).create title, 'Test is used by Selenium web driver'
visit(ArticlePage, using_params: { article_name: title })
end
Given(/^I am using user agent "(.+)"$/) do |user_agent|
@user_agent = user_agent
@browser = browser(test_name(@scenario), user_agent: user_agent)
$session_id = @browser.driver.instance_variable_get(:@bridge).session_id
end
Given(/^my user rights get changed$/) do
@username = new_username
client = on(APIPage).client
client.log_in(ENV['MEDIAWIKI_USER'], ENV['MEDIAWIKI_PASSWORD'])
resp = client.query(action: 'query', list: 'users', ususers: @username, ustoken: 'userrights')
data = resp.data
@token = data['users'][0]['userrightstoken']
client.action('userrights', token_type: false, token: @token, add: 'bot', user: @username)
end
Given(/^the user "(.*?)" exists$/) do |username|
on(APIPage).client.log_in(ENV['MEDIAWIKI_USER'], ENV['MEDIAWIKI_PASSWORD'])
begin
on(APIPage).client.create_account(username, ENV['MEDIAWIKI_PASSWORD'])
puts 'Successfully created user ' + username
rescue MediawikiApi::ApiError
puts 'Assuming in step that user ' + username + ' already exists since was unable to create.'
end
end
Then(/^I am on the Special Notifications page$/) do
expect(@browser.url).to match 'Special:Notifications'
end
Then(/^I see the first heading on the page says Notifications$/) do
expect(on(ArticlePage).first_heading).to eq 'Notifications'
end

View file

@ -1,18 +0,0 @@
When(/^I click the notification flyout button$/) do
# Sleep works around Chrome 40 issue that began
# ~2015-03-04
sleep 1
on(ArticlePage).flyout_link_element.when_present.click
end
Then(/^I do not see the notification flyout button$/) do
expect(on(ArticlePage).flyout_link_container_element).not_to be_visible
end
Then(/^I see the notification flyout$/) do
expect(on(ArticlePage).flyout_element.when_present).to be_visible
end
Then(/^I see the notification flyout button$/) do
expect(on(ArticlePage).flyout_link_container_element.when_present).to be_visible
end

View file

@ -1,17 +0,0 @@
Given(/^I click for the Messages view$/) do
on(ArticlePage).messages_view_link_element.when_present.click
end
Given(/^I have a Flow message that triggers an alert notification$/) do
client = on(APIPage).client
username = session_username_b
step 'the user "' + username + '" exists'
client.log_in(username, ENV['MEDIAWIKI_PASSWORD'])
client.action(
'flow', token_type: 'edit', submodule: 'new-topic', page: 'Talk:Flow QA', nttopic: 'Mention #1',
ntcontent: '[[User:' + session_username + ']] I wanted to say hello.')
end
When(/^I click the mark all as read button$/) do
on(ArticlePage).mark_as_read_element.when_present.click
end

View file

@ -1,91 +0,0 @@
def make_page_with_user(title, text, username)
client = on(APIPage).client
client.log_in(username, ENV['MEDIAWIKI_PASSWORD'])
client.create_page(title, text)
end
def clear_notifications(username)
client = on(APIPage).client
step 'the user "' + username + '" exists'
client.log_in(username, ENV['MEDIAWIKI_PASSWORD'])
client.action('echomarkread', token_type: 'edit', all: '1')
end
def make_page_with_user_b(title, text)
username = session_username_b
step 'the user "' + username + '" exists'
make_page_with_user(title, text, username)
end
def make_page_with_user_a(title, text)
make_page_with_user(title, text, session_username)
end
def poll_for_new_notifications(number_of_polls)
number_of_polls.to_i.times do
step 'I am on the "Selenium Echo flyout test page" page'
break if on(ArticlePage).flyout_link_element.class_name =~ /mw-echo-unseen-notifications/
end
end
Given(/^another user has linked to a page I created from another page$/) do
title = 'Selenium Echo link test ' + @random_string
make_page_with_user_a(title, 'Selenium test page. Feel free to delete me.')
title2 = title + ' ' + @random_string
make_page_with_user_b(title2, 'I am linking to [[' + title + ']].')
end
Given(/^another user writes on my talk page$/) do
make_page_with_user_b(
'User talk:' + session_username,
"== Barnstar ==\nHello Selenium, here is a barnstar for all your testing! " +
@random_string + "~~~~\n")
end
Given(/^another user @s me on "(.*?)"$/) do |title|
username = session_username.sub('_', ' ')
text = '@' + username + ' Cho cho cho. ~~~~'
make_page_with_user_b(title, text)
end
Given(/^I reload the page (.*?) times or until a notification shows up$/) do |number_of_polls|
poll_for_new_notifications(number_of_polls)
end
Given(/^another user mentions me on the wiki$/) do
title = 'Selenium Echo mention test ' + @random_string
username = session_username.sub('_', ' ')
text = "== The walrus ==\n[[User:" + username + "]]: Cho cho cho. ~~~~\n"
make_page_with_user_b(title, text)
end
Given(/^I am logged in as a new user$/) do
@username = new_username
step 'I am logged in as the user "' + @username + '"'
end
Given(/^I am logged in as a new user with no notifications$/) do
@username = new_username
clear_notifications(@username)
step 'I am logged in as the user "' + @username + '"'
end
Given(/^I am logged in with no notifications$/) do
# Mark all messages as read
client = on(APIPage).client
username = session_username
step 'the user "' + username + '" exists'
client.log_in(username, ENV['MEDIAWIKI_PASSWORD'])
client.action('echomarkread', token_type: 'edit', all: '1')
step 'I am logged in my non-shared account'
step 'I have no new notifications'
end
Then(/^I have no new notifications$/) do
expect(on(ArticlePage).flyout_link_element.when_present.class_name).not_to match 'mw-echo-unseen-notifications'
end
Then(/^I have new notifications$/) do
expect(on(ArticlePage).flyout_link_element.when_present.class_name).to match 'mw-echo-unseen-notifications'
end

View file

@ -0,0 +1,11 @@
# Data manager for Echo tests
class DataManager
def initialize
@data = {}
end
def get(part)
@data[part] = "#{part}_#{Random.srand}" unless @data.key? part
@data[part]
end
end

View file

@ -1,12 +1,11 @@
require 'rubygems'
require 'bundler/setup'
require 'mediawiki_selenium'
Bundler.require
require 'mediawiki_selenium/support'
require 'mediawiki_selenium/step_definitions'
if ENV['PAGE_WAIT_TIMEOUT']
PageObject.default_page_wait = ENV['PAGE_WAIT_TIMEOUT'].to_i
def env_or_default(key, default)
ENV[key].nil? ? default : ENV[key].to_i
end
if ENV['ELEMENT_WAIT_TIMEOUT']
PageObject.default_element_wait = ENV['ELEMENT_WAIT_TIMEOUT'].to_i
end
PageObject.default_page_wait = env_or_default 'PAGE_WAIT_TIMEOUT', 10
PageObject.default_element_wait = env_or_default 'ELEMENT_WAIT_TIMEOUT', 30

View file

@ -1,3 +1,6 @@
# Allow running of bundle exec cucumber --dry-run -f stepdefs
require 'mediawiki_selenium'
require 'page-object'
require_relative 'data_manager'
Before { @data_manager = DataManager.new }

View file

@ -1,16 +1,24 @@
# Page Object describing Headings, Flyouts, and Overlay in Echo
class ArticlePage
include PageObject
include URL
page_url URL.url('<%=params[:article_name]%><%=params[:hash]%>')
h1(:first_heading, id: 'firstHeading')
li(:flyout_link_container, css: '#pt-notifications')
a(:flyout_link, css: '#pt-notifications a')
div(:flyout, css: '.mw-echo-overlay')
# Overlay header
a(:alert_tab_link, css: '.mw-echo-overlay-title ul li a', index: 1)
button(:mark_as_read, css: '.mw-echo-notifications > button')
a(:messages_view_link, css: '.mw-ui-active')
li(:notifications_alert, css: '#pt-notifications-alert')
li(:notifications_message, css: '#pt-notifications-message')
link(:notifications_badge_alert, css: '#pt-notifications-alert a')
link(:notifications_badge_message, css: '#pt-notifications-message a')
div(:popup_alert, css: '#pt-notifications-alert .mw-echo-ui-notificationBadgeButtonPopupWidget-popup')
div(:popup_message, css: '#pt-notifications-message .mw-echo-ui-notificationBadgeButtonPopupWidget-popup')
# Popup elements
button(:mark_all_read_button, css: '.mw-echo-ui-notificationsWidget-markAllReadButton')
def popup_title(popupElement)
popupElement.when_present.span_element(css: '.oo-ui-popupWidget-head > .oo-ui-labelElement-label')
end
# span(:popup_title, css: '.oo-ui-popupWidget-head > .oo-ui-labelElement-label')
# Notification elements
a(:notification_option, css: '.mw-echo-ui-notificationOptionWidget')
a(:notification_option_markRead, css: '.mw-echo-ui-notificationOptionWidget-markAsReadButton')
end

View file

@ -0,0 +1,8 @@
# Special:Notifications page
class SpecialNotificationsPage
include PageObject
page_url 'Special:Notifications'
h1(:firstHeading, css: '.firstHeading')
end