2016-12-19 16:39:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
const Page = require( './page' );
|
|
|
|
|
|
|
|
|
|
class EditPage extends Page {
|
|
|
|
|
|
|
|
|
|
get content() { return browser.element( '#wpTextbox1' ); }
|
|
|
|
|
get displayedContent() { return browser.element( '#mw-content-text' ); }
|
|
|
|
|
get heading() { return browser.element( '#firstHeading' ); }
|
|
|
|
|
get save() { return browser.element( '#wpSave' ); }
|
|
|
|
|
|
2017-05-08 10:10:18 +00:00
|
|
|
openForEditing( name ) {
|
2016-12-19 16:39:29 +00:00
|
|
|
super.open( name + '&action=edit' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
edit( name, content ) {
|
2017-05-08 10:10:18 +00:00
|
|
|
this.openForEditing( name );
|
2016-12-19 16:39:29 +00:00
|
|
|
this.content.setValue( content );
|
|
|
|
|
this.save.click();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-08 10:10:18 +00:00
|
|
|
apiEdit( name, content ) {
|
|
|
|
|
const url = require( 'url' ), // https://nodejs.org/docs/latest/api/url.html
|
|
|
|
|
baseUrl = url.parse( browser.options.baseUrl ), // http://webdriver.io/guide/testrunner/browserobject.html
|
|
|
|
|
Bot = require( 'nodemw' ), // https://github.com/macbre/nodemw
|
|
|
|
|
client = new Bot( {
|
|
|
|
|
protocol: baseUrl.protocol,
|
|
|
|
|
server: baseUrl.hostname,
|
|
|
|
|
port: baseUrl.port,
|
|
|
|
|
path: baseUrl.path,
|
2017-10-03 09:17:39 +00:00
|
|
|
username: browser.options.username,
|
|
|
|
|
password: browser.options.password,
|
2017-05-08 10:10:18 +00:00
|
|
|
debug: false
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
return new Promise( ( resolve, reject ) => {
|
2017-10-03 09:17:39 +00:00
|
|
|
client.logIn( function ( err ) {
|
2017-05-08 10:10:18 +00:00
|
|
|
if ( err ) {
|
2017-10-03 09:17:39 +00:00
|
|
|
console.log( err );
|
2017-05-08 10:10:18 +00:00
|
|
|
return reject( err );
|
|
|
|
|
}
|
2017-10-03 09:17:39 +00:00
|
|
|
client.edit( name, content, `Created page with "${content}"`, function ( err ) {
|
|
|
|
|
if ( err ) {
|
|
|
|
|
return reject( err );
|
|
|
|
|
}
|
|
|
|
|
resolve();
|
|
|
|
|
} );
|
2017-05-08 10:10:18 +00:00
|
|
|
} );
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 16:39:29 +00:00
|
|
|
}
|
|
|
|
|
module.exports = new EditPage();
|