summaryrefslogtreecommitdiff
path: root/www/wiki/tests/selenium/pageobjects/edit.page.js
blob: 33a27f0f8ca12da60944669afe21c47ddcba04bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'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' ); }

	openForEditing( name ) {
		super.open( name + '&action=edit' );
	}

	edit( name, content ) {
		this.openForEditing( name );
		this.content.setValue( content );
		this.save.click();
	}

	apiEdit( name, content ) {

		const MWBot = require( 'mwbot' ), // https://github.com/Fannon/mwbot
			Promise = require( 'bluebird' );
		let bot = new MWBot();

		return Promise.coroutine( function* () {
			yield bot.loginGetEditToken( {
				apiUrl: `${browser.options.baseUrl}/api.php`,
				username: browser.options.username,
				password: browser.options.password
			} );
			yield bot.edit( name, content, `Created page with "${content}"` );
		} ).call( this );

	}

}
module.exports = new EditPage();