2020-05-14 21:14:42 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
2019-10-01 01:36:15 +00:00
|
|
|
const assert = require( 'assert' );
|
2021-07-08 03:49:25 +00:00
|
|
|
const CreateAccountPage = require( 'wdio-mediawiki/CreateAccountPage' );
|
2019-10-01 01:36:15 +00:00
|
|
|
const UserLoginPage = require( 'wdio-mediawiki/LoginPage' );
|
|
|
|
|
const Api = require( 'wdio-mediawiki/Api' );
|
|
|
|
|
const Util = require( 'wdio-mediawiki/Util' );
|
2016-12-19 16:39:29 +00:00
|
|
|
|
|
|
|
|
describe( 'User', function () {
|
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 058d5b7cd857af.
* 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-01 02:10:05 +00:00
|
|
|
let password, username, bot;
|
|
|
|
|
|
|
|
|
|
before( async () => {
|
|
|
|
|
bot = await Api.bot();
|
|
|
|
|
} );
|
2016-12-19 16:39:29 +00:00
|
|
|
|
|
|
|
|
beforeEach( function () {
|
2019-09-27 03:08:00 +00:00
|
|
|
browser.deleteAllCookies();
|
2018-06-20 11:06:45 +00:00
|
|
|
username = Util.getTestString( 'User-' );
|
|
|
|
|
password = Util.getTestString();
|
2016-12-19 16:39:29 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
it( 'should be able to create account', function () {
|
|
|
|
|
// create
|
|
|
|
|
CreateAccountPage.createAccount( username, password );
|
|
|
|
|
|
|
|
|
|
// check
|
2018-06-06 10:49:33 +00:00
|
|
|
assert.strictEqual( CreateAccountPage.heading.getText(), `Welcome, ${username}!` );
|
2016-12-19 16:39:29 +00:00
|
|
|
} );
|
|
|
|
|
|
2018-09-04 09:27:01 +00:00
|
|
|
it( 'should be able to log in @daily', function () {
|
2016-12-19 16:39:29 +00:00
|
|
|
// create
|
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 058d5b7cd857af.
* 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-01 02:10:05 +00:00
|
|
|
browser.call( async () => {
|
|
|
|
|
await Api.createAccount( bot, username, password );
|
2017-05-08 10:10:18 +00:00
|
|
|
} );
|
2016-12-19 16:39:29 +00:00
|
|
|
|
|
|
|
|
// log in
|
|
|
|
|
UserLoginPage.login( username, password );
|
|
|
|
|
|
|
|
|
|
// check
|
2020-03-25 15:21:18 +00:00
|
|
|
const actualUsername = browser.execute( () => {
|
|
|
|
|
return mw.config.get( 'wgUserName' );
|
|
|
|
|
} );
|
|
|
|
|
assert.strictEqual( actualUsername, username );
|
2016-12-19 16:39:29 +00:00
|
|
|
} );
|
|
|
|
|
} );
|