Merge "Fix sessionfailure i18n message during authentication"
[lhc/web/wiklou.git] / tests / selenium / pageobjects / delete.page.js
1 'use strict';
2 const Page = require( './page' );
3
4 class DeletePage extends Page {
5
6 get reason() { return browser.element( '#wpReason' ); }
7 get watch() { return browser.element( '#wpWatch' ); }
8 get submit() { return browser.element( '#wpConfirmB' ); }
9 get displayedContent() { return browser.element( '#mw-content-text' ); }
10
11 open( name ) {
12 super.open( name + '&action=delete' );
13 }
14
15 delete( name, reason ) {
16 this.open( name );
17 this.reason.setValue( reason );
18 this.submit.click();
19 }
20
21 apiDelete( name, reason ) {
22 const url = require( 'url' ), // https://nodejs.org/docs/latest/api/url.html
23 baseUrl = url.parse( browser.options.baseUrl ), // http://webdriver.io/guide/testrunner/browserobject.html
24 Bot = require( 'nodemw' ), // https://github.com/macbre/nodemw
25 client = new Bot( {
26 protocol: baseUrl.protocol,
27 server: baseUrl.hostname,
28 port: baseUrl.port,
29 path: baseUrl.path,
30 username: browser.options.username,
31 password: browser.options.password,
32 debug: false
33 } );
34
35 return new Promise( ( resolve, reject ) => {
36 client.logIn( function ( err ) {
37 if ( err ) {
38 console.log( err );
39 return reject( err );
40 }
41 client.delete( name, reason, function ( err ) {
42 if ( err ) {
43 return reject( err );
44 }
45 resolve();
46 } );
47 } );
48 } );
49 }
50
51 }
52 module.exports = new DeletePage();