@webship-js/mediawiki-steps 0.0.0-stage → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +550 -2
- package/package.json +63 -4
- package/tests/features/README.md +26 -0
- package/tests/features/accessibility.feature +16 -0
- package/tests/features/account-creation.feature +28 -0
- package/tests/features/administration.feature +49 -0
- package/tests/features/categories.feature +28 -0
- package/tests/features/edit-conflict.feature +15 -0
- package/tests/features/history.feature +30 -0
- package/tests/features/preferences.feature +15 -0
- package/tests/features/reading.feature +84 -0
- package/tests/features/search.feature +34 -0
- package/tests/features/session.feature +43 -0
- package/tests/features/source-editor.feature +42 -0
- package/tests/features/talk-page.feature +19 -0
- package/tests/features/upload.feature +20 -0
- package/tests/features/visual-editor.feature +18 -0
- package/tests/features/watchlist.feature +24 -0
- package/tests/fixtures/blue-square.png +0 -0
- package/tests/step-definitions/README.md +41 -0
- package/tests/step-definitions/mediawiki-admin.steps.js +241 -0
- package/tests/step-definitions/mediawiki-editing.steps.js +413 -0
- package/tests/step-definitions/mediawiki-files.steps.js +93 -0
- package/tests/step-definitions/mediawiki-helpers.js +768 -0
- package/tests/step-definitions/mediawiki-history.steps.js +135 -0
- package/tests/step-definitions/mediawiki-pages.steps.js +710 -0
- package/tests/step-definitions/mediawiki-search.steps.js +234 -0
- package/tests/step-definitions/mediawiki-session.steps.js +287 -0
- package/tests/step-definitions/mediawiki-watchlist.steps.js +265 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// The administrator's pages: protecting a page, deleting and restoring it, and
|
|
4
|
+
// blocking and unblocking an account. A block a scenario makes is lifted after it
|
|
5
|
+
// (the After hook of mediawiki-pages.steps.js), and the block form's
|
|
6
|
+
// "Block the last IP address used by this account" is cleared: an autoblock
|
|
7
|
+
// would block the address the whole suite runs from.
|
|
8
|
+
|
|
9
|
+
const { When, Then } = require('@cucumber/cucumber');
|
|
10
|
+
const { friendly } = require('webship-js/tests/step-definitions/webship');
|
|
11
|
+
const {
|
|
12
|
+
clean,
|
|
13
|
+
listed,
|
|
14
|
+
titleText,
|
|
15
|
+
cutRequest,
|
|
16
|
+
CUT_HINT,
|
|
17
|
+
openPage,
|
|
18
|
+
afterNavigation,
|
|
19
|
+
pageSummary,
|
|
20
|
+
messages,
|
|
21
|
+
hasMessage,
|
|
22
|
+
resolveUser,
|
|
23
|
+
pageInfo,
|
|
24
|
+
apiBlocks,
|
|
25
|
+
wikiUserName,
|
|
26
|
+
} = require('./mediawiki-helpers');
|
|
27
|
+
|
|
28
|
+
const LEVELS = {
|
|
29
|
+
'all users': 'Allow all users',
|
|
30
|
+
'autoconfirmed users': 'Allow only autoconfirmed users',
|
|
31
|
+
administrators: 'Allow only administrators',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Choose an option of an OOUI dropdown (a combobox), as a person does. */
|
|
35
|
+
async function chooseOption(world, combobox, option) {
|
|
36
|
+
await combobox.click();
|
|
37
|
+
const item = world.page.getByRole('option', { name: option, exact: true }).filter({ visible: true }).first();
|
|
38
|
+
try {
|
|
39
|
+
await item.waitFor({ state: 'visible', timeout: 5000 });
|
|
40
|
+
} catch {
|
|
41
|
+
const options = await world.page.locator('[role="option"]').filter({ visible: true }).allInnerTexts().catch(() => []);
|
|
42
|
+
throw friendly({ message: `The list offers no "${option}". It offers: ${listed(options)}.`, hint: 'Name the option as the form writes it.' });
|
|
43
|
+
}
|
|
44
|
+
await item.click();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** An account name from a handle of the users registry, or the name itself. */
|
|
48
|
+
function blockTarget(world, who) {
|
|
49
|
+
const users = (world.parameters && world.parameters.users) || {};
|
|
50
|
+
return users[who] ? resolveUser(world, who).wikiName : wikiUserName(who);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Protect a page with its protection form (action=protect), as an administrator:
|
|
55
|
+
* who may edit it (and move it, which follows). "remove the protection" sets it
|
|
56
|
+
* back to all users.
|
|
57
|
+
*
|
|
58
|
+
* Example #1: When I protect the page "Protection test page" so that only autoconfirmed users can edit it
|
|
59
|
+
* Example #2: When I protect the page "Protection test page" so that only administrators can edit it
|
|
60
|
+
* Example #3: When I remove the protection of the page "Protection test page"
|
|
61
|
+
* Example #4: And we protect the page "Second test page" so that only administrators can edit it
|
|
62
|
+
* Example #5: When we remove the protection of the page "Second test page"
|
|
63
|
+
*/
|
|
64
|
+
When(/^(?:(?:I|we) protect the page "([^"]*)" so that only (autoconfirmed users|administrators) can edit it|(?:I|we) remove the protection of the page "([^"]*)")$/, { timeout: 90000 }, async function (title, who, unprotectTitle) {
|
|
65
|
+
const page = this.page;
|
|
66
|
+
const target = title || unprotectTitle;
|
|
67
|
+
await openPage(this, target, { action: 'protect' });
|
|
68
|
+
const group = page.getByRole('group', { name: 'Edit', exact: true });
|
|
69
|
+
if (!(await group.count())) {
|
|
70
|
+
throw friendly({ message: `The protection form of "${titleText(target)}" did not open: ${await pageSummary(this)}. ${listed(await messages(this, 'error'))}`, hint: cutRequest(this) ? CUT_HINT : 'Log in as an administrator ("protect" right) first.' });
|
|
71
|
+
}
|
|
72
|
+
await chooseOption(this, group.getByRole('combobox').first(), LEVELS[who || 'all users']);
|
|
73
|
+
await afterNavigation(this, () => page.getByRole('button', { name: 'Confirm' }).click());
|
|
74
|
+
if (cutRequest(this)) throw friendly({ message: `The protection was not saved: ${cutRequest(this)}.`, hint: CUT_HINT });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Assert who may edit a page, as the wiki's API reports its protection.
|
|
79
|
+
*
|
|
80
|
+
* Example #1: Then the page "Protection test page" should be protected so that only autoconfirmed users can edit it
|
|
81
|
+
* Example #2: Then the page "Protection test page" should be protected so that only administrators can edit it
|
|
82
|
+
* Example #3: Then the page "Protection test page" should not be protected
|
|
83
|
+
* Example #4: And the page "Second test page" should be protected so that only administrators can edit it
|
|
84
|
+
* Example #5: And the page "Second test page" should not be protected
|
|
85
|
+
*/
|
|
86
|
+
Then(/^the page "([^"]*)" should (?:be protected so that only (autoconfirmed users|administrators) can edit it|(not) be protected)$/, async function (title, who, notCase) {
|
|
87
|
+
const info = await pageInfo(this, title);
|
|
88
|
+
const edit = info.protection.find((p) => p.type === 'edit');
|
|
89
|
+
const level = edit ? edit.level : '';
|
|
90
|
+
const want = notCase ? '' : (who === 'administrators' ? 'sysop' : 'autoconfirmed');
|
|
91
|
+
if (level !== want) {
|
|
92
|
+
throw friendly({ message: `"${titleText(title)}" is ${level ? `protected for "${level}"` : 'not protected'}, not ${want ? `for "${want}"` : 'unprotected'}.`, hint: 'Protect it first, with the protection form ("When I protect the page ...").' });
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Delete a page with its deletion form (action=delete), as an administrator, with
|
|
98
|
+
* a reason; the step waits for "Action complete".
|
|
99
|
+
*
|
|
100
|
+
* Example #1: When I delete the page "Deletion test page" with the reason "A test of the deletion"
|
|
101
|
+
* Example #2: When we delete the page "Second test page" with the reason "No longer needed"
|
|
102
|
+
* Example #3: And I delete the page "Deletion test page" with the reason "Duplicate"
|
|
103
|
+
* Example #4: When I delete the page "Talk:Deletion test page" with the reason "A test"
|
|
104
|
+
* Example #5: When we delete the page "Deletion test page" with the reason "Cleanup"
|
|
105
|
+
*/
|
|
106
|
+
When(/^(I |we )*delete the page "([^"]*)" with the reason "([^"]*)"$/, { timeout: 90000 }, async function (pronounCase, title, reason) {
|
|
107
|
+
const page = this.page;
|
|
108
|
+
await openPage(this, title, { action: 'delete' });
|
|
109
|
+
const button = page.getByRole('button', { name: 'Delete page' });
|
|
110
|
+
if (!(await button.count())) {
|
|
111
|
+
throw friendly({ message: `The deletion form of "${titleText(title)}" did not open: ${await pageSummary(this)}. ${listed(await messages(this, 'error'))}`, hint: cutRequest(this) ? CUT_HINT : 'Log in as an administrator ("delete" right) first; the page must exist.' });
|
|
112
|
+
}
|
|
113
|
+
await page.getByRole('textbox', { name: 'Other/additional reason:' }).fill(reason);
|
|
114
|
+
await afterNavigation(this, () => button.click());
|
|
115
|
+
const text = clean(await page.locator('#mw-content-text').innerText().catch(() => ''));
|
|
116
|
+
if (!/has been deleted/.test(text)) {
|
|
117
|
+
throw friendly({ message: `The wiki did not delete "${titleText(title)}": ${await pageSummary(this)}. ${listed(await messages(this, 'error'))}`, hint: cutRequest(this) ? CUT_HINT : 'The wiki answers a deletion with "Action complete".' });
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Restore a deleted page with every revision (Special:Undelete), as an
|
|
123
|
+
* administrator, with a reason.
|
|
124
|
+
*
|
|
125
|
+
* Example #1: When I restore the page "Deletion test page" with the reason "Deleted by mistake"
|
|
126
|
+
* Example #2: When we restore the page "Second test page" with the reason "Needed again"
|
|
127
|
+
* Example #3: And I restore the page "Deletion test page" with the reason "A test of the restore"
|
|
128
|
+
* Example #4: When I restore the page "Talk:Deletion test page" with the reason "A test"
|
|
129
|
+
* Example #5: When we restore the page "Deletion test page" with the reason "Back"
|
|
130
|
+
*/
|
|
131
|
+
When(/^(I |we )*restore the page "([^"]*)" with the reason "([^"]*)"$/, { timeout: 90000 }, async function (pronounCase, title, reason) {
|
|
132
|
+
const page = this.page;
|
|
133
|
+
await openPage(this, 'Special:Undelete', { target: titleText(title) });
|
|
134
|
+
const button = page.getByRole('button', { name: /^(Undelete|Restore)$/ });
|
|
135
|
+
if (!(await button.count())) {
|
|
136
|
+
throw friendly({ message: `The restore form of "${titleText(title)}" did not open: ${await pageSummary(this)}. ${listed(await messages(this, 'error'))}`, hint: cutRequest(this) ? CUT_HINT : 'Log in as an administrator ("undelete" right) first; the page must have been deleted.' });
|
|
137
|
+
}
|
|
138
|
+
await page.locator('input[name="wpComment"]').fill(reason);
|
|
139
|
+
await afterNavigation(this, () => button.first().click());
|
|
140
|
+
const text = clean(await page.locator('#mw-content-text').innerText().catch(() => ''));
|
|
141
|
+
if (!/has been undeleted|has been restored/.test(text)) {
|
|
142
|
+
throw friendly({ message: `The wiki did not restore "${titleText(title)}": ${text.slice(0, 200)}.`, hint: cutRequest(this) ? CUT_HINT : 'The wiki answers a restore with "<title> has been undeleted".' });
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Assert that a page exists, or does not, as the wiki's API reports it.
|
|
148
|
+
*
|
|
149
|
+
* Example #1: Then the page "Deletion test page" should not exist
|
|
150
|
+
* Example #2: Then the page "Deletion test page" should exist
|
|
151
|
+
* Example #3: And the page "Second test page" should exist
|
|
152
|
+
* Example #4: Then the page "Page made in the source editor" should exist
|
|
153
|
+
* Example #5: And the page "Talk:Deletion test page" should not exist
|
|
154
|
+
*/
|
|
155
|
+
Then(/^the page "([^"]*)" should( not)* exist$/, async function (title, notCase) {
|
|
156
|
+
const info = await pageInfo(this, title);
|
|
157
|
+
if (info.exists === !!notCase) {
|
|
158
|
+
throw friendly({ message: `"${titleText(title)}" ${info.exists ? 'exists' : 'does not exist'} on the wiki.`, hint: notCase ? 'Delete it first.' : 'Make it or restore it first.' });
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Block an account with the block form (Special:Block), as an administrator:
|
|
164
|
+
* on the whole site, for an expiry of the form's list ("2 hours", "1 day",
|
|
165
|
+
* "1 week", …), with a reason. The step clears "Block the last IP address used by
|
|
166
|
+
* this account" (an autoblock would block the address the suite runs from), and
|
|
167
|
+
* the block is lifted after the scenario.
|
|
168
|
+
*
|
|
169
|
+
* Example #1: When I block the account "reader" for "1 day" with the reason "A test of the block"
|
|
170
|
+
* Example #2: When we block the account "reader" for "2 hours" with the reason "Testing"
|
|
171
|
+
* Example #3: And I block the account "reader" for "1 week" with the reason "A test"
|
|
172
|
+
* Example #4: When I block the account "Reader" for "1 day" with the reason "A test of the block"
|
|
173
|
+
* Example #5: When we block the account "reader" for "3 days" with the reason "Testing the block list"
|
|
174
|
+
*/
|
|
175
|
+
When(/^(I |we )*block the account "([^"]*)" for "([^"]*)" with the reason "([^"]*)"$/, { timeout: 90000 }, async function (pronounCase, who, expiry, reason) {
|
|
176
|
+
const page = this.page;
|
|
177
|
+
const name = blockTarget(this, who);
|
|
178
|
+
await openPage(this, `Special:Block/${name}`);
|
|
179
|
+
const submit = page.getByRole('button', { name: /^(Add block|Block|Block this user)$/ });
|
|
180
|
+
if (!(await submit.count())) {
|
|
181
|
+
throw friendly({ message: `The block form did not open: ${await pageSummary(this)}. ${listed(await messages(this, 'error'))}`, hint: cutRequest(this) ? CUT_HINT : 'Log in as an administrator ("block" right) first.' });
|
|
182
|
+
}
|
|
183
|
+
if (!this.__wikiCleanup) this.__wikiCleanup = { pages: new Set(), blocks: new Set() };
|
|
184
|
+
this.__wikiCleanup.blocks.add(name);
|
|
185
|
+
await chooseOption(this, page.locator('[id^="mw-input-wpExpiry"] [role="combobox"]').first(), expiry);
|
|
186
|
+
// "Block the last IP address used by this account, …" (the long-term-support release: "Automatically block
|
|
187
|
+
// the last IP address used by this user, …"), the box wpAutoBlock of the form.
|
|
188
|
+
const autoblock = page.getByRole('checkbox', { name: /last IP address used by this (account|user)/i }).or(page.locator('input[name="wpAutoBlock"]')).first();
|
|
189
|
+
if (await autoblock.count()) await autoblock.uncheck();
|
|
190
|
+
await page.locator('input[name="wpReason-other"]').fill(reason);
|
|
191
|
+
await afterNavigation(this, () => submit.first().click());
|
|
192
|
+
const text = clean(await page.locator('#mw-content-text').innerText().catch(() => ''));
|
|
193
|
+
if (!/has been blocked/.test(text)) {
|
|
194
|
+
throw friendly({ message: `The wiki did not block "${name}": ${listed((await messages(this, 'error')).concat([text.slice(0, 160)]))}.`, hint: cutRequest(this) ? CUT_HINT : 'The wiki answers a block with "Block succeeded".' });
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Lift the block of an account with the unblock form (Special:Unblock), as an
|
|
200
|
+
* administrator, with a reason.
|
|
201
|
+
*
|
|
202
|
+
* Example #1: When I unblock the account "reader" with the reason "The test is over"
|
|
203
|
+
* Example #2: When we unblock the account "reader" with the reason "Done"
|
|
204
|
+
* Example #3: And I unblock the account "Reader" with the reason "A test of the unblock"
|
|
205
|
+
* Example #4: When I unblock the account "reader" with the reason "Blocked by mistake"
|
|
206
|
+
* Example #5: When we unblock the account "reader" with the reason "Testing"
|
|
207
|
+
*/
|
|
208
|
+
When(/^(I |we )*unblock the account "([^"]*)" with the reason "([^"]*)"$/, { timeout: 90000 }, async function (pronounCase, who, reason) {
|
|
209
|
+
const page = this.page;
|
|
210
|
+
const name = blockTarget(this, who);
|
|
211
|
+
await openPage(this, `Special:Unblock/${name}`);
|
|
212
|
+
const submit = page.getByRole('button', { name: /^(Remove this block|Unblock)$/ });
|
|
213
|
+
if (!(await submit.count())) {
|
|
214
|
+
throw friendly({ message: `The unblock form did not open: ${await pageSummary(this)}. ${listed(await messages(this, 'error'))}`, hint: cutRequest(this) ? CUT_HINT : 'Log in as an administrator ("block" right) first.' });
|
|
215
|
+
}
|
|
216
|
+
await page.getByRole('textbox', { name: 'Reason:' }).fill(reason);
|
|
217
|
+
await afterNavigation(this, () => submit.first().click());
|
|
218
|
+
const text = clean(await page.locator('#mw-content-text').innerText().catch(() => ''));
|
|
219
|
+
if (!/has been unblocked/.test(text)) {
|
|
220
|
+
throw friendly({ message: `The wiki did not unblock "${name}": ${listed((await messages(this, 'error')).concat([text.slice(0, 160)]))}.`, hint: cutRequest(this) ? CUT_HINT : 'The account must be blocked.' });
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Assert that an account is, or is not, blocked, as the wiki's API reports it.
|
|
226
|
+
*
|
|
227
|
+
* Example #1: Then the account "reader" should be blocked
|
|
228
|
+
* Example #2: Then the account "reader" should not be blocked
|
|
229
|
+
* Example #3: And the account "Reader" should be blocked
|
|
230
|
+
* Example #4: And the account "editor" should not be blocked
|
|
231
|
+
* Example #5: Then the account "reader" should be blocked
|
|
232
|
+
*/
|
|
233
|
+
Then(/^the account "([^"]*)" should( not)* be blocked$/, async function (who, notCase) {
|
|
234
|
+
const name = blockTarget(this, who);
|
|
235
|
+
const blocks = await apiBlocks(this, name);
|
|
236
|
+
if (!!notCase === !!blocks.length) {
|
|
237
|
+
throw friendly({ message: blocks.length ? `"${name}" is blocked until ${blocks[0].expiry} ("${blocks[0].reason}").` : `"${name}" is not blocked.`, hint: notCase ? 'Unblock it first.' : 'Block it first, with the block form.' });
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
module.exports = { chooseOption };
|
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Editing: the source editor (the wikitext, the summary, a minor edit, the
|
|
4
|
+
// preview, the changes, saving) and the visual editor (opening it, typing,
|
|
5
|
+
// saving through its dialog), an edit conflict with another account, and the
|
|
6
|
+
// refusal of a page the account may not edit.
|
|
7
|
+
//
|
|
8
|
+
// Waits are the wiki's own signals: the editors' modules through the module
|
|
9
|
+
// loader, the visual editor's hooks (ve.activationComplete, postEdit,
|
|
10
|
+
// ve.deactivationComplete), and the page the wiki answers a saved edit with
|
|
11
|
+
// (`wgPostEdit`). The visual editor's welcome dialog, which opens over the first
|
|
12
|
+
// editor each account opens, is closed with "Start editing".
|
|
13
|
+
|
|
14
|
+
const { When, Then } = require('@cucumber/cucumber');
|
|
15
|
+
const { friendly } = require('webship-js/tests/step-definitions/webship');
|
|
16
|
+
const {
|
|
17
|
+
budget,
|
|
18
|
+
clean,
|
|
19
|
+
listed,
|
|
20
|
+
titleText,
|
|
21
|
+
config,
|
|
22
|
+
cutRequest,
|
|
23
|
+
CUT_HINT,
|
|
24
|
+
settle,
|
|
25
|
+
waitForModules,
|
|
26
|
+
openPage,
|
|
27
|
+
afterNavigation,
|
|
28
|
+
eventually,
|
|
29
|
+
pageSummary,
|
|
30
|
+
messages,
|
|
31
|
+
hasMessage,
|
|
32
|
+
signedInName,
|
|
33
|
+
closeWelcomeDialog,
|
|
34
|
+
visualEditorActive,
|
|
35
|
+
countHook,
|
|
36
|
+
waitForHook,
|
|
37
|
+
apiEdit,
|
|
38
|
+
adminApi,
|
|
39
|
+
MARKER,
|
|
40
|
+
} = require('./mediawiki-helpers');
|
|
41
|
+
|
|
42
|
+
const SOURCE_HINT = 'Open the source editor first ("When I edit the page ...").';
|
|
43
|
+
|
|
44
|
+
/** The source editor's text box, once the editor is on screen. */
|
|
45
|
+
async function sourceBox(world) {
|
|
46
|
+
const box = world.page.locator('#wpTextbox1');
|
|
47
|
+
if (!(await box.count()) || await visualEditorActive(world)) {
|
|
48
|
+
throw friendly({ message: `The source editor is not open: ${await pageSummary(world)}.`, hint: SOURCE_HINT });
|
|
49
|
+
}
|
|
50
|
+
return box;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Open a page in the source editor (the "Edit source" tab, action=edit), as an
|
|
55
|
+
* account of the users registry or a visitor. The step waits for the editor's
|
|
56
|
+
* toolbar module and closes the visual editor's welcome dialog when it shows.
|
|
57
|
+
*
|
|
58
|
+
* Example #1: When I edit the page "Editing test page"
|
|
59
|
+
* Example #2: When we edit the page "Page made in the source editor"
|
|
60
|
+
* Example #3: And I edit the page "Conflict test page"
|
|
61
|
+
* Example #4: When I edit the page "Protected test page"
|
|
62
|
+
* Example #5: When I edit the page "Talk:Reading test page"
|
|
63
|
+
*/
|
|
64
|
+
When(/^(I |we )*edit the page "([^"]*)"$/, { timeout: 90000 }, async function (pronounCase, title) {
|
|
65
|
+
await openPage(this, title, { action: 'edit' });
|
|
66
|
+
if (cutRequest(this)) throw friendly({ message: `The editor of "${title}" did not open: ${cutRequest(this)}.`, hint: CUT_HINT });
|
|
67
|
+
await closeWelcomeDialog(this);
|
|
68
|
+
if (!(await this.page.locator('#wpTextbox1').count())) {
|
|
69
|
+
throw friendly({ message: `The source editor of "${titleText(title)}" did not open: ${await pageSummary(this)}. ${listed(await messages(this, 'error'))}`, hint: 'The account must be allowed to edit the page.' });
|
|
70
|
+
}
|
|
71
|
+
const editable = !(await this.page.locator('#wpTextbox1').evaluate((t) => t.readOnly).catch(() => true));
|
|
72
|
+
if (editable && await this.page.evaluate(() => mw.loader.getState('ext.wikiEditor') !== null).catch(() => false)) {
|
|
73
|
+
await waitForModules(this, 'ext.wikiEditor', { what: 'The toolbar of the source editor' });
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Replace the wikitext in the source editor.
|
|
79
|
+
*
|
|
80
|
+
* Example #1: When I set the wikitext to:
|
|
81
|
+
* Example #2: And I set the wikitext to:
|
|
82
|
+
* Example #3: When we set the wikitext to:
|
|
83
|
+
* Example #4: Then I set the wikitext to:
|
|
84
|
+
* Example #5: When I set the wikitext to:
|
|
85
|
+
*/
|
|
86
|
+
When(/^(I |we )*set the wikitext to:$/, async function (pronounCase, text) {
|
|
87
|
+
const box = await sourceBox(this);
|
|
88
|
+
await box.fill(String(text));
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Replace the wikitext in the source editor with one line.
|
|
93
|
+
*
|
|
94
|
+
* Example #1: When I set the wikitext to "A page made in the source editor."
|
|
95
|
+
* Example #2: And I set the wikitext to "My own first line."
|
|
96
|
+
* Example #3: When we set the wikitext to "Changed words."
|
|
97
|
+
* Example #4: When I set the wikitext to "== A section ==\nIts text."
|
|
98
|
+
* Example #5: And we set the wikitext to "A line."
|
|
99
|
+
*/
|
|
100
|
+
When(/^(I |we )*set the wikitext to "([^"]*)"$/, async function (pronounCase, text) {
|
|
101
|
+
const box = await sourceBox(this);
|
|
102
|
+
await box.fill(text.replace(/\\n/g, '\n'));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Add a line at the end of the wikitext in the source editor.
|
|
107
|
+
*
|
|
108
|
+
* Example #1: When I add the wikitext "A line added at the end."
|
|
109
|
+
* Example #2: And I add the wikitext "[[Category:Test guides]]"
|
|
110
|
+
* Example #3: When we add the wikitext "== New section =="
|
|
111
|
+
* Example #4: When I add the wikitext "More words."
|
|
112
|
+
* Example #5: And we add the wikitext "[[Second test page]]"
|
|
113
|
+
*/
|
|
114
|
+
When(/^(I |we )*add the wikitext "([^"]*)"$/, async function (pronounCase, text) {
|
|
115
|
+
const box = await sourceBox(this);
|
|
116
|
+
const current = await box.inputValue();
|
|
117
|
+
await box.fill(`${current.replace(/\s+$/, '')}\n${text.replace(/\\n/g, '\n')}\n`);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Show the preview of the source editor ("Show preview"), and wait for it.
|
|
122
|
+
*
|
|
123
|
+
* Example #1: When I preview the page
|
|
124
|
+
* Example #2: When we preview the page
|
|
125
|
+
* Example #3: And I preview the page
|
|
126
|
+
* Example #4: Then I preview the page
|
|
127
|
+
* Example #5: When I preview the page
|
|
128
|
+
*/
|
|
129
|
+
When(/^(I |we )*preview the page$/, { timeout: 60000 }, async function (pronounCase) {
|
|
130
|
+
await sourceBox(this);
|
|
131
|
+
await afterNavigation(this, () => this.page.locator('#wpPreview').click());
|
|
132
|
+
if (cutRequest(this)) throw friendly({ message: `The preview did not open: ${cutRequest(this)}.`, hint: CUT_HINT });
|
|
133
|
+
await closeWelcomeDialog(this);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Assert what the preview of the source editor shows (the rendered wikitext).
|
|
138
|
+
*
|
|
139
|
+
* Example #1: Then the preview should show "A page made in the source editor."
|
|
140
|
+
* Example #2: Then the preview should not show "Words to change."
|
|
141
|
+
* Example #3: And the preview should show "A section"
|
|
142
|
+
* Example #4: Then the preview should show "More words."
|
|
143
|
+
* Example #5: And the preview should not show "== A section =="
|
|
144
|
+
*/
|
|
145
|
+
Then(/^the preview should( not)* show "([^"]*)"$/, async function (notCase, expected) {
|
|
146
|
+
const read = async () => clean(await this.page.locator('#wikiPreview').innerText({ timeout: 2000 }).catch(() => ''));
|
|
147
|
+
await eventually(this, read, (text) => !!notCase !== text.includes(clean(expected)),
|
|
148
|
+
(text) => ({ message: text ? (notCase ? `The preview shows "${expected}".` : `The preview does not show "${expected}". It shows: "${text.slice(0, 300)}".`) : `No preview is on the page: ${this.page.url()}.`, hint: 'Preview first ("When I preview the page"); the note "Remember that this is only a preview" heads it.' }));
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Show the changes of the source editor against the saved page ("Show changes").
|
|
153
|
+
*
|
|
154
|
+
* Example #1: When I show my changes
|
|
155
|
+
* Example #2: When we show our changes
|
|
156
|
+
* Example #3: And I show my changes
|
|
157
|
+
* Example #4: Then I show my changes
|
|
158
|
+
* Example #5: When I show my changes
|
|
159
|
+
*/
|
|
160
|
+
When(/^(I |we )*show (my|our) changes$/, { timeout: 60000 }, async function (pronounCase, possessive) {
|
|
161
|
+
await sourceBox(this);
|
|
162
|
+
await afterNavigation(this, () => this.page.locator('#wpDiff').click());
|
|
163
|
+
if (cutRequest(this)) throw friendly({ message: `The changes did not open: ${cutRequest(this)}.`, hint: CUT_HINT });
|
|
164
|
+
await closeWelcomeDialog(this);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Assert a line of a comparison (the changes of the source editor, or two
|
|
169
|
+
* revisions compared from the history): a text added, or a text removed.
|
|
170
|
+
*
|
|
171
|
+
* Example #1: Then the changes should show "Second version of the page." added
|
|
172
|
+
* Example #2: Then the changes should show "First version of the page." removed
|
|
173
|
+
* Example #3: And the changes should show "A line added at the end." added
|
|
174
|
+
* Example #4: Then the changes should show "Words to change." removed
|
|
175
|
+
* Example #5: And the changes should show "My own first line." added
|
|
176
|
+
*/
|
|
177
|
+
Then(/^the changes should show "([^"]*)" (added|removed)$/, async function (expected, kind) {
|
|
178
|
+
const selector = kind === 'added' ? 'table.diff td.diff-addedline, table.diff ins.diffchange' : 'table.diff td.diff-deletedline, table.diff del.diffchange';
|
|
179
|
+
const read = () => this.page.evaluate((s) => [...document.querySelectorAll(s)].map((e) => e.textContent.replace(/\s+/g, ' ').trim()).filter(Boolean), selector).catch(() => []);
|
|
180
|
+
await eventually(this, read, (lines) => lines.some((l) => l.includes(clean(expected))),
|
|
181
|
+
(lines) => ({ message: lines.length || kind ? `The comparison does not show "${expected}" ${kind}. The ${kind} lines: ${listed(lines)}.` : 'No comparison is on the page.', hint: 'Show the changes first ("When I show my changes"), or compare two revisions from the history.' }));
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Open a page in the visual editor, as a person does with its "Edit" tab, and
|
|
186
|
+
* wait for the editor to be ready (its hook ve.activationComplete). The welcome
|
|
187
|
+
* dialog is closed when it shows.
|
|
188
|
+
*
|
|
189
|
+
* Example #1: When I edit the page "Visual editor test page" in the visual editor
|
|
190
|
+
* Example #2: When we edit the page "Editing test page" in the visual editor
|
|
191
|
+
* Example #3: And I edit the page "Reading test page" in the visual editor
|
|
192
|
+
* Example #4: When I edit the page "Second test page" in the visual editor
|
|
193
|
+
* Example #5: When I edit the page "Visual editor test page" in the visual editor
|
|
194
|
+
*/
|
|
195
|
+
When(/^(I |we )*edit the page "([^"]*)" in the visual editor$/, { timeout: 120000 }, async function (pronounCase, title) {
|
|
196
|
+
const page = this.page;
|
|
197
|
+
await openPage(this, title);
|
|
198
|
+
if (cutRequest(this)) throw friendly({ message: `The page "${title}" did not open: ${cutRequest(this)}.`, hint: CUT_HINT });
|
|
199
|
+
const tab = page.locator('#ca-ve-edit a, a#ca-ve-edit').filter({ visible: true }).first();
|
|
200
|
+
if (!(await tab.count())) {
|
|
201
|
+
throw friendly({ message: `The page "${titleText(title)}" offers no visual editor ("Edit" tab): ${await pageSummary(this)}.`, hint: 'The wiki needs the VisualEditor extension, and the account must be allowed to edit the page; a page that does not exist yet opens it from its red link or its "Create" tab.' });
|
|
202
|
+
}
|
|
203
|
+
await waitForModules(this, 'ext.visualEditor.desktopArticleTarget.init', { what: 'The visual editor' });
|
|
204
|
+
const seen = await countHook(this, 've.activationComplete');
|
|
205
|
+
await tab.click();
|
|
206
|
+
await closeWelcomeDialog(this);
|
|
207
|
+
try {
|
|
208
|
+
await waitForHook(this, 've.activationComplete', seen, budget(this) * 3);
|
|
209
|
+
} catch (err) {
|
|
210
|
+
throw friendly({ message: `The visual editor did not open on "${titleText(title)}" (no ve.activationComplete): ${await pageSummary(this)}.`, cause: err, hint: 'The visual editor reads the page through the REST API (rest.php): on nginx it needs the rule MediaWiki documents for rest.php/. See the browser console.' });
|
|
211
|
+
}
|
|
212
|
+
await closeWelcomeDialog(this);
|
|
213
|
+
await page.locator('.ve-ce-documentNode[contenteditable="true"]').first().waitFor({ state: 'visible', timeout: budget(this) });
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Type a text at the end of the page in the visual editor, as a person does.
|
|
218
|
+
*
|
|
219
|
+
* Example #1: When I type " Typed in the visual editor." in the visual editor
|
|
220
|
+
* Example #2: And I type "A new sentence." in the visual editor
|
|
221
|
+
* Example #3: When we type " More words." in the visual editor
|
|
222
|
+
* Example #4: When I type " The end." in the visual editor
|
|
223
|
+
* Example #5: And we type "A line." in the visual editor
|
|
224
|
+
*/
|
|
225
|
+
When(/^(I |we )*type "([^"]*)" in the visual editor$/, async function (pronounCase, text) {
|
|
226
|
+
if (!(await visualEditorActive(this))) throw friendly({ message: `The visual editor is not open: ${await pageSummary(this)}.`, hint: 'Open it first ("When I edit the page ... in the visual editor").' });
|
|
227
|
+
const surface = this.page.locator('.ve-ce-documentNode[contenteditable="true"]').first();
|
|
228
|
+
await surface.click();
|
|
229
|
+
await this.page.keyboard.press('Control+End');
|
|
230
|
+
await this.page.keyboard.type(text);
|
|
231
|
+
await this.page.waitForFunction(() => ve.init.target.edited === true, null, { timeout: budget(this) }).catch(() => {});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Assert that the visual editor is, or is not, open on the page.
|
|
236
|
+
*
|
|
237
|
+
* Example #1: Then the visual editor should be open
|
|
238
|
+
* Example #2: Then the visual editor should not be open
|
|
239
|
+
* Example #3: And the visual editor should be open
|
|
240
|
+
* Example #4: And the visual editor should not be open
|
|
241
|
+
* Example #5: Then the visual editor should be open
|
|
242
|
+
*/
|
|
243
|
+
Then(/^the visual editor should( not)* be open$/, async function (notCase) {
|
|
244
|
+
await eventually(this, () => visualEditorActive(this), (open) => !!notCase !== open,
|
|
245
|
+
() => ({ message: notCase ? 'The visual editor is still open.' : `The visual editor is not open: ${this.page.url()}.`, hint: 'The visual editor marks the page with the class ve-active while it is open.' }));
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
/** Save the page from the visual editor: its "Save changes…" dialog. */
|
|
249
|
+
async function saveFromVisualEditor(world, summary, minor) {
|
|
250
|
+
const page = world.page;
|
|
251
|
+
// The toolbar's "Save changes…" (its accessible name carries the access key: "Save changes… Alt+S").
|
|
252
|
+
const toolbarSave = page.locator('a.ve-ui-toolbar-saveButton, .ve-ui-toolbar-saveButton a').or(page.getByRole('button', { name: /^Save changes…/ })).filter({ visible: true }).first();
|
|
253
|
+
await toolbarSave.click();
|
|
254
|
+
const dialog = page.getByRole('dialog', { name: 'Save your changes' });
|
|
255
|
+
try {
|
|
256
|
+
await dialog.waitFor({ state: 'visible', timeout: budget(world) });
|
|
257
|
+
} catch (err) {
|
|
258
|
+
throw friendly({ message: 'The save dialog of the visual editor did not open ("Save your changes").', cause: err, hint: 'The visual editor saves only a page with changes; type something first.' });
|
|
259
|
+
}
|
|
260
|
+
if (summary !== null) await dialog.getByRole('combobox', { name: 'Describe what you changed' }).fill(summary);
|
|
261
|
+
if (minor) await dialog.getByRole('checkbox', { name: 'This is a minor edit' }).check();
|
|
262
|
+
const seen = await countHook(world, 'postEdit');
|
|
263
|
+
const deactivated = await countHook(world, 've.deactivationComplete');
|
|
264
|
+
await dialog.getByRole('button', { name: 'Save changes' }).click();
|
|
265
|
+
try {
|
|
266
|
+
await waitForHook(world, 'postEdit', seen, budget(world) * 3);
|
|
267
|
+
} catch (err) {
|
|
268
|
+
const errors = await page.evaluate(() => [...document.querySelectorAll('.ve-ui-mwSaveDialog .oo-ui-processDialog-errors, .ve-ui-mwSaveDialog .oo-ui-messageWidget')].map((e) => e.innerText.replace(/\s+/g, ' ').trim()).filter(Boolean)).catch(() => []);
|
|
269
|
+
throw friendly({ message: `The visual editor did not save the page (no postEdit). ${errors.length ? `The dialog says: ${listed(errors)}.` : ''}`.trim(), cause: err, hint: cutRequest(world) ? CUT_HINT : 'See the dialog\'s message: an edit conflict, a protected page, or a lost session.' });
|
|
270
|
+
}
|
|
271
|
+
await waitForHook(world, 've.deactivationComplete', deactivated, budget(world)).catch(() => {});
|
|
272
|
+
world.__lastSave = 'saved';
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Save the page from the source editor, and read what the wiki answered. */
|
|
276
|
+
async function saveFromSourceEditor(world, summary, minor) {
|
|
277
|
+
const page = world.page;
|
|
278
|
+
await sourceBox(world);
|
|
279
|
+
if (summary !== null) await page.locator('#wpSummary').fill(summary);
|
|
280
|
+
if (minor) {
|
|
281
|
+
const box = page.locator('#wpMinoredit');
|
|
282
|
+
if (!(await box.count())) throw friendly({ message: 'The editor offers no "This is a minor edit" box: a new page cannot be a minor edit.', hint: 'Mark only an edit of a page that exists as minor.' });
|
|
283
|
+
await box.check();
|
|
284
|
+
}
|
|
285
|
+
await afterNavigation(world, () => page.locator('#wpSave').click());
|
|
286
|
+
if (cutRequest(world)) throw friendly({ message: `The save did not reach the wiki: ${cutRequest(world)}.`, hint: CUT_HINT });
|
|
287
|
+
const posted = await config(world, 'wgPostEdit');
|
|
288
|
+
const heading = clean(await page.locator('#firstHeading').innerText().catch(() => ''));
|
|
289
|
+
if (posted) { world.__lastSave = posted; return; }
|
|
290
|
+
if (/^Edit conflict:/.test(heading)) { world.__lastSave = 'conflict'; return; }
|
|
291
|
+
throw friendly({
|
|
292
|
+
message: `The wiki did not save the page: ${await pageSummary(world)}. Its messages: ${listed((await messages(world, 'error')).concat(await messages(world, 'warning')))}.`,
|
|
293
|
+
hint: 'A protected page, a blocked account or an expired session refuses a save; the wiki says why above the editor.',
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Save the page from the editor that is open (the source editor or the visual
|
|
299
|
+
* editor), with an edit summary and as a minor edit when asked. The step waits
|
|
300
|
+
* for the wiki's answer: the saved page, or an edit conflict (assert it with
|
|
301
|
+
* "Then I should see an edit conflict").
|
|
302
|
+
*
|
|
303
|
+
* Example #1: When I save the page
|
|
304
|
+
* Example #2: When I save the page with the summary "First version"
|
|
305
|
+
* Example #3: When I save the page as a minor edit with the summary "A typo"
|
|
306
|
+
* Example #4: And we save the page as a minor edit
|
|
307
|
+
* Example #5: When we save the page with the summary "A sentence in the visual editor"
|
|
308
|
+
*/
|
|
309
|
+
When(/^(I |we )*save the page( as a minor edit)?(?: with the summary "([^"]*)")?$/, { timeout: 120000 }, async function (pronounCase, minorCase, summary) {
|
|
310
|
+
if (await visualEditorActive(this)) await saveFromVisualEditor(this, summary === undefined ? null : summary, !!minorCase);
|
|
311
|
+
else await saveFromSourceEditor(this, summary === undefined ? null : summary, !!minorCase);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Assert that the last save went through: the wiki answered with the page and
|
|
316
|
+
* says it was saved (or made, for a new page).
|
|
317
|
+
*
|
|
318
|
+
* Example #1: Then the edit should be saved
|
|
319
|
+
* Example #2: Then the page should be created
|
|
320
|
+
* Example #3: And the edit should be saved
|
|
321
|
+
* Example #4: And the page should be created
|
|
322
|
+
* Example #5: Then the edit should be saved
|
|
323
|
+
*/
|
|
324
|
+
Then(/^the (edit should be saved|page should be created)$/, async function (kind) {
|
|
325
|
+
const posted = await config(this, 'wgPostEdit');
|
|
326
|
+
const ok = kind === 'page should be created' ? posted === 'created' : ['saved', 'created'].includes(posted) || this.__lastSave === 'saved';
|
|
327
|
+
if (!ok) {
|
|
328
|
+
throw friendly({ message: `The wiki did not ${kind === 'page should be created' ? 'make the page' : 'save the edit'} (wgPostEdit ${posted || 'not set'}, last save ${this.__lastSave || 'none'}): ${await pageSummary(this)}.`, hint: 'Save first ("When I save the page"). A page saved again without changes is no new edit.' });
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Change a page through the API as the administrator of the users registry, while
|
|
334
|
+
* the browser's editor is open on it: the next save of the browser meets an edit
|
|
335
|
+
* conflict when both changed the same lines. The browser's account must not be
|
|
336
|
+
* that administrator.
|
|
337
|
+
*
|
|
338
|
+
* Example #1: When another account saves the page "Conflict test page" with the text "Changed by another account."
|
|
339
|
+
* Example #2: And another account saves the page "Conflict test page" with the text "Their line."
|
|
340
|
+
* Example #3: When another account saves the page "Editing test page" with the text "Changed meanwhile."
|
|
341
|
+
* Example #4: When another account saves the page "Conflict test page" with the text "The first line, changed."
|
|
342
|
+
* Example #5: And another account saves the page "Editing test page" with the text "Another change."
|
|
343
|
+
*/
|
|
344
|
+
When(/^another account saves the page "([^"]*)" with the text "([^"]*)"$/, { timeout: 60000 }, async function (title, text) {
|
|
345
|
+
const api = await adminApi(this);
|
|
346
|
+
const me = await signedInName(this);
|
|
347
|
+
if (me && me === api.admin.wikiName) {
|
|
348
|
+
throw friendly({ message: `The browser is signed in as ${me}, the account the API works as: the wiki does not raise an edit conflict with yourself.`, hint: 'Edit in the browser as another account of the users registry ("editor").' });
|
|
349
|
+
}
|
|
350
|
+
await apiEdit(this, title, text, `Changed meanwhile by another account ${MARKER}`);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Assert that the wiki answered the save with an edit conflict: the page
|
|
355
|
+
* "Edit conflict: <title>" with the current text above and the browser's own
|
|
356
|
+
* text below.
|
|
357
|
+
*
|
|
358
|
+
* Example #1: Then I should see an edit conflict
|
|
359
|
+
* Example #2: Then we should see an edit conflict
|
|
360
|
+
* Example #3: And I should see an edit conflict
|
|
361
|
+
* Example #4: Then I should see an edit conflict
|
|
362
|
+
* Example #5: And we should see an edit conflict
|
|
363
|
+
*/
|
|
364
|
+
Then(/^(I |we )*should see an edit conflict$/, async function (pronounCase) {
|
|
365
|
+
const heading = clean(await this.page.locator('#firstHeading').innerText().catch(() => ''));
|
|
366
|
+
const explained = await this.page.locator('.mw-explainconflict').count();
|
|
367
|
+
if (!/^Edit conflict:/.test(heading) || !explained) {
|
|
368
|
+
throw friendly({ message: `The wiki did not answer with an edit conflict: ${await pageSummary(this)}.`, hint: 'Both edits must change the same lines; the wiki merges changes to different lines on its own.' });
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Assert the browser's own text that the edit conflict page keeps ("Your text").
|
|
374
|
+
*
|
|
375
|
+
* Example #1: Then the edit conflict should keep my text "My own first line."
|
|
376
|
+
* Example #2: And the edit conflict should keep my text "My own first"
|
|
377
|
+
* Example #3: Then the edit conflict should keep my text "first line"
|
|
378
|
+
* Example #4: Then the edit conflict should keep my text "My own first line."
|
|
379
|
+
* Example #5: And the edit conflict should keep my text "line"
|
|
380
|
+
*/
|
|
381
|
+
Then(/^the edit conflict should keep my text "([^"]*)"$/, async function (expected) {
|
|
382
|
+
const mine = await this.page.locator('#wpTextbox2').inputValue().catch(() => null);
|
|
383
|
+
if (mine === null || !mine.includes(expected)) {
|
|
384
|
+
throw friendly({ message: mine === null ? `No edit conflict is on the page: ${await pageSummary(this)}.` : `The edit conflict keeps "${clean(mine).slice(0, 200)}" as my text, not "${expected}".`, hint: 'The lower text box of the edit conflict page holds the text the browser tried to save.' });
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Assert that the account in the browser may not edit a page: the wiki opens it
|
|
390
|
+
* read only ("View source for <title>") with a message, or a part of it.
|
|
391
|
+
*
|
|
392
|
+
* Example #1: Then editing the page "Protected test page" should be refused with "This page has been protected to prevent editing or other actions."
|
|
393
|
+
* Example #2: Then editing the page "Reading test page" should be refused with "Your username or IP address has been blocked."
|
|
394
|
+
* Example #3: And editing the page "Protected test page" should be refused with "protected"
|
|
395
|
+
* Example #4: Then editing the page "Second test page" should be refused with "This page has been protected"
|
|
396
|
+
* Example #5: Then editing the page "Reading test page" should be refused with "has been blocked"
|
|
397
|
+
*/
|
|
398
|
+
Then(/^editing the page "([^"]*)" should be refused with "([^"]*)"$/, { timeout: 60000 }, async function (title, expected) {
|
|
399
|
+
await openPage(this, title, { action: 'edit' });
|
|
400
|
+
await closeWelcomeDialog(this);
|
|
401
|
+
const heading = clean(await this.page.locator('#firstHeading').innerText().catch(() => ''));
|
|
402
|
+
const errors = await messages(this, 'error');
|
|
403
|
+
const readOnly = await this.page.locator('#wpTextbox1').evaluate((t) => t.readOnly).catch(() => true);
|
|
404
|
+
const save = await this.page.locator('#wpSave').count();
|
|
405
|
+
if (!/^View source for /.test(heading) || !readOnly || save || !hasMessage(errors, expected)) {
|
|
406
|
+
throw friendly({
|
|
407
|
+
message: `The wiki did not refuse "${titleText(title)}" with "${expected}": ${/^View source for /.test(heading) ? `it says ${listed(errors)}` : `the page is "${heading}" ${readOnly ? '' : 'with an editable text box'}`}.`,
|
|
408
|
+
hint: cutRequest(this) ? CUT_HINT : 'Log in as the account that is refused first ("reader" for a protected page); a page any account may edit opens in the editor.',
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
module.exports = { saveFromSourceEditor, saveFromVisualEditor };
|