Merge "Adding "diff.feature" selenium test"

This commit is contained in:
jenkins-bot 2019-04-11 18:19:56 +00:00 committed by Gerrit Code Review
commit b2448e0d23
11 changed files with 175 additions and 6 deletions

View File

@ -0,0 +1,30 @@
/**
* Extending the Mediawiki core webdriver config
*/
const path = require( 'path' ),
coreConfig = require( '../../../../../tests/selenium/wdio.conf' ),
relPath = ( foo ) => path.resolve( __dirname, '../..', foo ),
MinervaConfig = Object.assign( coreConfig.config, {
services: [],
specs: [
relPath( './selenium/features/*.feature' )
],
cucumberOpts: {
tagsInTitle: true,
timeout: 20000, // 20 seconds
require: [
relPath( './selenium/features/support/world.js' ),
relPath( './selenium/features/support/hooks.js' ),
relPath( './selenium/features/step_definitions/create_page_api_steps.js' ),
relPath( './selenium/features/step_definitions/common_steps.js' ),
relPath( './selenium/features/step_definitions/category_steps.js' ),
relPath( './selenium/features/step_definitions/editor_steps.js' ),
relPath( './selenium/features/step_definitions/diff_steps.js' ),
relPath( './selenium/features/step_definitions/special_history_steps.js' )
]
},
framework: 'cucumber'
} );
exports.config = MinervaConfig;

View File

@ -1,7 +1,5 @@
@chrome @en.m.wikipedia.beta.wmflabs.org @firefox @test2.m.wikipedia.org @vagrant @login
Feature: Page diff
@smoke @editing
Scenario: Added and removed content
Given I am logged into the mobile website
And I am on a page that has the following edits:

View File

