wiki.techinc.nl/tests/selenium/specs/page.js
Timo Tijhof 22d149c3f7 selenium: Fix more inefficient MWBot use and simplify wdio-mediawiki Api
This does the same for the other specs, as previously done to the
page.js spec in 058d5b7cd8.

* rollkback: From 6 api logins to 4 api logins.
  Before (2x3): admin for edit, admin for createaccount, vandal for edit.
  After (2x2): admin for edit + createaccount, vandal for edit.

* recentchanges spec: No difference, but updated pattern for consistency
  so that if it is extended in the future, it will be natural to re-use
  the bot object instead of creating a new one.

* watchlist spec: From 3 api logins to 1 api login.
  Before: admin for createaccount, admin for edit, admin for edit.
  After: admin (re-used)

* user spec: From 2 to 1 api login.

Also:

* Remove the now-unused Api.edit() and Api.delete() anti-pattern
  methods, as these are nothing but one-line shortcuts to the
  already one-line invocation of bot.edit() and bot.delete(),
  except that they bypassed the current bot object, causing
  inefficient repeat logins in way that was non-obvious.
  Migration is simple and won't be required until other repos
  upgrade to the next wdio-mediawiki version (not yet released).

* Make 'bot' a mandatory parameter for the createAccount, block,
  and unblock convenience wrapper methods.

* Move the vandalizePage() method from HistoryPage to rollback spec,
  as it had no connection with that page object or the action=history
  interface, and document why it can't (yet) re-use its bot object.

Bug: T234002
Change-Id: Id6e995916566f7dd7b618892295198b897fbee2e
2019-10-04 18:16:28 +01:00

138 lines
3.9 KiB
JavaScript

const assert = require( 'assert' );
const Api = require( 'wdio-mediawiki/Api' );
const DeletePage = require( '../pageobjects/delete.page' );
const RestorePage = require( '../pageobjects/restore.page' );
const EditPage = require( '../pageobjects/edit.page' );
const HistoryPage = require( '../pageobjects/history.page' );
const UndoPage = require( '../pageobjects/undo.page' );
const UserLoginPage = require( 'wdio-mediawiki/LoginPage' );
const Util = require( 'wdio-mediawiki/Util' );
describe( 'Page', function () {
let content, name, bot;
before( async () => {
bot = await Api.bot();
} );
beforeEach( function () {
browser.deleteAllCookies();
content = Util.getTestString( 'beforeEach-content-' );
name = Util.getTestString( 'BeforeEach-name-' );
} );
it( 'should be previewable', function () {
EditPage.preview( name, content );
assert.strictEqual( EditPage.heading.getText(), 'Creating ' + name );
assert.strictEqual( EditPage.displayedContent.getText(), content );
assert( EditPage.content.isDisplayed(), 'editor is still present' );
assert( !EditPage.conflictingContent.isDisplayed(), 'no edit conflict happened' );
} );
it( 'should be creatable', function () {
// create
EditPage.edit( name, content );
// check
assert.strictEqual( EditPage.heading.getText(), name );
assert.strictEqual( EditPage.displayedContent.getText(), content );
} );
it( 'should be re-creatable', function () {
const initialContent = Util.getTestString( 'initialContent-' );
// create and delete
browser.call( async () => {
await bot.edit( name, initialContent, 'create for delete' );
await bot.delete( name, 'delete prior to recreate' );
} );
// re-create
EditPage.edit( name, content );
// check
assert.strictEqual( EditPage.heading.getText(), name );
assert.strictEqual( EditPage.displayedContent.getText(), content );
} );
it( 'should be editable @daily', function () {
// create
browser.call( async () => {
await bot.edit( name, content, 'create for edit' );
} );
// edit
const editContent = Util.getTestString( 'editContent-' );
EditPage.edit( name, editContent );
// check
assert.strictEqual( EditPage.heading.getText(), name );
assert( EditPage.displayedContent.getText().includes( editContent ) );
} );
it( 'should have history @daily', function () {
// create
browser.call( async () => {
await bot.edit( name, content, `created with "${content}"` );
} );
// check
HistoryPage.open( name );
assert.strictEqual( HistoryPage.comment.getText(), `created with "${content}"` );
} );
it( 'should be deletable', function () {
// create
browser.call( async () => {
await bot.edit( name, content, 'create for delete' );
} );
// login
UserLoginPage.loginAdmin();
// delete
DeletePage.delete( name, 'delete reason' );
// check
assert.strictEqual(
DeletePage.displayedContent.getText(),
'"' + name + '" has been deleted. See deletion log for a record of recent deletions.\nReturn to Main Page.'
);
} );
it( 'should be restorable', function () {
// create and delete
browser.call( async () => {
await bot.edit( name, content, 'create for delete' );
await bot.delete( name, 'delete for restore' );
} );
// login
UserLoginPage.loginAdmin();
// restore
RestorePage.restore( name, 'restore reason' );
// check
assert.strictEqual( RestorePage.displayedContent.getText(), name + ' has been restored\nConsult the deletion log for a record of recent deletions and restorations.' );
} );
it( 'should be undoable', function () {
let previousRev, undoRev;
browser.call( async () => {
// create
await bot.edit( name, content, 'create to edit and undo' );
// edit
const response = await bot.edit( name, Util.getTestString( 'editContent-' ) );
previousRev = response.edit.oldrevid;
undoRev = response.edit.newrevid;
} );
UndoPage.undo( name, previousRev, undoRev );
assert.strictEqual( EditPage.displayedContent.getText(), content );
} );
} );