@ -1,4 +1,4 @@
const { api } = require( '../support/world' ),
const { api, ArticlePage } = require( '../support/world' ),
Api = require( 'wdio-mediawiki/Api' );
const login = () => {
@ -46,7 +46,25 @@ const iAmInAWikiThatHasCategories = ( title ) => {
waitForPropagation( 5000 );
};
const iAmOnAPageThatHasTheFollowingEdits = function ( table ) {
const randomString = Math.random().toString( 36 ).substring( 7 ),
pageTitle = `Selenium_diff_test_${randomString}`,
edits = table.rawTable.map( ( row, i ) =>
[ i === 0 ? 'create' : 'edit', pageTitle, row[ 0 ] ] );
api.loginGetEditToken( {
username: browser.options.username,
password: browser.options.password,
apiUrl: `${browser.options.baseUrl}/api.php`
} )
.then( () => api.batch( edits ) )
.then( () => ArticlePage.open( pageTitle ) )
.catch( ( err ) => { throw err; } );
waitForPropagation( 5000 );
};
module.exports = {
waitForPropagation,
iAmOnAPageThatHasTheFollowingEdits,
iAmInAWikiThatHasCategories
};

View File

@ -0,0 +1,12 @@
const assert = require( 'assert' ),
{ DiffPage } = require( '../support/world.js' );
const iShouldSeeAddedContent = ( text ) => {
DiffPage.inserted_content_element.waitForVisible();
assert.strictEqual( DiffPage.inserted_content_element.getText(), text );
};
const iShouldSeeRemovedContent = ( text ) => {
assert.strictEqual( DiffPage.deleted_content_element.getText(), text );
};
module.exports = { iShouldSeeAddedContent, iShouldSeeRemovedContent };

View File

@ -1,5 +1,6 @@
const assert = require( 'assert' ),
{ ArticlePage, SpecialHistoryPage } = require( '../support/world' );
{ ArticlePage, SpecialHistoryPage,
SpecialMobileDiffPage } = require( '../support/world.js' );
const iClickOnTheHistoryLinkInTheLastModifiedBar = () => {
ArticlePage.last_modified_bar_history_link_element.waitForVisible();
@ -7,6 +8,13 @@ const iClickOnTheHistoryLinkInTheLastModifiedBar = () => {
assert.strictEqual( SpecialHistoryPage.side_list_element.isVisible(), true );
};
const iOpenTheLatestDiff = () => {
SpecialHistoryPage.last_contribution_link_element.waitForExist();
SpecialHistoryPage.last_contribution_link_element.click();
assert.strictEqual( SpecialMobileDiffPage.user_info_element.isVisible(), true );
};
module.exports = {
iOpenTheLatestDiff,
iClickOnTheHistoryLinkInTheLastModifiedBar
};

View File

@ -2,13 +2,18 @@ const { defineSupportCode } = require( 'cucumber' ),
{ iClickOnTheCategoryButton,
iShouldSeeTheCategoriesOverlay, iShouldSeeAListOfCategories
} = require( './category_steps' ),
{ iAmInAWikiThatHasCategories } = require( './create_page_api_steps' ),
{ iAmInAWikiThatHasCategories,
iAmOnAPageThatHasTheFollowingEdits } = require( './create_page_api_steps' ),
{
iAmUsingTheMobileSite,
iAmLoggedIntoTheMobileWebsite,
iAmOnPage, iAmInBetaMode
} = require( './common_steps' ),
{
iShouldSeeAddedContent, iShouldSeeRemovedContent
} = require( './diff_steps' ),
{
iOpenTheLatestDiff,
iClickOnTheHistoryLinkInTheLastModifiedBar
} = require( './history_steps' );
@ -27,11 +32,17 @@ defineSupportCode( function ( { Then, When, Given } ) {
Given( /^I am in a wiki that has categories$/, () => {
iAmInAWikiThatHasCategories( 'Selenium categories test page' );
} );
Given( /^I am on a page that has the following edits:$/, iAmOnAPageThatHasTheFollowingEdits );
// history steps
When( /^I open the latest diff$/, iOpenTheLatestDiff );
When( /^I click on the history link in the last modified bar$/,
iClickOnTheHistoryLinkInTheLastModifiedBar );
// diff steps
Then( /^I should see "(.*?)" as added content$/, iShouldSeeAddedContent );
Then( /^I should see "(.*?)" as removed content$/, iShouldSeeRemovedContent );
// Category steps
When( /^I click on the category button$/, iClickOnTheCategoryButton );

View File

@ -0,0 +1,17 @@
/**
* Represents a page showing the difference between two revisions
*
* @extends Page
* @example
* https://en.m.wikipedia.org/w/index.php?title=Barack_Obama&type=revision&diff=833886807&oldid=833885770&diffmode=source
*/
const { Page } = require( './mw_core_pages' );
class DiffPage extends Page {
get inserted_content_element() { return $( 'ins' ); }
get deleted_content_element() { return $( 'del' ); }
}
module.exports = new DiffPage();

View File

@ -3,5 +3,8 @@
* To simplify imports in world.js.
*/
module.exports = {
ArticlePage: require( './article_page' )
ArticlePage: require( './article_page' ),
SpecialHistoryPage: require( './special_history_page' ),
SpecialMobileDiffPage: require( './special_mobilediff_page' ),
DiffPage: require( './diff_page' )
};

View File

@ -0,0 +1,27 @@
const { Page } = require( './mw_core_pages' );
/**
* Represents the mobile-first Special:History page
*
* @extends Page
* @example
* https://en.m.wikipedia.org/wiki/Special:History/Barack_Obama
*/
class SpecialHistoryPage extends Page {
get content_header_bar_element() { return $( '.content-header' ); }
get content_header_bar_link_element() { return $( '.content-header a' ); }
get side_list_element() { return $( '.side-list' ); }
get last_contribution_element() { return $( '.side-list li' ); }
get last_contribution_link_element() { return $( '.side-list li a' ); }
get last_contribution_title_element() { return $( '.side-list li h3' ); }
get last_contribution_timestamp_element() { return $( '.side-list li p.timestamp' ); }
get last_contribution_edit_summary_element() { return $( '.side-list li p.edit-summary' ); }
get last_contribution_username_element() { return $( '.side-list li p.mw-mf-user' ); }
get more_link_element() { return $( '.more' ); }
open() {
super.open( 'Special:History' );
}
}
module.exports = new SpecialHistoryPage();

View File

@ -0,0 +1,16 @@
/**
* Represents the mobile-first Special:MobileDiff page
*
* @extends Page
* @example
* https://en.m.wikipedia.org/wiki/Special:MobileDiff/833886807
*/
const { Page } = require( './mw_core_pages' );
class SpecialMobileDiffPage extends Page {
get user_info_element() { return $( '#mw-mf-userinfo' ); }
}
module.exports = new SpecialMobileDiffPage();

View File

@ -0,0 +1,29 @@
const { iAmOnAPageThatHasTheFollowingEdits
} = require( '../features/step_definitions/create_page_api_steps' ),
{
iAmLoggedIntoTheMobileWebsite
} = require( '../features/step_definitions/common_steps' ),
{
iShouldSeeAddedContent, iShouldSeeRemovedContent
} = require( '../features/step_definitions/diff_steps' ),
{
iOpenTheLatestDiff,
iClickOnTheHistoryLinkInTheLastModifiedBar
} = require( '../features/step_definitions/history_steps' );
describe( 'Page diff', () => {
it( 'Added and removed content', () => {
iAmLoggedIntoTheMobileWebsite();
iAmOnAPageThatHasTheFollowingEdits( {
rawTable: [
[ ' text ' ],
[ ' ABC DEF ' ],
[ ' ABC GHI ' ]
]
} );
iClickOnTheHistoryLinkInTheLastModifiedBar();
iOpenTheLatestDiff();
iShouldSeeAddedContent( 'GHI' );
iShouldSeeRemovedContent( 'DEF' );
} );
} );