webship-js 1.0.47 → 2.0.0-alpha1
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/.circleci/config.yml +15 -63
- package/.claude/settings.local.json +128 -4
- package/.github/workflows/github-actions.yml +7 -37
- package/.gitlab-ci.yml +11 -35
- package/.travis-ci.yml +12 -23
- package/.travis.yml +17 -0
- package/README.md +8 -8
- package/bitbucket-pipelines.yml +3 -7
- package/cucumber.js +36 -0
- package/examples/dynamic-examples.html +1 -2
- package/examples/index.html +0 -1
- package/examples/test--modal-dialogs.html +252 -0
- package/examples/test--when--i-click-text-in-table-row.html +1 -1
- package/examples/test--when--i-scroll-functionality.html +34 -33
- package/examples/test--when--i-scroll-left-right-functionality.html +115 -173
- package/package.json +10 -21
- package/playwright.config.ts +37 -0
- package/tests/assets/test-document.pdf +14 -0
- package/tests/step-definitions/webship-api.js +5 -31
- package/tests/step-definitions/webship.js +849 -2498
- package/tsconfig.json +10 -0
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -34
- package/assets/config_templates/circleci-linux-chrome.conf.js +0 -130
- package/assets/config_templates/github-linux-chrome.conf.js +0 -136
- package/dist/nightwatch.conf.dev.js +0 -93
- package/examples/main.js +0 -17
- package/lib/custom-assertions/checkboxChecked.js +0 -87
- package/lib/custom-assertions/elementContainsCss.js +0 -94
- package/lib/custom-assertions/elementContainsText.js +0 -86
- package/lib/custom-assertions/responseStatus.js +0 -31
- package/lib/custom-assertions/shouldVisible.js +0 -8
- package/lib/custom-assertions/textMatching.js +0 -44
- package/lib/custom-commands/checkItem.js +0 -4
- package/lib/custom-commands/clickLink.js +0 -23
- package/lib/custom-commands/fileUpload.js +0 -37
- package/lib/custom-commands/fillTextInput.js +0 -56
- package/lib/custom-commands/press.js +0 -3
- package/lib/custom-commands/selectOption.js +0 -11
- package/lib/custom-commands/uncheckItem.js +0 -4
- package/lib/custom-commands/wait.js +0 -12
- package/nightwatch.conf.js +0 -136
- package/src/index.js +0 -10
- package/steplist.js +0 -245
- package/webpack.config.js +0 -17
- package/webship-init.js +0 -75
|
@@ -1,2673 +1,1024 @@
|
|
|
1
|
-
|
|
2
|
-
const { When } = require('@cucumber/cucumber');
|
|
3
|
-
const { Then } = require('@cucumber/cucumber');
|
|
4
|
-
const {Before, After, BeforeStep, AfterStep} = require('@cucumber/cucumber');
|
|
5
|
-
|
|
1
|
+
'use strict';
|
|
6
2
|
|
|
3
|
+
const { setWorldConstructor, World, Before, After, BeforeStep, AfterStep, setDefaultTimeout, Given, When, Then } = require('@cucumber/cucumber');
|
|
4
|
+
const playwright = require('playwright');
|
|
5
|
+
const playwrightConfig = require('../../playwright.config');
|
|
6
|
+
const assert = require('assert');
|
|
7
7
|
const axios = require('axios');
|
|
8
8
|
const path = require('path');
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// World
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
setDefaultTimeout(30 * 1000);
|
|
14
|
+
|
|
15
|
+
class PlaywrightWorld extends World {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
super(options);
|
|
18
|
+
this.launchUrl = this.parameters.launchUrl;
|
|
19
|
+
this.minWaitTime = this.parameters.minWaitTime;
|
|
20
|
+
this.playwrightBrowser = null;
|
|
21
|
+
this.context = null;
|
|
22
|
+
this.page = null;
|
|
23
|
+
this.assetsFolder = path.join(__dirname, '../assets/');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async openBrowser() {
|
|
27
|
+
const { browser: browserName, launchOptions, contextOptions } = playwrightConfig;
|
|
28
|
+
this.playwrightBrowser = await playwright[browserName].launch(launchOptions);
|
|
29
|
+
this.context = await this.playwrightBrowser.newContext(contextOptions);
|
|
30
|
+
this.page = await this.context.newPage();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async closeBrowser() {
|
|
34
|
+
if (this.playwrightBrowser) {
|
|
35
|
+
await this.playwrightBrowser.close();
|
|
36
|
+
this.playwrightBrowser = null;
|
|
37
|
+
this.context = null;
|
|
38
|
+
this.page = null;
|
|
39
|
+
}
|
|
20
40
|
}
|
|
21
41
|
}
|
|
22
42
|
|
|
23
|
-
|
|
24
|
-
safePause('before_scenario');
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
After(function () {
|
|
28
|
-
safePause('after_scenario');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
BeforeStep(function () {
|
|
32
|
-
safePause('before_step');
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
AfterStep(function () {
|
|
36
|
-
safePause('after_step');
|
|
37
|
-
});
|
|
43
|
+
setWorldConstructor(PlaywrightWorld);
|
|
38
44
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
* Example #2: Given I am on the homepage
|
|
44
|
-
* Example #2: Given I am on frontpage
|
|
45
|
-
* Example #3: Given I am on the frontpage
|
|
46
|
-
* Example #4: Given we are on homepage
|
|
47
|
-
* Example #5: Given on the homepage
|
|
48
|
-
* Example #6: Given on homepage
|
|
49
|
-
* Example #7: Given we are on the frontpage
|
|
50
|
-
* Example #8: Given on frontpage
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*/
|
|
54
|
-
Given(/^(I am |we are )?on( the)* (homepage|frontpage)$/, function (pronounCase, theCase, pageCase) {
|
|
55
|
-
browser.url(browser.launch_url);
|
|
56
|
-
let defaultTime = 3000;
|
|
57
|
-
if (browser.globals && browser.globals.minimum_wait_time && browser.globals.minimum_wait_time.page) {
|
|
58
|
-
defaultTime = browser.globals.minimum_wait_time.page;
|
|
45
|
+
Before(async function () {
|
|
46
|
+
await this.openBrowser();
|
|
47
|
+
if (this.minWaitTime.before_scenario > 0) {
|
|
48
|
+
await this.page.waitForTimeout(this.minWaitTime.before_scenario);
|
|
59
49
|
}
|
|
60
|
-
browser.waitForElementPresent('body', defaultTime);
|
|
61
|
-
// Wait for any dynamic content to be loaded
|
|
62
|
-
return browser.executeScript('return document.readyState').then(function(result) {
|
|
63
|
-
if (result !== 'complete') {
|
|
64
|
-
return browser.pause(500);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
50
|
});
|
|
68
51
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
* Example #3: Given I am on the "/about-us.html" page
|
|
75
|
-
* Example #4: Given we are on the "/about-us.html" page
|
|
76
|
-
* Example #5: Given on "/about-us.html"
|
|
77
|
-
* Example #6: Given on the "/about-us.html" page
|
|
78
|
-
*
|
|
79
|
-
*/
|
|
80
|
-
Given(/^(I am |we are )*on( the)* "([^"]*)?"( page)*$/, function (pronounCase, theCase, url, pageCase) {
|
|
81
|
-
browser.url(browser.launch_url + url);
|
|
82
|
-
|
|
83
|
-
// Wait for body element to be present using active DOM polling
|
|
84
|
-
return browser.executeAsync(function(done) {
|
|
85
|
-
var maxAttempts = 20;
|
|
86
|
-
var attempts = 0;
|
|
87
|
-
|
|
88
|
-
var checkBody = setInterval(function() {
|
|
89
|
-
var body = document.querySelector('body');
|
|
90
|
-
var readyState = document.readyState;
|
|
91
|
-
attempts++;
|
|
92
|
-
|
|
93
|
-
if (body && (readyState === 'interactive' || readyState === 'complete')) {
|
|
94
|
-
clearInterval(checkBody);
|
|
95
|
-
done({ found: true });
|
|
96
|
-
} else if (attempts >= maxAttempts) {
|
|
97
|
-
clearInterval(checkBody);
|
|
98
|
-
done({ found: false });
|
|
99
|
-
}
|
|
100
|
-
}, 500);
|
|
101
|
-
}, [], function(result) {
|
|
102
|
-
if (!result || !result.value || !result.value.found) {
|
|
103
|
-
browser.assert.fail('Page body element was not found after navigation to "' + url + '"');
|
|
104
|
-
}
|
|
105
|
-
});
|
|
52
|
+
After(async function () {
|
|
53
|
+
if (this.minWaitTime.after_scenario > 0) {
|
|
54
|
+
await this.page.waitForTimeout(this.minWaitTime.after_scenario);
|
|
55
|
+
}
|
|
56
|
+
await this.closeBrowser();
|
|
106
57
|
});
|
|
107
58
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
* Example #1: When I go to homepage
|
|
112
|
-
* Example #2: When I go to the homepage
|
|
113
|
-
* Example #3: When I navigate to the homepage
|
|
114
|
-
* Example #4: When navigating to the homepage
|
|
115
|
-
* Example #5: When navigating to homepage
|
|
116
|
-
* Example #6: When navigating to the frontpage
|
|
117
|
-
* Example #7: When we go to the homepage
|
|
118
|
-
* Example #8: When we navigate to the homepage
|
|
119
|
-
*
|
|
120
|
-
*/
|
|
121
|
-
When(/^(I go |I navigate |we go |we navigate |navigating )?to( the)* (homepage|frontpage)$/, function (pronounCase, theCase, pageCase) {
|
|
122
|
-
browser.url(browser.launch_url);
|
|
123
|
-
let defaultTime = 3000;
|
|
124
|
-
if (browser.globals && browser.globals.minimum_wait_time && browser.globals.minimum_wait_time.page) {
|
|
125
|
-
defaultTime = browser.globals.minimum_wait_time.page;
|
|
59
|
+
BeforeStep(async function () {
|
|
60
|
+
if (this.page && this.minWaitTime.before_step > 0) {
|
|
61
|
+
await this.page.waitForTimeout(this.minWaitTime.before_step);
|
|
126
62
|
}
|
|
127
|
-
browser.waitForElementPresent('body', defaultTime);
|
|
128
|
-
// Wait for any dynamic content to be loaded
|
|
129
|
-
return browser.executeScript('return document.readyState').then(function(result) {
|
|
130
|
-
if (result !== 'complete') {
|
|
131
|
-
return browser.pause(500);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
63
|
});
|
|
135
64
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
* Example #1: When I go to "/contact-us.html"
|
|
140
|
-
* Example #2: When I go to "/user/login"
|
|
141
|
-
* Example #3: When I navigate to "/admin/dashboard"
|
|
142
|
-
* Example #4: When navigating to "/products"
|
|
143
|
-
* Example #7: When we go to "/products"
|
|
144
|
-
* Example #8: When we navigate to "/terms"
|
|
145
|
-
*
|
|
146
|
-
*/
|
|
147
|
-
When(/^(I go |I navigate |we go |we navigate |navigating )?to "([^"]*)?"$/, function (pronounCase, url) {
|
|
148
|
-
browser.url(browser.launch_url + url);
|
|
149
|
-
let defaultTime = 3000;
|
|
150
|
-
if (browser.globals && browser.globals.minimum_wait_time && browser.globals.minimum_wait_time.page) {
|
|
151
|
-
defaultTime = browser.globals.minimum_wait_time.page;
|
|
65
|
+
AfterStep(async function () {
|
|
66
|
+
if (this.page && this.minWaitTime.after_step > 0) {
|
|
67
|
+
await this.page.waitForTimeout(this.minWaitTime.after_step);
|
|
152
68
|
}
|
|
153
|
-
browser.waitForElementPresent('body', defaultTime);
|
|
154
|
-
// Wait for any dynamic content to be loaded
|
|
155
|
-
return browser.executeScript('return document.readyState').then(function(result) {
|
|
156
|
-
if (result !== 'complete') {
|
|
157
|
-
return browser.pause(500);
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
69
|
});
|
|
161
70
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
*
|
|
186
|
-
*/
|
|
187
|
-
When(/^(I |we )*move forward one page$/, function (pronounCase) {
|
|
188
|
-
return browser.forward();
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Moves backward one page in browser history.
|
|
193
|
-
*
|
|
194
|
-
* Example: When I move backward one page
|
|
195
|
-
*
|
|
196
|
-
*/
|
|
197
|
-
When(/^(I |we )*move backward one page$/, function (pronounCase) {
|
|
198
|
-
return browser.back();
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Presses button with specified element.
|
|
203
|
-
*
|
|
204
|
-
* Example: When I press "Log In"
|
|
205
|
-
* Example: And I press the "Log In" button
|
|
206
|
-
* Example: And I press the "Save as" button
|
|
207
|
-
*
|
|
208
|
-
*/
|
|
209
|
-
When(/^(I |we )*press( the)* "([^"]*)?"( button)*$/, function (pronounCase, theCase, element, buttonCase) {
|
|
210
|
-
// Actively wait for dynamically generated button by polling the DOM
|
|
211
|
-
return browser.executeAsync(function(buttonText, done) {
|
|
212
|
-
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds
|
|
213
|
-
var attempts = 0;
|
|
214
|
-
|
|
215
|
-
var checkButton = setInterval(function() {
|
|
216
|
-
const buttons = document.querySelectorAll('button, input[type="button"], input[type="submit"], [role="button"], .btn, a');
|
|
217
|
-
var foundButton = null;
|
|
218
|
-
|
|
219
|
-
for (let btn of buttons) {
|
|
220
|
-
const text = (btn.textContent || btn.innerText || btn.value || '').trim();
|
|
221
|
-
if (text === buttonText) {
|
|
222
|
-
foundButton = btn;
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
attempts++;
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
// Helper: build CSS selector from attrValue + optional attr argument.
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
function buildSelector(attrValue, attr) {
|
|
75
|
+
const hasASpace = attrValue.indexOf(' ');
|
|
76
|
+
if ((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace === -1) {
|
|
77
|
+
return attrValue;
|
|
78
|
+
}
|
|
79
|
+
if (!attr && hasASpace === -1) {
|
|
80
|
+
return (
|
|
81
|
+
attrValue +
|
|
82
|
+
',#' + attrValue +
|
|
83
|
+
',.' + attrValue +
|
|
84
|
+
',[name=' + attrValue + '],' +
|
|
85
|
+
'[value="' + attrValue + '"],[placeholder="' + attrValue + '"]' +
|
|
86
|
+
',[title="' + attrValue + '"]'
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (!attr && hasASpace > -1) {
|
|
90
|
+
return '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
91
|
+
}
|
|
92
|
+
return '[' + attr + '="' + attrValue + '" i]';
|
|
93
|
+
}
|
|
228
94
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
clearInterval(checkButton);
|
|
236
|
-
done({ found: false });
|
|
237
|
-
}
|
|
238
|
-
}, 500);
|
|
239
|
-
}, [element], function(result) {
|
|
240
|
-
if (!result || !result.value || !result.value.found) {
|
|
241
|
-
browser.assert.fail('Button "' + element + '" was not found in dynamically generated content');
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
});
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
// Helper: wait for domcontentloaded
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
async function waitForPageLoad(page, timeout) {
|
|
99
|
+
await page.waitForLoadState('domcontentloaded', { timeout: timeout || 10000 });
|
|
100
|
+
}
|
|
245
101
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
When(/^(I |we )*press "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, attrValue, itsCase, attr, attrCase) {
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
// Helper: navigate to a URL, tolerating empty-response errors (Firefox)
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
async function gotoUrl(page, url) {
|
|
106
|
+
try {
|
|
107
|
+
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
|
108
|
+
} catch (e) {
|
|
109
|
+
if (!/NS_ERROR_NET_EMPTY_RESPONSE|net::ERR_EMPTY_RESPONSE/.test(e.message)) throw e;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
257
112
|
|
|
258
|
-
|
|
259
|
-
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
// Helper: fill a field located by label, placeholder, or name
|
|
115
|
+
// ---------------------------------------------------------------------------
|
|
116
|
+
async function fillField(page, field, value) {
|
|
117
|
+
const byLabel = page.getByLabel(field, { exact: true });
|
|
118
|
+
if (await byLabel.count() > 0) {
|
|
119
|
+
await byLabel.fill(value);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const byPlaceholder = page.getByPlaceholder(field, { exact: true });
|
|
123
|
+
if (await byPlaceholder.count() > 0) {
|
|
124
|
+
await byPlaceholder.fill(value);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
await page.locator(`[name="${field}"]`).first().fill(value);
|
|
128
|
+
}
|
|
260
129
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
selector = '[' + attr + '="' + attrValue + '"]';
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
// Helper: get text from a locator — input value or text content
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
async function getLocatorText(locator) {
|
|
134
|
+
try {
|
|
135
|
+
return await locator.inputValue();
|
|
136
|
+
} catch {
|
|
137
|
+
return await locator.textContent() || '';
|
|
272
138
|
}
|
|
139
|
+
}
|
|
273
140
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}
|
|
141
|
+
const MODAL_SELECTOR = '.modal, .modal.show, .modal.in, [role="dialog"], .dialog, .popup';
|
|
142
|
+
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
// Helper: wait for any matching modal element to reach a state
|
|
145
|
+
// ---------------------------------------------------------------------------
|
|
146
|
+
async function waitForModalState(page, state, timeout) {
|
|
147
|
+
const sel = MODAL_SELECTOR;
|
|
148
|
+
if (state === 'visible') {
|
|
149
|
+
await page.waitForFunction(
|
|
150
|
+
(s) => Array.from(document.querySelectorAll(s)).some(el => {
|
|
151
|
+
const cs = window.getComputedStyle(el);
|
|
152
|
+
return cs.display !== 'none' && cs.visibility !== 'hidden' && el.offsetParent !== null;
|
|
153
|
+
}),
|
|
154
|
+
sel, { timeout }
|
|
155
|
+
);
|
|
156
|
+
} else {
|
|
157
|
+
await page.waitForFunction(
|
|
158
|
+
(s) => !Array.from(document.querySelectorAll(s)).some(el => {
|
|
159
|
+
const cs = window.getComputedStyle(el);
|
|
160
|
+
return cs.display !== 'none' && cs.visibility !== 'hidden' && el.offsetParent !== null;
|
|
161
|
+
}),
|
|
162
|
+
sel, { timeout }
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
298
166
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
var attempts = 0;
|
|
311
|
-
|
|
312
|
-
var checkLink = setInterval(function() {
|
|
313
|
-
var clickableElements = document.querySelectorAll('a, button, [role="button"], .btn, input[type="button"], input[type="submit"]');
|
|
314
|
-
var foundElement = null;
|
|
315
|
-
|
|
316
|
-
for (var i = 0; i < clickableElements.length; i++) {
|
|
317
|
-
var text = (clickableElements[i].textContent || clickableElements[i].innerText || clickableElements[i].value || '').trim();
|
|
318
|
-
if (text === linkText) {
|
|
319
|
-
foundElement = clickableElements[i];
|
|
320
|
-
break;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
167
|
+
// ---------------------------------------------------------------------------
|
|
168
|
+
// Helper: find the first visible modal locator
|
|
169
|
+
// ---------------------------------------------------------------------------
|
|
170
|
+
async function findVisibleModal(page) {
|
|
171
|
+
const all = page.locator(MODAL_SELECTOR);
|
|
172
|
+
const count = await all.count();
|
|
173
|
+
for (let i = 0; i < count; i++) {
|
|
174
|
+
if (await all.nth(i).isVisible()) return all.nth(i);
|
|
175
|
+
}
|
|
176
|
+
throw new Error('No visible modal found');
|
|
177
|
+
}
|
|
323
178
|
|
|
324
|
-
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
// Helper: check if any modal is currently visible
|
|
181
|
+
// ---------------------------------------------------------------------------
|
|
182
|
+
async function isAnyModalVisible(page) {
|
|
183
|
+
return page.evaluate((sel) =>
|
|
184
|
+
Array.from(document.querySelectorAll(sel)).some(el => {
|
|
185
|
+
const cs = window.getComputedStyle(el);
|
|
186
|
+
return cs.display !== 'none' && cs.visibility !== 'hidden' && el.offsetParent !== null;
|
|
187
|
+
}),
|
|
188
|
+
MODAL_SELECTOR
|
|
189
|
+
);
|
|
190
|
+
}
|
|
325
191
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
192
|
+
// ---------------------------------------------------------------------------
|
|
193
|
+
// Given I am on homepage / frontpage
|
|
194
|
+
// Captures: (pronounCase, theCase, pageCase) = 3
|
|
195
|
+
// ---------------------------------------------------------------------------
|
|
196
|
+
Given(/^(I am |we are )?on( the)* (homepage|frontpage)$/, async function (pronounCase, theCase, pageCase) {
|
|
197
|
+
const defaultTime = this.minWaitTime.page || 3000;
|
|
198
|
+
await gotoUrl(this.page, this.launchUrl);
|
|
199
|
+
await this.page.waitForSelector('body', { state: 'attached', timeout: defaultTime });
|
|
200
|
+
await waitForPageLoad(this.page, defaultTime);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
// Given I am on "/about-us.html"
|
|
205
|
+
// Captures: (pronounCase, theCase, url, pageCase) = 4
|
|
206
|
+
// ---------------------------------------------------------------------------
|
|
207
|
+
Given(/^(I am |we are )*on( the)* "([^"]*)?"( page)*$/, async function (pronounCase, theCase, url, pageCase) {
|
|
208
|
+
await gotoUrl(this.page, this.launchUrl + url);
|
|
209
|
+
await this.page.waitForSelector('body', { state: 'attached', timeout: 10000 });
|
|
210
|
+
await waitForPageLoad(this.page);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// ---------------------------------------------------------------------------
|
|
214
|
+
// When I go to homepage / frontpage
|
|
215
|
+
// Captures: (pronounCase, theCase, pageCase) = 3
|
|
216
|
+
// ---------------------------------------------------------------------------
|
|
217
|
+
When(/^(I go |I navigate |we go |we navigate |navigating )?to( the)* (homepage|frontpage)$/, async function (pronounCase, theCase, pageCase) {
|
|
218
|
+
const defaultTime = this.minWaitTime.page || 3000;
|
|
219
|
+
await gotoUrl(this.page, this.launchUrl);
|
|
220
|
+
await this.page.waitForSelector('body', { state: 'attached', timeout: defaultTime });
|
|
221
|
+
await waitForPageLoad(this.page, defaultTime);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// ---------------------------------------------------------------------------
|
|
225
|
+
// When I go to "/contact-us.html"
|
|
226
|
+
// Captures: (pronounCase, url) = 2
|
|
227
|
+
// ---------------------------------------------------------------------------
|
|
228
|
+
When(/^(I go |I navigate |we go |we navigate |navigating )?to "([^"]*)?"$/, async function (pronounCase, url) {
|
|
229
|
+
const defaultTime = this.minWaitTime.page || 3000;
|
|
230
|
+
await gotoUrl(this.page, this.launchUrl + url);
|
|
231
|
+
await this.page.waitForSelector('body', { state: 'attached', timeout: defaultTime });
|
|
232
|
+
await waitForPageLoad(this.page, defaultTime);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// ---------------------------------------------------------------------------
|
|
236
|
+
// Then I should see "text" / Then I should not see "text"
|
|
237
|
+
// Captures: (pronounCase, notCase, expectedText) = 3
|
|
238
|
+
// ---------------------------------------------------------------------------
|
|
239
|
+
Then(/^(I |we )*should( not)* see "([^"]*)?"$/, async function (pronounCase, notCase, expectedText) {
|
|
240
|
+
if (notCase) {
|
|
241
|
+
const text = await this.page.locator('body').textContent() || '';
|
|
242
|
+
assert.ok(!text.includes(expectedText), `Page should NOT contain "${expectedText}" but it does.`);
|
|
243
|
+
} else {
|
|
244
|
+
await this.page.locator('body').filter({ hasText: expectedText }).waitFor({ timeout: 5000 });
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// ---------------------------------------------------------------------------
|
|
249
|
+
// When I move forward one page
|
|
250
|
+
// Captures: (pronounCase) = 1
|
|
251
|
+
// ---------------------------------------------------------------------------
|
|
252
|
+
When(/^(I |we )*move forward one page$/, async function (pronounCase) {
|
|
253
|
+
await this.page.goForward();
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// ---------------------------------------------------------------------------
|
|
257
|
+
// When I move backward one page
|
|
258
|
+
// Captures: (pronounCase) = 1
|
|
259
|
+
// ---------------------------------------------------------------------------
|
|
260
|
+
When(/^(I |we )*move backward one page$/, async function (pronounCase) {
|
|
261
|
+
await this.page.goBack();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// ---------------------------------------------------------------------------
|
|
265
|
+
// When I press "Log In" button
|
|
266
|
+
// Captures: (pronounCase, theCase, element, buttonCase) = 4
|
|
267
|
+
// ---------------------------------------------------------------------------
|
|
268
|
+
When(/^(I |we )*press( the)* "([^"]*)?"( button)*$/, async function (pronounCase, theCase, element, buttonCase) {
|
|
269
|
+
const esc = element.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
270
|
+
await this.page.locator('button, input[type="button"], input[type="submit"], [role="button"], .btn, a')
|
|
271
|
+
.filter({ hasText: new RegExp('^' + esc + '$') })
|
|
272
|
+
.first()
|
|
273
|
+
.click();
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
// ---------------------------------------------------------------------------
|
|
277
|
+
// When I press "btn-pressid" by attr / attribute
|
|
278
|
+
// Captures: (pronounCase, attrValue, itsCase, attr, attrWord) = 5
|
|
279
|
+
// ---------------------------------------------------------------------------
|
|
280
|
+
When(/^(I |we )*press "([^"]*)?" by( its)*(?: "([^"]*)?")* (attribute|attr)$/, async function (pronounCase, attrValue, itsCase, attr, attrWord) {
|
|
281
|
+
await this.page.locator(buildSelector(attrValue, attr)).first().click();
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// ---------------------------------------------------------------------------
|
|
285
|
+
// When I click "Contact Us"
|
|
286
|
+
// Captures: (pronounCase, item) = 2
|
|
287
|
+
// ---------------------------------------------------------------------------
|
|
288
|
+
When(/^(I |we )*click "([^"]*)?"$/, async function (pronounCase, item) {
|
|
289
|
+
const esc = item.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
290
|
+
await this.page.locator('a, button, [role="button"], .btn, input[type="button"], input[type="submit"]')
|
|
291
|
+
.filter({ hasText: new RegExp('^' + esc + '$') })
|
|
292
|
+
.first()
|
|
293
|
+
.click();
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// ---------------------------------------------------------------------------
|
|
297
|
+
// When I click "#about-us-id" by attr / attribute
|
|
298
|
+
// Captures: (pronounCase, attrValue, itsCase, attr, attrWord) = 5
|
|
299
|
+
// ---------------------------------------------------------------------------
|
|
300
|
+
When(/^(I |we )*click "([^"]*)?" by( its)*(?: "([^"]*)?")* (attribute|attr)$/, async function (pronounCase, attrValue, itsCase, attr, attrWord) {
|
|
301
|
+
await this.page.locator(buildSelector(attrValue, attr)).first().click();
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
// ---------------------------------------------------------------------------
|
|
305
|
+
// When I click "Edit" in the "John Smith" row
|
|
306
|
+
// Captures: (pronounCase, clickText, theCase, rowIdentifier) = 4
|
|
307
|
+
// ---------------------------------------------------------------------------
|
|
308
|
+
When(/^(I |we )*click "([^"]*)?" in( the)* "([^"]*)?" row$/, async function (pronounCase, clickText, theCase, rowIdentifier) {
|
|
309
|
+
const esc = clickText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
310
|
+
const row = this.page.locator('tr').filter({ hasText: rowIdentifier }).first();
|
|
311
|
+
const clickable = row.locator('a, button, [role="button"], .btn, input[type="submit"], input[type="button"]')
|
|
312
|
+
.filter({ hasText: new RegExp('^' + esc + '$') });
|
|
313
|
+
if (await clickable.count() > 0) {
|
|
314
|
+
await clickable.first().click();
|
|
315
|
+
} else {
|
|
316
|
+
await row.getByText(clickText, { exact: true }).first().click();
|
|
317
|
+
}
|
|
340
318
|
});
|
|
341
319
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
*
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
if((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace == -1){
|
|
357
|
-
selector = attrValue;
|
|
358
|
-
}
|
|
359
|
-
else if (!attr && hasASpace == -1){
|
|
360
|
-
selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
361
|
-
}
|
|
362
|
-
else if (!attr && hasASpace > -1){
|
|
363
|
-
selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
364
|
-
}
|
|
365
|
-
else {
|
|
366
|
-
selector = '[' + attr + '="' + attrValue + '"]';
|
|
320
|
+
// ---------------------------------------------------------------------------
|
|
321
|
+
// Then I should see "Active" in the "John Smith" row
|
|
322
|
+
// Captures: (pronounCase, notCase, expectedText, theCase, rowIdentifier) = 5
|
|
323
|
+
// ---------------------------------------------------------------------------
|
|
324
|
+
Then(/^(I |we )*should( not)* see "([^"]*)?" in( the)* "([^"]*)?" row$/, async function (pronounCase, notCase, expectedText, theCase, rowIdentifier) {
|
|
325
|
+
const found = await this.page.evaluate(({ id, text }) => {
|
|
326
|
+
const rows = Array.from(document.querySelectorAll('tr'));
|
|
327
|
+
return rows.filter(r => r.textContent.includes(id)).some(r => r.textContent.includes(text));
|
|
328
|
+
}, { id: rowIdentifier, text: expectedText });
|
|
329
|
+
if (notCase) {
|
|
330
|
+
assert.ok(!found, `Found "${expectedText}" in the "${rowIdentifier}" row, but it should not be there.`);
|
|
331
|
+
} else {
|
|
332
|
+
assert.ok(found, `Could not find "${expectedText}" in the "${rowIdentifier}" row.`);
|
|
367
333
|
}
|
|
368
|
-
|
|
369
|
-
return browser.executeAsync(function(sel, done) {
|
|
370
|
-
var maxAttempts = 20;
|
|
371
|
-
var attempts = 0;
|
|
372
|
-
|
|
373
|
-
var checkElement = setInterval(function() {
|
|
374
|
-
var element = document.querySelector(sel);
|
|
375
|
-
attempts++;
|
|
376
|
-
|
|
377
|
-
if (element) {
|
|
378
|
-
clearInterval(checkElement);
|
|
379
|
-
element.click();
|
|
380
|
-
done({ found: true });
|
|
381
|
-
} else if (attempts >= maxAttempts) {
|
|
382
|
-
clearInterval(checkElement);
|
|
383
|
-
done({ found: false });
|
|
384
|
-
}
|
|
385
|
-
}, 500);
|
|
386
|
-
}, [selector], function(result) {
|
|
387
|
-
if (!result || !result.value || !result.value.found) {
|
|
388
|
-
browser.assert.fail('Element with selector "' + selector + '" was not found in dynamically generated content');
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
|
|
392
334
|
});
|
|
393
335
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
*
|
|
399
|
-
|
|
400
|
-
* Example #3: When we click "View Details" in the "Order #12345" row
|
|
401
|
-
* Example #4: And I click "Download" in the "Report 2024" row
|
|
402
|
-
*
|
|
403
|
-
*/
|
|
404
|
-
When(/^(I |we )*click "([^"]*)?" in( the)* "([^"]*)?" row$/, function (pronounCase, clickText, theCase, rowIdentifier) {
|
|
405
|
-
|
|
406
|
-
return browser.executeAsync(function(rowId, targetText, done) {
|
|
407
|
-
var maxAttempts = 20;
|
|
408
|
-
var attempts = 0;
|
|
409
|
-
|
|
410
|
-
var checkTable = setInterval(function() {
|
|
411
|
-
// Find all tables on the page
|
|
412
|
-
const tables = document.querySelectorAll('table');
|
|
413
|
-
attempts++;
|
|
414
|
-
|
|
415
|
-
if (tables.length > 0) {
|
|
416
|
-
clearInterval(checkTable);
|
|
417
|
-
|
|
418
|
-
// Search through each table for the row containing the identifier
|
|
419
|
-
for (let table of tables) {
|
|
420
|
-
const rows = table.querySelectorAll('tr');
|
|
421
|
-
for (let row of rows) {
|
|
422
|
-
const rowText = row.textContent || row.innerText;
|
|
423
|
-
if (rowText.includes(rowId)) {
|
|
424
|
-
// Found the correct row, now look for clickable elements with the target text
|
|
425
|
-
|
|
426
|
-
// First, try to find exact text matches in clickable elements
|
|
427
|
-
const clickableElements = row.querySelectorAll('a, button, [onclick], [role="button"], .btn, input[type="submit"], input[type="button"]');
|
|
428
|
-
for (let element of clickableElements) {
|
|
429
|
-
const elementText = (element.textContent || element.innerText || element.value || '').trim();
|
|
430
|
-
if (elementText === targetText) {
|
|
431
|
-
element.click();
|
|
432
|
-
done({ success: true, element: element.tagName });
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
// If not found in obvious clickable elements, search all elements
|
|
438
|
-
const allElements = row.querySelectorAll('*');
|
|
439
|
-
for (let element of allElements) {
|
|
440
|
-
const elementText = (element.textContent || element.innerText || '').trim();
|
|
441
|
-
if (elementText === targetText) {
|
|
442
|
-
// Check if element or parent is clickable
|
|
443
|
-
let clickableParent = element;
|
|
444
|
-
while (clickableParent && clickableParent !== row) {
|
|
445
|
-
if (clickableParent.tagName === 'A' ||
|
|
446
|
-
clickableParent.tagName === 'BUTTON' ||
|
|
447
|
-
clickableParent.onclick ||
|
|
448
|
-
clickableParent.getAttribute('role') === 'button' ||
|
|
449
|
-
clickableParent.classList.contains('btn') ||
|
|
450
|
-
clickableParent.style.cursor === 'pointer') {
|
|
451
|
-
clickableParent.click();
|
|
452
|
-
done({ success: true, element: clickableParent.tagName });
|
|
453
|
-
return;
|
|
454
|
-
}
|
|
455
|
-
clickableParent = clickableParent.parentElement;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
// If no clickable parent found, try clicking the element itself
|
|
459
|
-
try {
|
|
460
|
-
element.click();
|
|
461
|
-
done({ success: true, element: element.tagName });
|
|
462
|
-
return;
|
|
463
|
-
} catch (e) {
|
|
464
|
-
// Continue searching if click failed
|
|
465
|
-
continue;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
// Row found but target text not clickable
|
|
471
|
-
done({
|
|
472
|
-
success: false,
|
|
473
|
-
error: 'Found row containing "' + rowId + '" but could not find clickable "' + targetText + '" within it. Row contains: ' + rowText.substring(0, 200) + '...'
|
|
474
|
-
});
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// Row not found
|
|
481
|
-
done({
|
|
482
|
-
success: false,
|
|
483
|
-
error: 'Could not find row containing "' + rowId + '". Available rows: ' + Array.from(document.querySelectorAll('table tr')).map(function(r) { return (r.textContent || '').substring(0, 50); }).join(', ')
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
} else if (attempts >= maxAttempts) {
|
|
487
|
-
clearInterval(checkTable);
|
|
488
|
-
done({
|
|
489
|
-
success: false,
|
|
490
|
-
error: 'No tables found on the page after waiting'
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
}, 500);
|
|
494
|
-
}, [rowIdentifier, clickText], function(result) {
|
|
495
|
-
if (!result || !result.value || !result.value.success) {
|
|
496
|
-
var errorMsg = (result && result.value && result.value.error) || 'Could not find "' + clickText + '" in the "' + rowIdentifier + '" row. Please verify the table structure and text content.';
|
|
497
|
-
browser.assert.fail(errorMsg);
|
|
498
|
-
}
|
|
499
|
-
});
|
|
336
|
+
// ---------------------------------------------------------------------------
|
|
337
|
+
// When I reload the page
|
|
338
|
+
// Captures: (pronounCase, theCase, pageCase) = 3
|
|
339
|
+
// ---------------------------------------------------------------------------
|
|
340
|
+
When(/^(I |we )*reload( the)*( page)*$/, async function (pronounCase, theCase, pageCase) {
|
|
341
|
+
await this.page.reload();
|
|
500
342
|
});
|
|
501
343
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
*
|
|
507
|
-
|
|
508
|
-
* Example #3: Then we should see "Processing" in the "Order #12345" row
|
|
509
|
-
* Example #4: And I should see "Admin" in the "john.smith@example.com" row
|
|
510
|
-
* Example #5: Then I should not see "Admin" in the "Jane Doe" row
|
|
511
|
-
* Example #6: Then I should not see "Out of Stock" in the "Product A" row
|
|
512
|
-
* Example #7: And I should not see "Inactive" in the "john.smith@example.com" row
|
|
513
|
-
*
|
|
514
|
-
*/
|
|
515
|
-
Then(/^(I |we )*should( not)* see "([^"]*)?" in( the)* "([^"]*)?" row$/, function (pronounCase, notCase, expectedText, theCase, rowIdentifier) {
|
|
516
|
-
|
|
517
|
-
return browser.execute(function(rowId, expectedTxt) {
|
|
518
|
-
// Find all tables
|
|
519
|
-
const tables = document.querySelectorAll('table');
|
|
520
|
-
if (tables.length === 0) {
|
|
521
|
-
throw new Error('No tables found on the page');
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
// Search through each table for the row containing the identifier
|
|
525
|
-
for (let table of tables) {
|
|
526
|
-
const rows = table.querySelectorAll('tr');
|
|
527
|
-
for (let row of rows) {
|
|
528
|
-
const rowText = row.textContent || row.innerText;
|
|
529
|
-
if (rowText.includes(rowId)) {
|
|
530
|
-
// Found the correct row, now check if it contains the expected text
|
|
531
|
-
if (rowText.includes(expectedTxt)) {
|
|
532
|
-
return true; // Found the text
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
return false; // Text not found
|
|
538
|
-
}, [rowIdentifier, expectedText], function(result) {
|
|
539
|
-
if (notCase) {
|
|
540
|
-
if (result.value) {
|
|
541
|
-
throw new Error(`Found "${expectedText}" in the "${rowIdentifier}" row, but it should not be there.`);
|
|
542
|
-
}
|
|
543
|
-
} else {
|
|
544
|
-
if (!result.value) {
|
|
545
|
-
throw new Error(`Could not find "${expectedText}" in the "${rowIdentifier}" row. Please verify the table structure and text content.`);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
});
|
|
344
|
+
// ---------------------------------------------------------------------------
|
|
345
|
+
// When I fill in "Username" with "John Smith"
|
|
346
|
+
// Captures: (pronounCase, field, value) = 3
|
|
347
|
+
// ---------------------------------------------------------------------------
|
|
348
|
+
When(/^(I |we )*fill in "([^"]*)?" with "([^"]*)?"$/, async function (pronounCase, field, value) {
|
|
349
|
+
await fillField(this.page, field, value);
|
|
549
350
|
});
|
|
550
351
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
*
|
|
556
|
-
|
|
557
|
-
* Example #4: And we reload the page
|
|
558
|
-
*
|
|
559
|
-
*/
|
|
560
|
-
When(/^(I |we )*reload( the)*( page)*$/, function (pronounCase, theCase, pageCase) {
|
|
561
|
-
return browser.refresh(browser.getCurrentUrl());
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
/**
|
|
565
|
-
* Define the step of filling values in the form field specified element.
|
|
566
|
-
*
|
|
567
|
-
* Example: When I fill in "Username" with "John Smith"
|
|
568
|
-
*
|
|
569
|
-
*/
|
|
570
|
-
When(/^(I |we )*fill in "([^"]*)?" with "([^"]*)?"$/, function (pronounCase, field, value) {
|
|
571
|
-
// Wait for dynamic content to render (AJAX/JS)
|
|
572
|
-
browser.pause(500);
|
|
573
|
-
const elementField = browser.element.findByText(field, { exact: true });
|
|
574
|
-
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
575
|
-
// Wait for the input element to be present (handles dynamically generated form fields)
|
|
576
|
-
browser.waitForElementPresent('#' + eleAttribute.value, 5000);
|
|
577
|
-
return browser.setValue('#' + eleAttribute.value, value);
|
|
578
|
-
});
|
|
352
|
+
// ---------------------------------------------------------------------------
|
|
353
|
+
// When I fill in "uname" with "John Smith" by attr
|
|
354
|
+
// Captures: (pronounCase, attrValue, txtValue, itsCase, attr, attrWord) = 6
|
|
355
|
+
// ---------------------------------------------------------------------------
|
|
356
|
+
When(/^(I |we )*fill in "([^"]*)?" with "([^"]*)?" by( its)*(?: "([^"]*)?")* (attribute|attr)$/, async function (pronounCase, attrValue, txtValue, itsCase, attr, attrWord) {
|
|
357
|
+
await this.page.locator(buildSelector(attrValue, attr)).first().fill(txtValue);
|
|
579
358
|
});
|
|
580
359
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
* Example: And I fill in "Your full name" with "John Smith" by its "placeholder" attribute
|
|
588
|
-
*
|
|
589
|
-
*/
|
|
590
|
-
When(/^(I |we )*fill in "([^"]*)?" with "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, attrValue, txtValue, itsCase, attr, attrCase) {
|
|
591
|
-
|
|
592
|
-
const hasASpace = attrValue.indexOf(' ');
|
|
593
|
-
var selector = '';
|
|
594
|
-
|
|
595
|
-
if((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace == -1){
|
|
596
|
-
selector = attrValue;
|
|
597
|
-
}
|
|
598
|
-
else if (!attr && hasASpace == -1){
|
|
599
|
-
selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
600
|
-
}
|
|
601
|
-
else if (!attr && hasASpace > -1){
|
|
602
|
-
selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
603
|
-
}
|
|
604
|
-
else {
|
|
605
|
-
selector = '[' + attr + '="' + attrValue + '"]';
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
browser.waitForElementPresent(selector, 5000);
|
|
609
|
-
return browser.setValue(selector, txtValue);
|
|
610
|
-
|
|
611
|
-
});
|
|
612
|
-
|
|
613
|
-
/**
|
|
614
|
-
* Fill input type text with empty value by its Label.
|
|
615
|
-
*
|
|
616
|
-
* Example: When I fill in "Username" with:
|
|
617
|
-
*
|
|
618
|
-
*/
|
|
619
|
-
When(/^(I |we )*fill in "([^"]*)?" with:$/, function (pronounCase, field) {
|
|
620
|
-
// Wait for dynamic content to render (AJAX/JS)
|
|
621
|
-
browser.pause(500);
|
|
622
|
-
const elementField = browser.element.findByText(field, { exact: true });
|
|
623
|
-
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
624
|
-
// Wait for the input element to be present (handles dynamically generated form fields)
|
|
625
|
-
browser.waitForElementPresent('#' + eleAttribute.value, 5000);
|
|
626
|
-
return browser.setValue('#' + eleAttribute.value, '');
|
|
627
|
-
});
|
|
360
|
+
// ---------------------------------------------------------------------------
|
|
361
|
+
// When I fill in "Username" with: (empty)
|
|
362
|
+
// Captures: (pronounCase, field) = 2
|
|
363
|
+
// ---------------------------------------------------------------------------
|
|
364
|
+
When(/^(I |we )*fill in "([^"]*)?" with:$/, async function (pronounCase, field) {
|
|
365
|
+
await fillField(this.page, field, '');
|
|
628
366
|
});
|
|
629
367
|
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
* Example: And I fill in "Your full name" with: by its "placeholder" attribute
|
|
637
|
-
*
|
|
638
|
-
*/
|
|
639
|
-
When(/^(I |we )*fill in "([^"]*)?" with: by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, attrValue , itsCase, attr, attrCase) {
|
|
640
|
-
|
|
641
|
-
const hasASpace = attrValue.indexOf(' ');
|
|
642
|
-
var selector = '';
|
|
643
|
-
|
|
644
|
-
if((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace == -1){
|
|
645
|
-
selector = attrValue;
|
|
646
|
-
}
|
|
647
|
-
else if (!attr && hasASpace == -1){
|
|
648
|
-
selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
649
|
-
}
|
|
650
|
-
else if (!attr && hasASpace > -1){
|
|
651
|
-
selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
652
|
-
}
|
|
653
|
-
else {
|
|
654
|
-
selector = '[' + attr + '="' + attrValue + '"]';
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
browser.waitForElementPresent(selector, 5000);
|
|
658
|
-
return browser.setValue(selector, '');
|
|
659
|
-
});
|
|
660
|
-
|
|
661
|
-
/**
|
|
662
|
-
* Fill in value for input type text by its Label.
|
|
663
|
-
*
|
|
664
|
-
* Example #1: When I fill in "jon-smith" for "Username"
|
|
665
|
-
* Example #2: When we fill in "Testing" for "Organization options"
|
|
666
|
-
*
|
|
667
|
-
*/
|
|
668
|
-
When(/^(I |we )*fill in "([^"]*)?" for "([^"]*)?"$/, function (pronounCase, value, field) {
|
|
669
|
-
// Wait for dynamic content to render (AJAX/JS)
|
|
670
|
-
browser.pause(500);
|
|
671
|
-
const elementField = browser.element.findByText(field, { exact: true });
|
|
672
|
-
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
673
|
-
// Wait for the input element to be present (handles dynamically generated form fields)
|
|
674
|
-
browser.waitForElementPresent('#' + eleAttribute.value, 5000);
|
|
675
|
-
return browser.setValue('#' + eleAttribute.value, value);
|
|
676
|
-
});
|
|
368
|
+
// ---------------------------------------------------------------------------
|
|
369
|
+
// When I fill in "uname" with: by attr (empty by attr)
|
|
370
|
+
// Captures: (pronounCase, attrValue, itsCase, attr, attrWord) = 5
|
|
371
|
+
// ---------------------------------------------------------------------------
|
|
372
|
+
When(/^(I |we )*fill in "([^"]*)?" with: by( its)*(?: "([^"]*)?")* (attribute|attr)$/, async function (pronounCase, attrValue, itsCase, attr, attrWord) {
|
|
373
|
+
await this.page.locator(buildSelector(attrValue, attr)).first().fill('');
|
|
677
374
|
});
|
|
678
375
|
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
* Example #4: And I fill in "John Smith" for "Your full name" by its "placeholder" attribute
|
|
686
|
-
*
|
|
687
|
-
*/
|
|
688
|
-
When(/^(I |we )*fill in "([^"]*)?" for "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, txtValue, attrValue, itsCase, attr, attrCase) {
|
|
689
|
-
|
|
690
|
-
const hasASpace = attrValue.indexOf(' ');
|
|
691
|
-
var selector = '';
|
|
692
|
-
|
|
693
|
-
if((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace == -1){
|
|
694
|
-
selector = attrValue;
|
|
695
|
-
}
|
|
696
|
-
else if (!attr && hasASpace == -1){
|
|
697
|
-
selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
698
|
-
}
|
|
699
|
-
else if (!attr && hasASpace > -1){
|
|
700
|
-
selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
701
|
-
}
|
|
702
|
-
else {
|
|
703
|
-
selector = '[' + attr + '="' + attrValue + '"]';
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
// Actively wait for dynamically generated element by polling the DOM
|
|
707
|
-
return browser.executeAsync(function(sel, value, done) {
|
|
708
|
-
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds
|
|
709
|
-
var attempts = 0;
|
|
710
|
-
|
|
711
|
-
var checkElement = setInterval(function() {
|
|
712
|
-
var element = document.querySelector(sel);
|
|
713
|
-
attempts++;
|
|
714
|
-
|
|
715
|
-
if (element) {
|
|
716
|
-
clearInterval(checkElement);
|
|
717
|
-
element.value = value;
|
|
718
|
-
done({ found: true });
|
|
719
|
-
} else if (attempts >= maxAttempts) {
|
|
720
|
-
clearInterval(checkElement);
|
|
721
|
-
done({ found: false });
|
|
722
|
-
}
|
|
723
|
-
}, 500);
|
|
724
|
-
}, [selector, txtValue], function(result) {
|
|
725
|
-
if (!result || !result.value || !result.value.found) {
|
|
726
|
-
browser.assert.fail('Element "' + selector + '" was not found in dynamically generated content');
|
|
727
|
-
}
|
|
728
|
-
});
|
|
729
|
-
|
|
376
|
+
// ---------------------------------------------------------------------------
|
|
377
|
+
// When I fill in "John Smith" for "Username"
|
|
378
|
+
// Captures: (pronounCase, value, field) = 3
|
|
379
|
+
// ---------------------------------------------------------------------------
|
|
380
|
+
When(/^(I |we )*fill in "([^"]*)?" for "([^"]*)?"$/, async function (pronounCase, value, field) {
|
|
381
|
+
await fillField(this.page, field, value);
|
|
730
382
|
});
|
|
731
383
|
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
*/
|
|
739
|
-
|
|
740
|
-
When(/^(I |we )*fill in( the)* following:$/, function (pronounCase, theCase, table) {
|
|
741
|
-
|
|
742
|
-
// Wait for dynamic content to render (AJAX/JS)
|
|
743
|
-
browser.pause(500);
|
|
744
|
-
|
|
745
|
-
var elementField = browser.element.findByText(table.rawTable[0][0], { exact: true });
|
|
746
|
-
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
747
|
-
// Wait for the input element to be present (handles dynamically generated form fields)
|
|
748
|
-
browser.waitForElementPresent('#' + eleAttribute.value, 5000);
|
|
749
|
-
browser.setValue('#' + eleAttribute.value, table.rawTable[0][1]);
|
|
750
|
-
});
|
|
751
|
-
|
|
752
|
-
table.rows().forEach(row => {
|
|
753
|
-
|
|
754
|
-
elementField = browser.element.findByText(row[0], { exact: true });
|
|
755
|
-
browser.getAttribute(elementField, 'for', function (eleAttribute2) {
|
|
756
|
-
// Wait for the input element to be present (handles dynamically generated form fields)
|
|
757
|
-
browser.waitForElementPresent('#' + eleAttribute2.value, 5000);
|
|
758
|
-
browser.setValue('#' + eleAttribute2.value, row[1]);
|
|
759
|
-
});
|
|
760
|
-
});
|
|
384
|
+
// ---------------------------------------------------------------------------
|
|
385
|
+
// When I fill in "John Smith" for "uname" by attr
|
|
386
|
+
// Captures: (pronounCase, txtValue, attrValue, itsCase, attr, attrWord) = 6
|
|
387
|
+
// ---------------------------------------------------------------------------
|
|
388
|
+
When(/^(I |we )*fill in "([^"]*)?" for "([^"]*)?" by( its)*(?: "([^"]*)?")* (attribute|attr)$/, async function (pronounCase, txtValue, attrValue, itsCase, attr, attrWord) {
|
|
389
|
+
await this.page.locator(buildSelector(attrValue, attr)).first().fill(txtValue);
|
|
761
390
|
});
|
|
762
391
|
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
*
|
|
771
|
-
* Example #2: When I fill in the following: by its "placeholder" attribute
|
|
772
|
-
* | Your full name | John Smith |
|
|
773
|
-
* | Your Password | 1234 |
|
|
774
|
-
*/
|
|
775
|
-
When(/^(I |we )*fill in( the)* following: by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, theCase, itsCase, attr, attrCase, table) {
|
|
776
|
-
|
|
777
|
-
var hasASpace = table.rawTable[0][0].indexOf(' ');
|
|
778
|
-
var selector = '';
|
|
779
|
-
|
|
780
|
-
if((table.rawTable[0][0].startsWith('#') || table.rawTable[0][0].startsWith('.')) && hasASpace == -1){
|
|
781
|
-
selector = table.rawTable[0][0];
|
|
392
|
+
// ---------------------------------------------------------------------------
|
|
393
|
+
// When I fill in the following: (table by label)
|
|
394
|
+
// Captures: (pronounCase, theCase) = 2
|
|
395
|
+
// ---------------------------------------------------------------------------
|
|
396
|
+
When(/^(I |we )*fill in( the)* following:$/, async function (pronounCase, theCase, table) {
|
|
397
|
+
for (const [field, value] of table.raw()) {
|
|
398
|
+
await fillField(this.page, field, value);
|
|
782
399
|
}
|
|
783
|
-
else if (!attr && hasASpace == -1){
|
|
784
|
-
selector = table.rawTable[0][0] + ',#' + table.rawTable[0][0] + ',.' + table.rawTable[0][0] + ',[name=' + table.rawTable[0][0] + "]," + '[value="' + table.rawTable[0][0] + '"],[placeholder="' + table.rawTable[0][0] + '"]';
|
|
785
|
-
}
|
|
786
|
-
else if (!attr && hasASpace > -1){
|
|
787
|
-
selector ='[value="' + table.rawTable[0][0] + '"],[placeholder="' + table.rawTable[0][0] + '"]';
|
|
788
|
-
}
|
|
789
|
-
else {
|
|
790
|
-
selector = '[' + attr + '="' + table.rawTable[0][0] + '"]';
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
browser.waitForElementPresent(selector, 5000);
|
|
794
|
-
browser.setValue(selector, table.rawTable[0][1]);
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
table.rows().forEach(row => {
|
|
798
|
-
|
|
799
|
-
hasASpace = row[0].indexOf(' ');
|
|
800
|
-
var selector = '';
|
|
801
|
-
|
|
802
|
-
if((row[0].startsWith('#') || row[0].startsWith('.')) && hasASpace == -1){
|
|
803
|
-
selector = row[0];
|
|
804
|
-
}
|
|
805
|
-
else if (!attr && hasASpace == -1){
|
|
806
|
-
|
|
807
|
-
selector = row[0] + ',#' + row[0] + ',.' + row[0] + ',[name=' + row[0] + "]," + '[value="' + row[0] + '"],[placeholder="' + row[0] + '"]';
|
|
808
|
-
}
|
|
809
|
-
else if (!attr && hasASpace > -1){
|
|
810
|
-
selector ='[value="' + row[0] + '"],[placeholder="' + row[0] + '"]';
|
|
811
|
-
}
|
|
812
|
-
else {
|
|
813
|
-
selector = '[' + attr + '="' + row[0] + '"]';
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
browser.waitForElementPresent(selector, 5000);
|
|
817
|
-
browser.setValue(selector, row[1]);
|
|
818
|
-
|
|
819
|
-
});
|
|
820
400
|
});
|
|
821
401
|
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
*
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
*/
|
|
830
|
-
When(/^(I |we )*select "([^"]*)?" from "([^"]*)?"$/, function (pronounCase, option, selectList) {
|
|
831
|
-
|
|
832
|
-
const hasASpace = selectList.indexOf(' ');
|
|
833
|
-
|
|
834
|
-
let selector = '';
|
|
835
|
-
if((selectList.startsWith('#') || selectList.startsWith('.'))){
|
|
836
|
-
selector = selectList;
|
|
837
|
-
}
|
|
838
|
-
else if (hasASpace == -1){
|
|
839
|
-
selector = '[name="' + selectList + '"],[id="' + selectList + '"],[class="' + selectList + '"]';
|
|
840
|
-
}
|
|
841
|
-
else {
|
|
842
|
-
selector = browser.element.findByText(selectList, { exact: true });
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
// Wait for select element to be present
|
|
846
|
-
if (typeof selector === 'string') {
|
|
847
|
-
browser.waitForElementPresent(selector, 5000);
|
|
402
|
+
// ---------------------------------------------------------------------------
|
|
403
|
+
// When I fill in the following: by attr (table by attribute)
|
|
404
|
+
// Captures: (pronounCase, theCase, itsCase, attr, attrWord) = 5
|
|
405
|
+
// ---------------------------------------------------------------------------
|
|
406
|
+
When(/^(I |we )*fill in( the)* following: by( its)*(?: "([^"]*)?")* (attribute|attr)$/, async function (pronounCase, theCase, itsCase, attr, attrWord, table) {
|
|
407
|
+
for (const [attrValue, value] of table.raw()) {
|
|
408
|
+
await this.page.locator(buildSelector(attrValue, attr)).first().fill(value);
|
|
848
409
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
let optionValue = '';
|
|
852
|
-
const result = option.toLowerCase();
|
|
410
|
+
});
|
|
853
411
|
|
|
854
|
-
|
|
855
|
-
|
|
412
|
+
// ---------------------------------------------------------------------------
|
|
413
|
+
// When I select "Mercedes" from "Cars"
|
|
414
|
+
// Captures: (pronounCase, option, selectList) = 3
|
|
415
|
+
// ---------------------------------------------------------------------------
|
|
416
|
+
When(/^(I |we )*select "([^"]*)?" from "([^"]*)?"$/, async function (pronounCase, option, selectList) {
|
|
417
|
+
let loc;
|
|
418
|
+
if (selectList.startsWith('#') || selectList.startsWith('.')) {
|
|
419
|
+
loc = this.page.locator(selectList);
|
|
420
|
+
} else if (!selectList.includes(' ')) {
|
|
421
|
+
loc = this.page.locator(`[name="${selectList}"], #${selectList}`).first();
|
|
422
|
+
} else {
|
|
423
|
+
loc = this.page.getByLabel(selectList, { exact: true });
|
|
856
424
|
}
|
|
857
|
-
|
|
858
|
-
|
|
425
|
+
try {
|
|
426
|
+
await loc.selectOption({ label: option }, { timeout: 3000 });
|
|
427
|
+
} catch {
|
|
428
|
+
await loc.selectOption(option);
|
|
859
429
|
}
|
|
430
|
+
});
|
|
860
431
|
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
*
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds
|
|
875
|
-
var attempts = 0;
|
|
876
|
-
|
|
877
|
-
var checkCheckbox = setInterval(function() {
|
|
878
|
-
var element = null;
|
|
879
|
-
|
|
880
|
-
// Try to find checkbox by selector (e.g., #newsletter, .checkbox)
|
|
881
|
-
if (checkboxItem.startsWith('#') || checkboxItem.startsWith('.')) {
|
|
882
|
-
element = document.querySelector(checkboxItem);
|
|
883
|
-
} else {
|
|
884
|
-
// Try to find by label text
|
|
885
|
-
var labels = document.querySelectorAll('label');
|
|
886
|
-
for (var i = 0; i < labels.length; i++) {
|
|
887
|
-
var labelText = (labels[i].textContent || labels[i].innerText || '').trim();
|
|
888
|
-
if (labelText === checkboxItem) {
|
|
889
|
-
var forAttr = labels[i].getAttribute('for');
|
|
890
|
-
if (forAttr) {
|
|
891
|
-
element = document.getElementById(forAttr);
|
|
892
|
-
break;
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
attempts++;
|
|
899
|
-
|
|
900
|
-
if (element) {
|
|
901
|
-
clearInterval(checkCheckbox);
|
|
902
|
-
element.checked = true;
|
|
903
|
-
// Trigger change event
|
|
904
|
-
var event = new Event('change', { bubbles: true });
|
|
905
|
-
element.dispatchEvent(event);
|
|
906
|
-
done({ found: true });
|
|
907
|
-
} else if (attempts >= maxAttempts) {
|
|
908
|
-
clearInterval(checkCheckbox);
|
|
909
|
-
done({ found: false });
|
|
910
|
-
}
|
|
911
|
-
}, 500);
|
|
912
|
-
}, [item], function(result) {
|
|
913
|
-
if (!result || !result.value || !result.value.found) {
|
|
914
|
-
browser.assert.fail('Checkbox "' + item + '" was not found in dynamically generated content');
|
|
432
|
+
// ---------------------------------------------------------------------------
|
|
433
|
+
// When I check "Remember me"
|
|
434
|
+
// Captures: (pronounCase, item) = 2
|
|
435
|
+
// ---------------------------------------------------------------------------
|
|
436
|
+
When(/^(I |we )*check "([^"]*)?"$/, async function (pronounCase, item) {
|
|
437
|
+
if (item.startsWith('#') || item.startsWith('.')) {
|
|
438
|
+
await this.page.locator(item).check();
|
|
439
|
+
} else {
|
|
440
|
+
const byLabel = this.page.getByLabel(item, { exact: true });
|
|
441
|
+
if (await byLabel.count() > 0) {
|
|
442
|
+
await byLabel.check();
|
|
443
|
+
} else {
|
|
444
|
+
await this.page.locator(`input[type="checkbox"][id="${item}"], input[type="checkbox"][name="${item}"], input[type="checkbox"][value="${item}"]`).first().check();
|
|
915
445
|
}
|
|
916
|
-
}
|
|
446
|
+
}
|
|
917
447
|
});
|
|
918
448
|
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
var checkCheckbox = setInterval(function() {
|
|
933
|
-
var element = null;
|
|
934
|
-
|
|
935
|
-
// Try to find checkbox by selector (e.g., #newsletter, .checkbox)
|
|
936
|
-
if (checkboxItem.startsWith('#') || checkboxItem.startsWith('.')) {
|
|
937
|
-
element = document.querySelector(checkboxItem);
|
|
938
|
-
} else {
|
|
939
|
-
// Try to find by label text
|
|
940
|
-
var labels = document.querySelectorAll('label');
|
|
941
|
-
for (var i = 0; i < labels.length; i++) {
|
|
942
|
-
var labelText = (labels[i].textContent || labels[i].innerText || '').trim();
|
|
943
|
-
if (labelText === checkboxItem) {
|
|
944
|
-
var forAttr = labels[i].getAttribute('for');
|
|
945
|
-
if (forAttr) {
|
|
946
|
-
element = document.getElementById(forAttr);
|
|
947
|
-
break;
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
attempts++;
|
|
954
|
-
|
|
955
|
-
if (element) {
|
|
956
|
-
clearInterval(checkCheckbox);
|
|
957
|
-
element.checked = false;
|
|
958
|
-
// Trigger change event
|
|
959
|
-
var event = new Event('change', { bubbles: true });
|
|
960
|
-
element.dispatchEvent(event);
|
|
961
|
-
done({ found: true });
|
|
962
|
-
} else if (attempts >= maxAttempts) {
|
|
963
|
-
clearInterval(checkCheckbox);
|
|
964
|
-
done({ found: false });
|
|
965
|
-
}
|
|
966
|
-
}, 500);
|
|
967
|
-
}, [item], function(result) {
|
|
968
|
-
if (!result || !result.value || !result.value.found) {
|
|
969
|
-
browser.assert.fail('Checkbox "' + item + '" was not found in dynamically generated content');
|
|
449
|
+
// ---------------------------------------------------------------------------
|
|
450
|
+
// When I uncheck "Remember me"
|
|
451
|
+
// Captures: (pronounCase, item) = 2
|
|
452
|
+
// ---------------------------------------------------------------------------
|
|
453
|
+
When(/^(I |we )*uncheck "([^"]*)?"$/, async function (pronounCase, item) {
|
|
454
|
+
if (item.startsWith('#') || item.startsWith('.')) {
|
|
455
|
+
await this.page.locator(item).uncheck();
|
|
456
|
+
} else {
|
|
457
|
+
const byLabel = this.page.getByLabel(item, { exact: true });
|
|
458
|
+
if (await byLabel.count() > 0) {
|
|
459
|
+
await byLabel.uncheck();
|
|
460
|
+
} else {
|
|
461
|
+
await this.page.locator(`input[type="checkbox"][id="${item}"], input[type="checkbox"][name="${item}"], input[type="checkbox"][value="${item}"]`).first().uncheck();
|
|
970
462
|
}
|
|
971
|
-
}
|
|
463
|
+
}
|
|
972
464
|
});
|
|
973
465
|
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
var attempts = 0;
|
|
988
|
-
|
|
989
|
-
var selectRadio = setInterval(function() {
|
|
990
|
-
var element = null;
|
|
991
|
-
|
|
992
|
-
// Try to find radio button by selector (e.g., #gender-male, .radio-option)
|
|
993
|
-
if (radioItem.startsWith('#') || radioItem.startsWith('.')) {
|
|
994
|
-
var foundElement = document.querySelector(radioItem);
|
|
995
|
-
if (foundElement && foundElement.type === 'radio') {
|
|
996
|
-
element = foundElement;
|
|
997
|
-
}
|
|
998
|
-
} else {
|
|
999
|
-
// Try to find by value attribute first
|
|
1000
|
-
var radioButtons = document.querySelectorAll('input[type="radio"]');
|
|
1001
|
-
for (var i = 0; i < radioButtons.length; i++) {
|
|
1002
|
-
if (radioButtons[i].value === radioItem) {
|
|
1003
|
-
element = radioButtons[i];
|
|
1004
|
-
break;
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
// If not found by value, try to find by label text
|
|
1009
|
-
if (!element) {
|
|
1010
|
-
var labels = document.querySelectorAll('label');
|
|
1011
|
-
for (var j = 0; j < labels.length; j++) {
|
|
1012
|
-
var labelText = (labels[j].textContent || labels[j].innerText || '').trim();
|
|
1013
|
-
if (labelText === radioItem) {
|
|
1014
|
-
var forAttr = labels[j].getAttribute('for');
|
|
1015
|
-
if (forAttr) {
|
|
1016
|
-
var radioElement = document.getElementById(forAttr);
|
|
1017
|
-
if (radioElement && radioElement.type === 'radio') {
|
|
1018
|
-
element = radioElement;
|
|
1019
|
-
break;
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
// Also check if label wraps the radio input
|
|
1023
|
-
var radioInput = labels[j].querySelector('input[type="radio"]');
|
|
1024
|
-
if (radioInput) {
|
|
1025
|
-
element = radioInput;
|
|
1026
|
-
break;
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
attempts++;
|
|
1034
|
-
|
|
1035
|
-
if (element) {
|
|
1036
|
-
clearInterval(selectRadio);
|
|
1037
|
-
element.checked = true;
|
|
1038
|
-
// Trigger change and click events for better compatibility
|
|
1039
|
-
var changeEvent = new Event('change', { bubbles: true });
|
|
1040
|
-
var clickEvent = new Event('click', { bubbles: true });
|
|
1041
|
-
element.dispatchEvent(clickEvent);
|
|
1042
|
-
element.dispatchEvent(changeEvent);
|
|
1043
|
-
done({ found: true, value: element.value, name: element.name });
|
|
1044
|
-
} else if (attempts >= maxAttempts) {
|
|
1045
|
-
clearInterval(selectRadio);
|
|
1046
|
-
done({ found: false });
|
|
1047
|
-
}
|
|
1048
|
-
}, 500);
|
|
1049
|
-
}, [item], function(result) {
|
|
1050
|
-
if (!result || !result.value || !result.value.found) {
|
|
1051
|
-
browser.assert.fail('Radio button "' + item + '" was not found in dynamically generated content');
|
|
466
|
+
// ---------------------------------------------------------------------------
|
|
467
|
+
// When I select radio button "Male"
|
|
468
|
+
// Captures: (pronounCase, item) = 2
|
|
469
|
+
// ---------------------------------------------------------------------------
|
|
470
|
+
When(/^(I |we )*select radio button "([^"]*)?"$/, async function (pronounCase, item) {
|
|
471
|
+
if (item.startsWith('#') || item.startsWith('.')) {
|
|
472
|
+
await this.page.locator(item).check();
|
|
473
|
+
} else {
|
|
474
|
+
const byValue = this.page.locator(`input[type="radio"][value="${item}"]`);
|
|
475
|
+
if (await byValue.count() > 0) {
|
|
476
|
+
await byValue.first().check();
|
|
477
|
+
} else {
|
|
478
|
+
await this.page.getByLabel(item, { exact: true }).check();
|
|
1052
479
|
}
|
|
1053
|
-
}
|
|
480
|
+
}
|
|
1054
481
|
});
|
|
1055
482
|
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
*
|
|
1061
|
-
|
|
1062
|
-
* Example #4: And should be on the homepage
|
|
1063
|
-
* Example #5: Then should be on homepage
|
|
1064
|
-
* Example #6: And we should be on homepage
|
|
1065
|
-
* Example #7: Then should be on frontpage
|
|
1066
|
-
* Example #8: And we should be on the homepage
|
|
1067
|
-
* Example #9: Then I should not be on homepage
|
|
1068
|
-
* Example #10: And I should not be on the homepage
|
|
1069
|
-
* Example #11: Then I should not be on frontpage
|
|
1070
|
-
* Example #12: Then we should not be on homepage
|
|
1071
|
-
* Example #13: Then should not be on the homepage
|
|
1072
|
-
* Example #14: And we should not be on frontpage
|
|
1073
|
-
* Example #15: And we should not be on the homepage
|
|
1074
|
-
*
|
|
1075
|
-
*/
|
|
1076
|
-
Then(/^(I |we )*should( not)* be on( the)* (homepage|frontpage)$/, function (pronounCase, notCase, theCase, pageCase) {
|
|
483
|
+
// ---------------------------------------------------------------------------
|
|
484
|
+
// Then I should be on homepage / frontpage
|
|
485
|
+
// Captures: (pronounCase, notCase, theCase, pageCase) = 4
|
|
486
|
+
// ---------------------------------------------------------------------------
|
|
487
|
+
Then(/^(I |we )*should( not)* be on( the)* (homepage|frontpage)$/, async function (pronounCase, notCase, theCase, pageCase) {
|
|
488
|
+
const currentUrl = this.page.url();
|
|
1077
489
|
if (notCase) {
|
|
1078
|
-
|
|
490
|
+
assert.ok(currentUrl !== this.launchUrl && !currentUrl.startsWith(this.launchUrl + '/'),
|
|
491
|
+
`Should NOT be on homepage but current URL is: ${currentUrl}`);
|
|
1079
492
|
} else {
|
|
1080
|
-
|
|
493
|
+
assert.ok(currentUrl.startsWith(this.launchUrl),
|
|
494
|
+
`Should be on homepage but current URL is: ${currentUrl}`);
|
|
1081
495
|
}
|
|
1082
496
|
});
|
|
1083
497
|
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
*
|
|
1089
|
-
|
|
1090
|
-
* Example #4: Then we should be on the "/" page
|
|
1091
|
-
* Example #5: And we should be on "/user/login"
|
|
1092
|
-
* Example #6: And we should be on "https://google.com"
|
|
1093
|
-
* Example #7: Then should be on the "/user/reset" page
|
|
1094
|
-
* Example #8: And we should be on "https://x.com"
|
|
1095
|
-
* Example #9: Then I should not be on "/"
|
|
1096
|
-
* Example #10: And I should not be on "/user/login"
|
|
1097
|
-
* Example #11: And I should not be on "https://un.org"
|
|
1098
|
-
* Example #12: Then we should not be on the "/" page
|
|
1099
|
-
* Example #13: And we should not be on "/user/login"
|
|
1100
|
-
* Example #14: Then we should not be on "https://google.com"
|
|
1101
|
-
* Example #15: And should not be on "/user/reset"
|
|
1102
|
-
* Example #16: And we should not be on the "https://x.com" page
|
|
1103
|
-
*
|
|
1104
|
-
*/
|
|
1105
|
-
Then(/^(I |we )*should( not)* be on( the)* "([^"]*)?"( page)*$/, function (pronounCase, notCase, theCase, url, pageCase) {
|
|
498
|
+
// ---------------------------------------------------------------------------
|
|
499
|
+
// Then I should be on "/user/login"
|
|
500
|
+
// Captures: (pronounCase, notCase, theCase, url, pageCase) = 5
|
|
501
|
+
// ---------------------------------------------------------------------------
|
|
502
|
+
Then(/^(I |we )*should( not)* be on( the)* "([^"]*)?"( page)*$/, async function (pronounCase, notCase, theCase, url, pageCase) {
|
|
503
|
+
const currentUrl = this.page.url();
|
|
1106
504
|
if (notCase) {
|
|
1107
|
-
|
|
505
|
+
assert.ok(!currentUrl.includes(url), `URL should NOT contain "${url}" but it is: ${currentUrl}`);
|
|
1108
506
|
} else {
|
|
1109
|
-
|
|
507
|
+
assert.ok(currentUrl.includes(url), `URL should contain "${url}" but it is: ${currentUrl}`);
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
// ---------------------------------------------------------------------------
|
|
512
|
+
// Then the "Login" link should contain "/log-in"
|
|
513
|
+
// Captures: (theCase, element, url) = 3
|
|
514
|
+
// ---------------------------------------------------------------------------
|
|
515
|
+
Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?"$/, async function (theCase, element, url) {
|
|
516
|
+
const loc = this.page.getByText(element, { exact: true }).first();
|
|
517
|
+
await loc.waitFor({ timeout: 5000 });
|
|
518
|
+
const href = await loc.evaluate(el => el.href || el.getAttribute('href') || '');
|
|
519
|
+
assert.ok(href.includes(url), `Expected link "${element}" href to contain "${url}" but got "${href}"`);
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
// ---------------------------------------------------------------------------
|
|
523
|
+
// Then the "#about-us-id" link should contain "about" by attr
|
|
524
|
+
// Captures: (theCase, attrValue, url, itsCase, attr, attrWord) = 6
|
|
525
|
+
// ---------------------------------------------------------------------------
|
|
526
|
+
Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?" by( its)*(?: "([^"]*)?")* (attribute|attr)$/, async function (theCase, attrValue, url, itsCase, attr, attrWord) {
|
|
527
|
+
const loc = this.page.locator(buildSelector(attrValue, attr)).first();
|
|
528
|
+
await loc.waitFor({ timeout: 5000 });
|
|
529
|
+
const href = await loc.evaluate(el => el.href || el.getAttribute('href') || '');
|
|
530
|
+
assert.ok(href.includes(url), `Expected element href to contain "${url}" but got "${href}"`);
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
// ---------------------------------------------------------------------------
|
|
534
|
+
// Then the response should contain "text"
|
|
535
|
+
// Captures: (theCase, notCase, expectedText) = 3
|
|
536
|
+
// ---------------------------------------------------------------------------
|
|
537
|
+
Then(/^(the )*response should( not)* contain "([^"]*)?"$/, async function (theCase, notCase, expectedText) {
|
|
538
|
+
const text = await this.page.locator('html').textContent() || '';
|
|
539
|
+
if (notCase) {
|
|
540
|
+
assert.ok(!text.includes(expectedText), `Response should NOT contain "${expectedText}" but it does.`);
|
|
541
|
+
} else {
|
|
542
|
+
assert.ok(text.includes(expectedText), `Response should contain "${expectedText}" but it does not.`);
|
|
1110
543
|
}
|
|
1111
544
|
});
|
|
1112
545
|
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
*
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
});
|
|
1127
|
-
|
|
1128
|
-
/**
|
|
1129
|
-
* Verify, that the current link contains the specified URL, found by its attributes.
|
|
1130
|
-
*
|
|
1131
|
-
* Example #1: Then the "#about-us-id" link should contain "about" by attr
|
|
1132
|
-
* Example #2: And the "aboutUs" link should contain "about" by its "class" attribute
|
|
1133
|
-
* Example #3: And the ".contactUs" link should contain "/contact-" by attr
|
|
1134
|
-
*
|
|
1135
|
-
*/
|
|
1136
|
-
Then(/^(the )*"([^"]*)?" link should contain "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, function (theCase, attrValue, url, itsCase, attr, attrCase) {
|
|
1137
|
-
|
|
1138
|
-
// Wait for dynamic content to render (AJAX/JS)
|
|
1139
|
-
browser.pause(500);
|
|
1140
|
-
|
|
1141
|
-
const hasASpace = attrValue.indexOf(' ');
|
|
1142
|
-
var selector = '';
|
|
1143
|
-
|
|
1144
|
-
if((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace == -1){
|
|
1145
|
-
selector = attrValue;
|
|
1146
|
-
}
|
|
1147
|
-
else if (!attr && hasASpace == -1){
|
|
1148
|
-
selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"],' + '[title="' + attrValue + '"]';
|
|
1149
|
-
}
|
|
1150
|
-
else if (!attr && hasASpace > -1){
|
|
1151
|
-
selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
1152
|
-
}
|
|
1153
|
-
else {
|
|
1154
|
-
selector = '[' + attr + '="' + attrValue + '"]';
|
|
546
|
+
// ---------------------------------------------------------------------------
|
|
547
|
+
// Then I should see "John Smith" in the "Username" element
|
|
548
|
+
// Captures: (pronounCase, notCase, expectedText, theCase, element) = 5
|
|
549
|
+
// ---------------------------------------------------------------------------
|
|
550
|
+
Then(/^(I |we )*should( not)* see "([^"]*)?" in( the)* "([^"]*)?" element$/, async function (pronounCase, notCase, expectedText, theCase, element) {
|
|
551
|
+
const forAttr = await this.page.getByText(element, { exact: true }).getAttribute('for').catch(() => null);
|
|
552
|
+
const loc = this.page.locator(forAttr ? '#' + forAttr : element).first();
|
|
553
|
+
await loc.waitFor({ timeout: 5000 });
|
|
554
|
+
const content = await getLocatorText(loc);
|
|
555
|
+
if (notCase) {
|
|
556
|
+
assert.ok(!content.includes(expectedText), `Element should NOT contain "${expectedText}" but it does.`);
|
|
557
|
+
} else {
|
|
558
|
+
assert.ok(content.includes(expectedText), `Element should contain "${expectedText}" but it does not.`);
|
|
1155
559
|
}
|
|
1156
|
-
|
|
1157
|
-
// Wait for link to be present (handles dynamically generated links)
|
|
1158
|
-
browser.waitForElementPresent(selector, 5000);
|
|
1159
|
-
return browser.assert.attributeContains(selector, 'href', url);
|
|
1160
|
-
});
|
|
1161
|
-
|
|
1162
|
-
/**
|
|
1163
|
-
* Checks, that HTML response contains or does not contain specific text.
|
|
1164
|
-
*
|
|
1165
|
-
* Example #1: Then the response should contain "Welcome visitor, How can I help you?"
|
|
1166
|
-
* Example #2: Then the response should not contain "Welcome visitor, How can I help you?"
|
|
1167
|
-
*
|
|
1168
|
-
*/
|
|
1169
|
-
Then(/^(the )*response should( not)* contain "([^"]*)?"$/, function (theCase, notCase, expectedText) {
|
|
1170
|
-
return this.shouldSee = function (browser) {
|
|
1171
|
-
if (notCase) {
|
|
1172
|
-
browser.assert.not.textContains("html", expectedText);
|
|
1173
|
-
} else {
|
|
1174
|
-
browser.assert.textContains("html", expectedText);
|
|
1175
|
-
}
|
|
1176
|
-
};
|
|
1177
|
-
});
|
|
1178
|
-
|
|
1179
|
-
/**
|
|
1180
|
-
* Assert, that input text contains or does not contain a specific value by its label.
|
|
1181
|
-
*
|
|
1182
|
-
* Example #1: Then I should see "John Smith" in the "Username" element
|
|
1183
|
-
* Example #2: Then I should not see "Joe Smith" in the "Username" element
|
|
1184
|
-
*
|
|
1185
|
-
*/
|
|
1186
|
-
Then(/^(I |we )*should( not)* see "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, notCase, expectedText, theCase, element) {
|
|
1187
|
-
// Wait for dynamic content to load
|
|
1188
|
-
browser.pause(500);
|
|
1189
|
-
|
|
1190
|
-
const elementField = browser.element.findByText(element, { exact: true });
|
|
1191
|
-
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
1192
|
-
// Wait for the element to be present (handles dynamically generated elements)
|
|
1193
|
-
browser.waitForElementPresent('#' + eleAttribute.value, 5000);
|
|
1194
|
-
|
|
1195
|
-
return this.shouldSee = function (browser) {
|
|
1196
|
-
// Check dynamically rendered content in the element
|
|
1197
|
-
browser.execute(function(selector, text) {
|
|
1198
|
-
const elem = document.querySelector(selector);
|
|
1199
|
-
if (!elem) return null;
|
|
1200
|
-
const content = elem.textContent || elem.innerText || elem.value || '';
|
|
1201
|
-
return content.includes(text);
|
|
1202
|
-
}, ['#' + eleAttribute.value, expectedText], function(result) {
|
|
1203
|
-
if (result.value === null) {
|
|
1204
|
-
browser.assert.fail(`Element with ID "${eleAttribute.value}" not found`);
|
|
1205
|
-
} else if (notCase) {
|
|
1206
|
-
if (result.value) {
|
|
1207
|
-
browser.assert.fail(`Text "${expectedText}" should not be in element`);
|
|
1208
|
-
}
|
|
1209
|
-
} else {
|
|
1210
|
-
if (!result.value) {
|
|
1211
|
-
browser.assert.fail(`Text "${expectedText}" should be in element`);
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
});
|
|
1215
|
-
|
|
1216
|
-
if (notCase) {
|
|
1217
|
-
browser.assert.not.textContains('#' + eleAttribute.value, expectedText);
|
|
1218
|
-
} else {
|
|
1219
|
-
browser.assert.textContains('#' + eleAttribute.value, expectedText);
|
|
1220
|
-
}
|
|
1221
|
-
};
|
|
1222
|
-
});
|
|
1223
560
|
});
|
|
1224
561
|
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
var selector = '';
|
|
1239
|
-
if((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace == -1){
|
|
1240
|
-
selector = attrValue;
|
|
1241
|
-
}
|
|
1242
|
-
else if (!attr && hasASpace == -1){
|
|
1243
|
-
selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
1244
|
-
}
|
|
1245
|
-
else if (!attr && hasASpace > -1){
|
|
1246
|
-
selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
1247
|
-
}
|
|
1248
|
-
else {
|
|
1249
|
-
selector = '[' + attr + '="' + attrValue + '"]';
|
|
562
|
+
// ---------------------------------------------------------------------------
|
|
563
|
+
// Then I should see "John Smith" in the "uname" element by attr
|
|
564
|
+
// Captures: (pronounCase, notCase, expectedText, theCase, attrValue, itsCase, attr, attrWord) = 8
|
|
565
|
+
// ---------------------------------------------------------------------------
|
|
566
|
+
Then(/^(I |we )*should( not)* see "([^"]*)?" in( the)* "([^"]*)?" element by( its)*(?: "([^"]*)?")* (attribute|attr)$/, async function (pronounCase, notCase, expectedText, theCase, attrValue, itsCase, attr, attrWord) {
|
|
567
|
+
const loc = this.page.locator(buildSelector(attrValue, attr)).first();
|
|
568
|
+
await loc.waitFor({ timeout: 10000 });
|
|
569
|
+
const content = await getLocatorText(loc);
|
|
570
|
+
if (notCase) {
|
|
571
|
+
assert.ok(!content.includes(expectedText), `Element should NOT contain "${expectedText}" but it does.`);
|
|
572
|
+
} else {
|
|
573
|
+
assert.ok(content.includes(expectedText), `Element should contain "${expectedText}" but it does not.`);
|
|
1250
574
|
}
|
|
575
|
+
});
|
|
1251
576
|
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
} else if (attempts >= maxAttempts) {
|
|
1266
|
-
clearInterval(checkElement);
|
|
1267
|
-
done({ found: false, containsText: false, actualContent: null });
|
|
1268
|
-
}
|
|
1269
|
-
}, 500);
|
|
1270
|
-
}, [selector, expectedText, !notCase], function(result) {
|
|
1271
|
-
if (!result || !result.value || !result.value.found) {
|
|
1272
|
-
browser.assert.fail('Element matching selector "' + selector + '" was not found');
|
|
577
|
+
// ---------------------------------------------------------------------------
|
|
578
|
+
// Then I should see a "Username" element
|
|
579
|
+
// Captures: (pronounCase, notCase, aAnCase, element) = 4
|
|
580
|
+
// ---------------------------------------------------------------------------
|
|
581
|
+
Then(/^(I |we )*should( not)* see (a|an) "([^"]*)?" element$/, async function (pronounCase, notCase, aAnCase, element) {
|
|
582
|
+
if (notCase) {
|
|
583
|
+
const text = await this.page.locator('body').textContent() || '';
|
|
584
|
+
assert.ok(!text.includes(element), `Page should NOT contain element text "${element}" but it does.`);
|
|
585
|
+
} else {
|
|
586
|
+
const loc = this.page.getByText(element, { exact: true }).first();
|
|
587
|
+
const forAttr = await loc.getAttribute('for').catch(() => null);
|
|
588
|
+
if (forAttr) {
|
|
589
|
+
await this.page.locator('#' + forAttr).waitFor({ state: 'visible', timeout: 3000 });
|
|
1273
590
|
} else {
|
|
1274
|
-
|
|
1275
|
-
if (result.value.containsText) {
|
|
1276
|
-
browser.assert.fail('Text "' + expectedText + '" should not be in element "' + selector + '" but it is. Content: ' + result.value.actualContent);
|
|
1277
|
-
}
|
|
1278
|
-
} else {
|
|
1279
|
-
if (!result.value.containsText) {
|
|
1280
|
-
browser.assert.fail('Text "' + expectedText + '" should be in element "' + selector + '" but it is not. Content: ' + result.value.actualContent);
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
591
|
+
await loc.waitFor({ state: 'visible', timeout: 3000 });
|
|
1283
592
|
}
|
|
1284
|
-
}
|
|
593
|
+
}
|
|
1285
594
|
});
|
|
1286
595
|
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
596
|
+
// ---------------------------------------------------------------------------
|
|
597
|
+
// Then I should see a "uname" element by attr
|
|
598
|
+
// Captures: (pronounCase, notCase, aAnCase, attrValue, itsCase, attr, attrWord) = 7
|
|
599
|
+
// ---------------------------------------------------------------------------
|
|
600
|
+
Then(/^(I |we )*should( not)* see (a|an) "([^"]*)?" element by( its)*(?: "([^"]*)?")* (attribute|attr)$/, async function (pronounCase, notCase, aAnCase, attrValue, itsCase, attr, attrWord) {
|
|
601
|
+
const loc = this.page.locator(buildSelector(attrValue, attr));
|
|
602
|
+
if (notCase) {
|
|
603
|
+
assert.strictEqual(await loc.count(), 0, `Element should NOT be present but it is.`);
|
|
604
|
+
} else {
|
|
605
|
+
await loc.first().waitFor({ state: 'visible', timeout: 3000 });
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
// ---------------------------------------------------------------------------
|
|
610
|
+
// Then the "body" element should contain "color:white;"
|
|
611
|
+
// Captures: (theCase, selectorRaw, notCase, elementCss) = 4
|
|
612
|
+
// ---------------------------------------------------------------------------
|
|
613
|
+
Then(/^(the )*"([^"]*)?" element should( not)* contain "([^"]*)?"$/, async function (theCase, selectorRaw, notCase, elementCss) {
|
|
614
|
+
const cssClean = elementCss.replace(/;$/, '');
|
|
615
|
+
const colonIdx = cssClean.indexOf(':');
|
|
616
|
+
const cssProperty = cssClean.substring(0, colonIdx).trim();
|
|
617
|
+
const expectedValue = cssClean.substring(colonIdx + 1).trim();
|
|
618
|
+
|
|
619
|
+
const loc = this.page.locator(buildSelector(selectorRaw)).first();
|
|
620
|
+
await loc.waitFor({ timeout: 10000 });
|
|
621
|
+
const matches = await loc.evaluate((el, { prop, expectedVal }) => {
|
|
622
|
+
function colorToRgb(color) {
|
|
623
|
+
const canvas = document.createElement('canvas');
|
|
624
|
+
canvas.width = canvas.height = 1;
|
|
625
|
+
const ctx = canvas.getContext('2d');
|
|
626
|
+
ctx.fillStyle = 'rgb(1, 2, 3)';
|
|
627
|
+
ctx.fillStyle = color.trim();
|
|
628
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
629
|
+
const d = ctx.getImageData(0, 0, 1, 1).data;
|
|
630
|
+
return 'rgb(' + d[0] + ', ' + d[1] + ', ' + d[2] + ')';
|
|
631
|
+
}
|
|
632
|
+
function isValidColor(value) { return colorToRgb(value) !== 'rgb(1, 2, 3)'; }
|
|
633
|
+
function normalizeColorTokens(value) {
|
|
634
|
+
return value.replace(/rgb\([^)]+\)|rgba\([^)]+\)|#[0-9a-fA-F]+|\b[a-zA-Z]+\b/g,
|
|
635
|
+
(token) => isValidColor(token) ? colorToRgb(token) : token);
|
|
636
|
+
}
|
|
637
|
+
function tokenize(value) {
|
|
638
|
+
const tokens = [], regex = /rgb\([^)]+\)|rgba\([^)]+\)|[^\s]+/g;
|
|
639
|
+
let m;
|
|
640
|
+
while ((m = regex.exec(value)) !== null) tokens.push(m[0]);
|
|
641
|
+
return tokens;
|
|
642
|
+
}
|
|
643
|
+
const computed = window.getComputedStyle(el).getPropertyValue(prop).trim();
|
|
644
|
+
return tokenize(normalizeColorTokens(expectedVal.toLowerCase()))
|
|
645
|
+
.every(token => normalizeColorTokens(computed.toLowerCase()).includes(token));
|
|
646
|
+
}, { prop: cssProperty, expectedVal: expectedValue });
|
|
1297
647
|
|
|
1298
648
|
if (notCase) {
|
|
1299
|
-
|
|
649
|
+
assert.ok(!matches, `Element should NOT have CSS "${cssProperty}: ${expectedValue}" but it does.`);
|
|
1300
650
|
} else {
|
|
1301
|
-
|
|
1302
|
-
browser.waitForElementPresent('body', 2000);
|
|
1303
|
-
|
|
1304
|
-
const elementField = browser.element.findByText(element, { exact: true });
|
|
1305
|
-
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
1306
|
-
// Wait for the specific element to be visible (in case it's AJAX-loaded)
|
|
1307
|
-
browser.waitForElementVisible('#' + eleAttribute.value, 3000);
|
|
1308
|
-
return browser.verify.visible('#' + eleAttribute.value);
|
|
1309
|
-
});
|
|
651
|
+
assert.ok(matches, `Element should have CSS "${cssProperty}: ${expectedValue}".`);
|
|
1310
652
|
}
|
|
1311
653
|
});
|
|
1312
654
|
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
*
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
Then(/^(I |we )*should( not)* see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")* (attribute|attr)$/, function (pronounCase, notCase, aAnCase, attrValue, itsCase, attr, attrCase) {
|
|
1323
|
-
|
|
1324
|
-
const hasASpace = attrValue.indexOf(' ');
|
|
1325
|
-
|
|
1326
|
-
var selector = '';
|
|
1327
|
-
if (!attr && hasASpace == -1){
|
|
1328
|
-
selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
|
|
655
|
+
// ---------------------------------------------------------------------------
|
|
656
|
+
// Then the "Username" field should contain "John Smith"
|
|
657
|
+
// Captures: (theCase, field, notCase, expectedText) = 4
|
|
658
|
+
// ---------------------------------------------------------------------------
|
|
659
|
+
Then(/^(the )*"([^"]*)?" field should( not)* contain "([^"]*)?"$/, async function (theCase, field, notCase, expectedText) {
|
|
660
|
+
let selector = field;
|
|
661
|
+
if (!field.startsWith('#') && !field.startsWith('.')) {
|
|
662
|
+
const forAttr = await this.page.getByText(field, { exact: true }).getAttribute('for').catch(() => null);
|
|
663
|
+
if (forAttr) selector = '#' + forAttr;
|
|
1329
664
|
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
665
|
+
const loc = this.page.locator(selector).first();
|
|
666
|
+
await loc.waitFor({ timeout: 5000 });
|
|
667
|
+
const content = await getLocatorText(loc);
|
|
668
|
+
if (notCase) {
|
|
669
|
+
assert.ok(!content.includes(expectedText), `Field should NOT contain "${expectedText}" but it does.`);
|
|
670
|
+
} else {
|
|
671
|
+
assert.ok(content.includes(expectedText), `Field should contain "${expectedText}" but it does not.`);
|
|
1335
672
|
}
|
|
673
|
+
});
|
|
1336
674
|
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
675
|
+
// ---------------------------------------------------------------------------
|
|
676
|
+
// Then the "#PrivacyPolicy" checkbox should be checked
|
|
677
|
+
// Captures: (theCase, checkbox, notCase) = 3
|
|
678
|
+
// ---------------------------------------------------------------------------
|
|
679
|
+
Then(/^(the )*"([^"]*)?" checkbox should( not)* be checked$/, async function (theCase, checkbox, notCase) {
|
|
680
|
+
const isChecked = await this.page.locator(checkbox).isChecked();
|
|
1340
681
|
if (notCase) {
|
|
1341
|
-
|
|
682
|
+
assert.ok(!isChecked, `Checkbox "${checkbox}" should NOT be checked but it is.`);
|
|
1342
683
|
} else {
|
|
1343
|
-
|
|
1344
|
-
browser.waitForElementVisible(selector, 3000);
|
|
1345
|
-
return browser.verify.visible(selector);
|
|
684
|
+
assert.ok(isChecked, `Checkbox "${checkbox}" should be checked but it is not.`);
|
|
1346
685
|
}
|
|
1347
686
|
});
|
|
1348
687
|
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
*
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
elementCss = elementCss.replace(";", '');
|
|
1362
|
-
const cssPropertyArr = elementCss.split(":");
|
|
1363
|
-
|
|
1364
|
-
const cssProperty = cssPropertyArr[0].trim();
|
|
1365
|
-
const propertyVal = cssPropertyArr[1].trim();
|
|
1366
|
-
|
|
1367
|
-
return browser.executeAsync(function(sel, cssProp, done) {
|
|
1368
|
-
var maxAttempts = 20;
|
|
1369
|
-
var attempts = 0;
|
|
1370
|
-
|
|
1371
|
-
var checkElement = setInterval(function() {
|
|
1372
|
-
var element = document.querySelector(sel);
|
|
1373
|
-
attempts++;
|
|
1374
|
-
|
|
1375
|
-
if (element) {
|
|
1376
|
-
clearInterval(checkElement);
|
|
1377
|
-
var computedStyle = window.getComputedStyle(element);
|
|
1378
|
-
var actualValue = computedStyle.getPropertyValue(cssProp);
|
|
1379
|
-
done({ found: true, value: actualValue });
|
|
1380
|
-
} else if (attempts >= maxAttempts) {
|
|
1381
|
-
clearInterval(checkElement);
|
|
1382
|
-
done({ found: false, value: null });
|
|
1383
|
-
}
|
|
1384
|
-
}, 500);
|
|
1385
|
-
}, [selector, cssProperty], function(result) {
|
|
1386
|
-
if (!result || !result.value || !result.value.found) {
|
|
1387
|
-
browser.assert.fail('Element "' + selector + '" was not found');
|
|
1388
|
-
} else {
|
|
1389
|
-
var actualValue = (result.value.value || '').trim();
|
|
1390
|
-
var expectedValue = propertyVal.trim();
|
|
1391
|
-
|
|
1392
|
-
if (notCase) {
|
|
1393
|
-
if (actualValue === expectedValue) {
|
|
1394
|
-
browser.assert.fail('Element "' + selector + '" should not contain CSS "' + cssProperty + ': ' + expectedValue + '" but it does');
|
|
1395
|
-
}
|
|
1396
|
-
} else {
|
|
1397
|
-
if (actualValue !== expectedValue) {
|
|
1398
|
-
browser.assert.fail('Element "' + selector + '" should contain CSS "' + cssProperty + ': ' + expectedValue + '" but has "' + actualValue + '"');
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
});
|
|
688
|
+
// ---------------------------------------------------------------------------
|
|
689
|
+
// Then the "#rememberMe" checkbox is checked
|
|
690
|
+
// Captures: (theCase, checkbox, notCase) = 3
|
|
691
|
+
// ---------------------------------------------------------------------------
|
|
692
|
+
Then(/^(the )*"([^"]*)?" checkbox is( not)* checked$/, async function (theCase, checkbox, notCase) {
|
|
693
|
+
const isChecked = await this.page.locator(checkbox).isChecked();
|
|
694
|
+
if (notCase) {
|
|
695
|
+
assert.ok(!isChecked, `Checkbox "${checkbox}" should NOT be checked but it is.`);
|
|
696
|
+
} else {
|
|
697
|
+
assert.ok(isChecked, `Checkbox "${checkbox}" should be checked but it is not.`);
|
|
698
|
+
}
|
|
1403
699
|
});
|
|
1404
700
|
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
*
|
|
1410
|
-
|
|
1411
|
-
*/
|
|
1412
|
-
Then(/^(the )*"([^"]*)?" field should( not)* contain "([^"]*)?"$/, function (theCase, field, notCase, expectedText) {
|
|
1413
|
-
// Wait for dynamic content to render (AJAX/JS)
|
|
1414
|
-
browser.pause(500);
|
|
1415
|
-
|
|
701
|
+
// ---------------------------------------------------------------------------
|
|
702
|
+
// Then the checkbox "#PrivacyPolicy" should be checked
|
|
703
|
+
// Captures: (theCase, checkbox, notCase) = 3
|
|
704
|
+
// ---------------------------------------------------------------------------
|
|
705
|
+
Then(/^(the )*checkbox "([^"]*)?" should( not)* be checked$/, async function (theCase, checkbox, notCase) {
|
|
706
|
+
const isChecked = await this.page.locator(checkbox).isChecked();
|
|
1416
707
|
if (notCase) {
|
|
1417
|
-
|
|
1418
|
-
browser.waitForElementPresent(field, 5000);
|
|
1419
|
-
return this.shouldSee = function (browser) {
|
|
1420
|
-
browser.assert.not.textContains(field, expectedText);
|
|
1421
|
-
};
|
|
708
|
+
assert.ok(!isChecked, `Checkbox "${checkbox}" should NOT be checked but it is.`);
|
|
1422
709
|
} else {
|
|
1423
|
-
|
|
1424
|
-
browser.getAttribute(elementField, 'for', function (eleAttribute) {
|
|
1425
|
-
// Wait for the input field to be present (handles dynamically generated form fields)
|
|
1426
|
-
browser.waitForElementPresent('#' + eleAttribute.value, 5000);
|
|
1427
|
-
return this.shouldSee = function (browser) {
|
|
1428
|
-
browser.assert.textContains('#' + eleAttribute.value, expectedText);
|
|
1429
|
-
};
|
|
1430
|
-
});
|
|
710
|
+
assert.ok(isChecked, `Checkbox "${checkbox}" should be checked but it is not.`);
|
|
1431
711
|
}
|
|
1432
712
|
});
|
|
1433
713
|
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
*
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
var attempts = 0;
|
|
1446
|
-
|
|
1447
|
-
var checkCheckbox = setInterval(function() {
|
|
1448
|
-
var element = document.querySelector(checkboxSelector);
|
|
1449
|
-
attempts++;
|
|
1450
|
-
|
|
1451
|
-
if (element) {
|
|
1452
|
-
clearInterval(checkCheckbox);
|
|
1453
|
-
var isChecked = element.checked;
|
|
1454
|
-
done({ found: true, checked: isChecked });
|
|
1455
|
-
} else if (attempts >= maxAttempts) {
|
|
1456
|
-
clearInterval(checkCheckbox);
|
|
1457
|
-
done({ found: false, checked: false });
|
|
1458
|
-
}
|
|
1459
|
-
}, 500);
|
|
1460
|
-
}, [checkbox, !notCase], function(result) {
|
|
1461
|
-
if (!result || !result.value || !result.value.found) {
|
|
1462
|
-
browser.assert.fail('Checkbox "' + checkbox + '" was not found in dynamically generated content');
|
|
1463
|
-
} else {
|
|
1464
|
-
if (notCase) {
|
|
1465
|
-
if (result.value.checked) {
|
|
1466
|
-
browser.assert.fail('Checkbox "' + checkbox + '" should not be checked but it is');
|
|
1467
|
-
}
|
|
1468
|
-
} else {
|
|
1469
|
-
if (!result.value.checked) {
|
|
1470
|
-
browser.assert.fail('Checkbox "' + checkbox + '" should be checked but it is not');
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
|
-
}
|
|
1474
|
-
});
|
|
714
|
+
// ---------------------------------------------------------------------------
|
|
715
|
+
// Then the checkbox "#rememberMe" is checked
|
|
716
|
+
// Captures: (theCase, checkbox, notCase) = 3
|
|
717
|
+
// ---------------------------------------------------------------------------
|
|
718
|
+
Then(/^(the )*checkbox "([^"]*)?" is( not)* checked$/, async function (theCase, checkbox, notCase) {
|
|
719
|
+
const isChecked = await this.page.locator(checkbox).isChecked();
|
|
720
|
+
if (notCase) {
|
|
721
|
+
assert.ok(!isChecked, `Checkbox "${checkbox}" should NOT be checked but it is.`);
|
|
722
|
+
} else {
|
|
723
|
+
assert.ok(isChecked, `Checkbox "${checkbox}" should be checked but it is not.`);
|
|
724
|
+
}
|
|
1475
725
|
});
|
|
1476
726
|
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
*
|
|
1482
|
-
|
|
1483
|
-
*/
|
|
1484
|
-
Then(/^(the )*"([^"]*)?" checkbox is( not)* checked$/, function (theCase, checkbox, notCase) {
|
|
1485
|
-
// Wait for dynamic content to render (AJAX/JS)
|
|
1486
|
-
browser.pause(500);
|
|
1487
|
-
// Wait for checkbox to be present (handles dynamically generated checkboxes)
|
|
1488
|
-
browser.waitForElementPresent(checkbox, 5000);
|
|
1489
|
-
|
|
727
|
+
// ---------------------------------------------------------------------------
|
|
728
|
+
// Then the radio button "#gender-male" should be selected
|
|
729
|
+
// Captures: (theCase, radioButton, notCase) = 3
|
|
730
|
+
// ---------------------------------------------------------------------------
|
|
731
|
+
Then(/^(the )*radio button "([^"]*)?" should( not)* be selected$/, async function (theCase, radioButton, notCase) {
|
|
732
|
+
const isChecked = await this.page.locator(radioButton).isChecked();
|
|
1490
733
|
if (notCase) {
|
|
1491
|
-
|
|
734
|
+
assert.ok(!isChecked, `Radio button "${radioButton}" should NOT be selected but it is.`);
|
|
1492
735
|
} else {
|
|
1493
|
-
|
|
736
|
+
assert.ok(isChecked, `Radio button "${radioButton}" should be selected but it is not.`);
|
|
1494
737
|
}
|
|
1495
738
|
});
|
|
1496
739
|
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
*
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
var checkCheckbox = setInterval(function() {
|
|
1510
|
-
var element = document.querySelector(checkboxSelector);
|
|
1511
|
-
attempts++;
|
|
1512
|
-
|
|
1513
|
-
if (element) {
|
|
1514
|
-
clearInterval(checkCheckbox);
|
|
1515
|
-
var isChecked = element.checked;
|
|
1516
|
-
done({ found: true, checked: isChecked });
|
|
1517
|
-
} else if (attempts >= maxAttempts) {
|
|
1518
|
-
clearInterval(checkCheckbox);
|
|
1519
|
-
done({ found: false, checked: false });
|
|
1520
|
-
}
|
|
1521
|
-
}, 500);
|
|
1522
|
-
}, [checkbox, !notCase], function(result) {
|
|
1523
|
-
if (!result || !result.value || !result.value.found) {
|
|
1524
|
-
browser.assert.fail('Checkbox "' + checkbox + '" was not found');
|
|
1525
|
-
} else {
|
|
1526
|
-
if (notCase) {
|
|
1527
|
-
if (result.value.checked) {
|
|
1528
|
-
browser.assert.fail('Checkbox "' + checkbox + '" should not be checked but it is');
|
|
1529
|
-
}
|
|
1530
|
-
} else {
|
|
1531
|
-
if (!result.value.checked) {
|
|
1532
|
-
browser.assert.fail('Checkbox "' + checkbox + '" should be checked but it is not');
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
}
|
|
1536
|
-
});
|
|
740
|
+
// ---------------------------------------------------------------------------
|
|
741
|
+
// Then the radio button with value "male" should be selected
|
|
742
|
+
// Captures: (theCase, radioValue, notCase) = 3
|
|
743
|
+
// ---------------------------------------------------------------------------
|
|
744
|
+
Then(/^(the )*radio button with value "([^"]*)?" should( not)* be selected$/, async function (theCase, radioValue, notCase) {
|
|
745
|
+
const isChecked = await this.page.locator(`input[type="radio"][value="${radioValue}"]`).first().isChecked();
|
|
746
|
+
if (notCase) {
|
|
747
|
+
assert.ok(!isChecked, `Radio button with value "${radioValue}" should NOT be selected but it is.`);
|
|
748
|
+
} else {
|
|
749
|
+
assert.ok(isChecked, `Radio button with value "${radioValue}" should be selected but it is not.`);
|
|
750
|
+
}
|
|
1537
751
|
});
|
|
1538
752
|
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
*
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
var checkCheckbox = setInterval(function() {
|
|
1552
|
-
var element = document.querySelector(checkboxSelector);
|
|
1553
|
-
attempts++;
|
|
1554
|
-
|
|
1555
|
-
if (element) {
|
|
1556
|
-
clearInterval(checkCheckbox);
|
|
1557
|
-
var isChecked = element.checked;
|
|
1558
|
-
done({ found: true, checked: isChecked });
|
|
1559
|
-
} else if (attempts >= maxAttempts) {
|
|
1560
|
-
clearInterval(checkCheckbox);
|
|
1561
|
-
done({ found: false, checked: false });
|
|
1562
|
-
}
|
|
1563
|
-
}, 500);
|
|
1564
|
-
}, [checkbox, !notCase], function(result) {
|
|
1565
|
-
if (!result || !result.value || !result.value.found) {
|
|
1566
|
-
browser.assert.fail('Checkbox "' + checkbox + '" was not found');
|
|
1567
|
-
} else {
|
|
1568
|
-
if (notCase) {
|
|
1569
|
-
if (result.value.checked) {
|
|
1570
|
-
browser.assert.fail('Checkbox "' + checkbox + '" should not be checked but it is');
|
|
1571
|
-
}
|
|
1572
|
-
} else {
|
|
1573
|
-
if (!result.value.checked) {
|
|
1574
|
-
browser.assert.fail('Checkbox "' + checkbox + '" should be checked but it is not');
|
|
1575
|
-
}
|
|
1576
|
-
}
|
|
1577
|
-
}
|
|
1578
|
-
});
|
|
753
|
+
// ---------------------------------------------------------------------------
|
|
754
|
+
// Then the "#gender-male" radio button is selected
|
|
755
|
+
// Captures: (theCase, radioButton, notCase) = 3
|
|
756
|
+
// ---------------------------------------------------------------------------
|
|
757
|
+
Then(/^(the )*"([^"]*)?" radio button is( not)* selected$/, async function (theCase, radioButton, notCase) {
|
|
758
|
+
const isChecked = await this.page.locator(radioButton).isChecked();
|
|
759
|
+
if (notCase) {
|
|
760
|
+
assert.ok(!isChecked, `Radio button "${radioButton}" should NOT be selected but it is.`);
|
|
761
|
+
} else {
|
|
762
|
+
assert.ok(isChecked, `Radio button "${radioButton}" should be selected but it is not.`);
|
|
763
|
+
}
|
|
1579
764
|
});
|
|
1580
765
|
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
*
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds
|
|
1593
|
-
var attempts = 0;
|
|
1594
|
-
|
|
1595
|
-
var checkRadio = setInterval(function() {
|
|
1596
|
-
var element = document.querySelector(radioSelector);
|
|
1597
|
-
attempts++;
|
|
1598
|
-
|
|
1599
|
-
if (element && element.type === 'radio') {
|
|
1600
|
-
clearInterval(checkRadio);
|
|
1601
|
-
var isSelected = element.checked;
|
|
1602
|
-
done({ found: true, selected: isSelected });
|
|
1603
|
-
} else if (attempts >= maxAttempts) {
|
|
1604
|
-
clearInterval(checkRadio);
|
|
1605
|
-
done({ found: false, selected: false });
|
|
1606
|
-
}
|
|
1607
|
-
}, 500);
|
|
1608
|
-
}, [radioButton, !notCase], function(result) {
|
|
1609
|
-
if (!result || !result.value || !result.value.found) {
|
|
1610
|
-
browser.assert.fail('Radio button "' + radioButton + '" was not found in dynamically generated content');
|
|
766
|
+
// ---------------------------------------------------------------------------
|
|
767
|
+
// Then the response status code should be 200
|
|
768
|
+
// Captures: (theCase, notCase, expectedStatusCode) = 3
|
|
769
|
+
// ---------------------------------------------------------------------------
|
|
770
|
+
Then(/^(the )*response status code should( not)* be (\d+)$/, async function (theCase, notCase, expectedStatusCode) {
|
|
771
|
+
const currentURL = this.page.url();
|
|
772
|
+
try {
|
|
773
|
+
const response = await axios.get(currentURL);
|
|
774
|
+
const status = response.status;
|
|
775
|
+
if (notCase) {
|
|
776
|
+
assert.notStrictEqual(status, parseInt(expectedStatusCode), `Status code should NOT be ${expectedStatusCode}`);
|
|
1611
777
|
} else {
|
|
1612
|
-
|
|
1613
|
-
if (result.value.selected) {
|
|
1614
|
-
browser.assert.fail('Radio button "' + radioButton + '" should not be selected but it is');
|
|
1615
|
-
}
|
|
1616
|
-
} else {
|
|
1617
|
-
if (!result.value.selected) {
|
|
1618
|
-
browser.assert.fail('Radio button "' + radioButton + '" should be selected but it is not');
|
|
1619
|
-
}
|
|
1620
|
-
}
|
|
778
|
+
assert.strictEqual(status, parseInt(expectedStatusCode), `Expected status ${expectedStatusCode} but got ${status}`);
|
|
1621
779
|
}
|
|
1622
|
-
})
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
* Assert, that radio button with specified value in a group should or should not be selected.
|
|
1627
|
-
*
|
|
1628
|
-
* Example #1: Then the radio button with value "male" should be selected
|
|
1629
|
-
* Example #2: Then the radio button with value "female" should not be selected
|
|
1630
|
-
*
|
|
1631
|
-
*/
|
|
1632
|
-
Then(/^(the )*radio button with value "([^"]*)?" should( not)* be selected$/, function (theCase, radioValue, notCase) {
|
|
1633
|
-
// Actively wait for dynamically generated radio button by polling the DOM
|
|
1634
|
-
return browser.executeAsync(function(value, shouldBeSelected, done) {
|
|
1635
|
-
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds
|
|
1636
|
-
var attempts = 0;
|
|
1637
|
-
|
|
1638
|
-
var checkRadio = setInterval(function() {
|
|
1639
|
-
var radioButtons = document.querySelectorAll('input[type="radio"]');
|
|
1640
|
-
var element = null;
|
|
1641
|
-
|
|
1642
|
-
for (var i = 0; i < radioButtons.length; i++) {
|
|
1643
|
-
if (radioButtons[i].value === value) {
|
|
1644
|
-
element = radioButtons[i];
|
|
1645
|
-
break;
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
|
|
1649
|
-
attempts++;
|
|
1650
|
-
|
|
1651
|
-
if (element) {
|
|
1652
|
-
clearInterval(checkRadio);
|
|
1653
|
-
var isSelected = element.checked;
|
|
1654
|
-
done({ found: true, selected: isSelected });
|
|
1655
|
-
} else if (attempts >= maxAttempts) {
|
|
1656
|
-
clearInterval(checkRadio);
|
|
1657
|
-
done({ found: false, selected: false });
|
|
1658
|
-
}
|
|
1659
|
-
}, 500);
|
|
1660
|
-
}, [radioValue, !notCase], function(result) {
|
|
1661
|
-
if (!result || !result.value || !result.value.found) {
|
|
1662
|
-
browser.assert.fail('Radio button with value "' + radioValue + '" was not found in dynamically generated content');
|
|
780
|
+
} catch (error) {
|
|
781
|
+
const status = error.response ? error.response.status : null;
|
|
782
|
+
if (notCase) {
|
|
783
|
+
if (status !== null) assert.notStrictEqual(status, parseInt(expectedStatusCode));
|
|
1663
784
|
} else {
|
|
1664
|
-
|
|
1665
|
-
if (result.value.selected) {
|
|
1666
|
-
browser.assert.fail('Radio button with value "' + radioValue + '" should not be selected but it is');
|
|
1667
|
-
}
|
|
1668
|
-
} else {
|
|
1669
|
-
if (!result.value.selected) {
|
|
1670
|
-
browser.assert.fail('Radio button with value "' + radioValue + '" should be selected but it is not');
|
|
1671
|
-
}
|
|
1672
|
-
}
|
|
785
|
+
assert.strictEqual(status, parseInt(expectedStatusCode), `Expected status ${expectedStatusCode} but got ${status}`);
|
|
1673
786
|
}
|
|
1674
|
-
}
|
|
787
|
+
}
|
|
1675
788
|
});
|
|
1676
789
|
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
*
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
Then(/^(the )*"([^"]*)?" radio button is( not)* selected$/, function (theCase, radioButton, notCase) {
|
|
1685
|
-
// Wait for dynamic content to render (AJAX/JS)
|
|
1686
|
-
browser.pause(500);
|
|
1687
|
-
// Wait for radio button to be present (handles dynamically generated radio buttons)
|
|
1688
|
-
browser.waitForElementPresent(radioButton, 5000);
|
|
1689
|
-
|
|
790
|
+
// ---------------------------------------------------------------------------
|
|
791
|
+
// Then I should see text matching "^T\w+"
|
|
792
|
+
// Captures: (pronounCase, notCase, textPattern) = 3
|
|
793
|
+
// ---------------------------------------------------------------------------
|
|
794
|
+
Then(/^(I |we )*should( not)* see text matching "([^"]*)?"$/, async function (pronounCase, notCase, textPattern) {
|
|
795
|
+
const bodyText = await this.page.evaluate(() => document.body.innerText || '');
|
|
796
|
+
const regex = new RegExp(textPattern);
|
|
1690
797
|
if (notCase) {
|
|
1691
|
-
|
|
798
|
+
assert.ok(!regex.test(bodyText), `Page text should NOT match "${textPattern}" but it does.`);
|
|
1692
799
|
} else {
|
|
1693
|
-
|
|
800
|
+
assert.ok(regex.test(bodyText), `Page text should match "${textPattern}" but it does not.`);
|
|
1694
801
|
}
|
|
1695
802
|
});
|
|
1696
803
|
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
*
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
axios.get(currentURL.value)
|
|
1707
|
-
.then(function (response) {
|
|
1708
|
-
if (notCase) {
|
|
1709
|
-
browser.assert.not.equal(response.status, expectedStatusCode);
|
|
1710
|
-
} else {
|
|
1711
|
-
browser.assert.equal(response.status, expectedStatusCode);
|
|
1712
|
-
}
|
|
1713
|
-
})
|
|
1714
|
-
.catch(function (error) {
|
|
1715
|
-
if (notCase) {
|
|
1716
|
-
browser.assert.not.equal(error.status, expectedStatusCode);
|
|
1717
|
-
} else {
|
|
1718
|
-
browser.assert.equal(error.status, expectedStatusCode);
|
|
1719
|
-
}
|
|
1720
|
-
})
|
|
1721
|
-
.finally(function () {
|
|
1722
|
-
// always executed
|
|
1723
|
-
});
|
|
1724
|
-
});
|
|
1725
|
-
});
|
|
1726
|
-
|
|
1727
|
-
/**
|
|
1728
|
-
* Checks, that page contains or does not contain text matching specified pattern.
|
|
1729
|
-
*
|
|
1730
|
-
* Example #1: Then I should see text matching "^T\w+" //pattern of word start with 'T'
|
|
1731
|
-
* Example #2: Then I should not see text matching "^O\w+" //pattern of word start with 'O'
|
|
1732
|
-
*
|
|
1733
|
-
*/
|
|
1734
|
-
Then(/^(I |we )*should( not)* see text matching "([^"]*)?"$/, function (pronounCase, notCase, textPattern) {
|
|
1735
|
-
// Wait for dynamically rendered content
|
|
1736
|
-
browser.pause(500);
|
|
1737
|
-
// Wait for body element to be present (handles dynamically generated content)
|
|
1738
|
-
browser.waitForElementPresent('body', 5000);
|
|
1739
|
-
|
|
1740
|
-
browser.elements('css selector', 'body', function (elements) {
|
|
1741
|
-
elements.value.forEach(function (elementsObj) {
|
|
1742
|
-
if (notCase) {
|
|
1743
|
-
return browser.assert.not.textMatches(elementsObj, textPattern);
|
|
1744
|
-
} else {
|
|
1745
|
-
return browser.assert.textMatches(elementsObj, textPattern);
|
|
1746
|
-
}
|
|
1747
|
-
});
|
|
1748
|
-
});
|
|
1749
|
-
});
|
|
1750
|
-
|
|
1751
|
-
/**
|
|
1752
|
-
* Checks, that page contains or does not contain text matching specified pattern.
|
|
1753
|
-
*
|
|
1754
|
-
* Example #1: Then I should see text matching "(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}" in the "#date" element
|
|
1755
|
-
* // pattern of DD/MM/YYYY or DD-MM-YYYY
|
|
1756
|
-
* Example #2: Then I should not see text matching "(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}" in the "#date" element
|
|
1757
|
-
* // pattern of DD/MM/YYYY or DD-MM-YYYY
|
|
1758
|
-
*
|
|
1759
|
-
*/
|
|
1760
|
-
Then(/^(I |we )*should( not)* see text matching "([^"]*)?" in( the)* "([^"]*)?" element$/, function (pronounCase, notCase, textPattern, theCase, element) {
|
|
1761
|
-
// Wait for dynamic content to render (AJAX/JS)
|
|
1762
|
-
browser.pause(500);
|
|
1763
|
-
// Wait for element to be present (handles dynamically generated elements)
|
|
1764
|
-
browser.waitForElementPresent(element, 5000);
|
|
1765
|
-
|
|
804
|
+
// ---------------------------------------------------------------------------
|
|
805
|
+
// Then I should see text matching "..." in the "#date" element
|
|
806
|
+
// Captures: (pronounCase, notCase, textPattern, theCase, element) = 5
|
|
807
|
+
// ---------------------------------------------------------------------------
|
|
808
|
+
Then(/^(I |we )*should( not)* see text matching "([^"]*)?" in( the)* "([^"]*)?" element$/, async function (pronounCase, notCase, textPattern, theCase, element) {
|
|
809
|
+
const loc = this.page.locator(element).first();
|
|
810
|
+
await loc.waitFor({ timeout: 5000 });
|
|
811
|
+
const text = await getLocatorText(loc);
|
|
812
|
+
const regex = new RegExp(textPattern);
|
|
1766
813
|
if (notCase) {
|
|
1767
|
-
|
|
814
|
+
assert.ok(!regex.test(text), `Element "${element}" text should NOT match "${textPattern}" but it does.`);
|
|
1768
815
|
} else {
|
|
1769
|
-
|
|
1770
|
-
browser.assert.textMatches(element, textPattern);
|
|
1771
|
-
};
|
|
816
|
+
assert.ok(regex.test(text), `Element "${element}" text should match "${textPattern}" but it does not.`);
|
|
1772
817
|
}
|
|
1773
818
|
});
|
|
1774
819
|
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
Then(/^(the )*url should( not)* match "([^"]*)?"$/, function (theCase, notCase, pattern) {
|
|
1783
|
-
// Wait for page to load and URL changes from AJAX/JS navigation
|
|
1784
|
-
browser.pause(500);
|
|
1785
|
-
// Wait for page to be present (handles dynamic navigation)
|
|
1786
|
-
browser.waitForElementPresent('body', 5000);
|
|
1787
|
-
|
|
820
|
+
// ---------------------------------------------------------------------------
|
|
821
|
+
// Then the url should match "/contact-us.html"
|
|
822
|
+
// Captures: (theCase, notCase, pattern) = 3
|
|
823
|
+
// ---------------------------------------------------------------------------
|
|
824
|
+
Then(/^(the )*url should( not)* match "([^"]*)?"$/, async function (theCase, notCase, pattern) {
|
|
825
|
+
const currentUrl = this.page.url();
|
|
826
|
+
const regex = new RegExp(pattern);
|
|
1788
827
|
if (notCase) {
|
|
1789
|
-
|
|
828
|
+
assert.ok(!regex.test(currentUrl), `URL "${currentUrl}" should NOT match "${pattern}" but it does.`);
|
|
1790
829
|
} else {
|
|
1791
|
-
|
|
830
|
+
assert.ok(regex.test(currentUrl), `URL "${currentUrl}" should match "${pattern}" but it does not.`);
|
|
1792
831
|
}
|
|
1793
832
|
});
|
|
1794
833
|
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
*/
|
|
1802
|
-
When(/^(I |we )*attach( the)* file "([^"]*)?" to "([^"]*)?"$/, function (pronounCase, theCase, fileName, element) {
|
|
1803
|
-
// Construct local file path.
|
|
1804
|
-
let assetsFolder;
|
|
1805
|
-
if (browser.globals && browser.globals.assets_folder) {
|
|
1806
|
-
assetsFolder = browser.globals.assets_folder;
|
|
1807
|
-
} else {
|
|
1808
|
-
assetsFolder = path.join(__dirname, '/tests/assets/');
|
|
1809
|
-
}
|
|
1810
|
-
|
|
1811
|
-
const localFilePath = path.resolve(assetsFolder, fileName);
|
|
1812
|
-
|
|
1813
|
-
// Wait for file input element to be present
|
|
1814
|
-
browser.waitForElementPresent(element, 5000);
|
|
1815
|
-
browser.pause(5000);
|
|
1816
|
-
browser.uploadFile(element, localFilePath);
|
|
1817
|
-
browser.pause(10000);
|
|
1818
|
-
return browser.setValue(element, fileName);
|
|
1819
|
-
|
|
1820
|
-
});
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
/**
|
|
1825
|
-
* Wait a specific number of seconds.
|
|
1826
|
-
*
|
|
1827
|
-
|
|
1828
|
-
* Example #1: When I wait 1 second
|
|
1829
|
-
* Example #2: When I wait 5 seconds
|
|
1830
|
-
* Example #3: When we wait 3s
|
|
1831
|
-
* Example #4: And wait 2s
|
|
1832
|
-
* Example #5: And wait 2 seconds
|
|
1833
|
-
* Example #6: When we wait 1 second
|
|
1834
|
-
* Example #7: When we wait 5 seconds
|
|
1835
|
-
* Example #8: When we wait 4s
|
|
1836
|
-
*
|
|
1837
|
-
*/
|
|
1838
|
-
When(/^(I |we )*wait (\d*)( second| seconds|s)?$/, function (pronounCase, number, withSecondWord) {
|
|
1839
|
-
var waitTime = number * 1000;
|
|
1840
|
-
return browser.pause(waitTime);
|
|
1841
|
-
});
|
|
1842
|
-
|
|
1843
|
-
/**
|
|
1844
|
-
* Wait a max number of seconds until the element present.
|
|
1845
|
-
*
|
|
1846
|
-
* Example #1: When I wait max of 1 second
|
|
1847
|
-
* Example #2: When I wait max of 5 seconds
|
|
1848
|
-
* Example #3: When we wait max of 3s
|
|
1849
|
-
* Example #4: And wait max of 2s
|
|
1850
|
-
* Example #5: And wait max of 2 seconds
|
|
1851
|
-
* Example #6: When we wait max of 1 second
|
|
1852
|
-
* Example #7: When we wait max of 5 seconds
|
|
1853
|
-
* Example #8: When we wait max of 4s
|
|
1854
|
-
*
|
|
1855
|
-
*/
|
|
1856
|
-
When(/^(I |we )*wait max of (\d*)( second| seconds|s)?$/, function (pronounCase, number, withSecondWord) {
|
|
1857
|
-
var waitTime = number * 1000;
|
|
1858
|
-
return browser.waitForElementPresent('body', waitTime);
|
|
1859
|
-
});
|
|
1860
|
-
|
|
1861
|
-
/**
|
|
1862
|
-
* Wait a specific number of minutes.
|
|
1863
|
-
*
|
|
1864
|
-
* Example #1: When I wait 1 minute
|
|
1865
|
-
* Example #2: When I wait 10 minutes
|
|
1866
|
-
* Example #3: When we wait 1m
|
|
1867
|
-
* Example #4: And wait 2s
|
|
1868
|
-
* Example #5: And wait 2 minutes
|
|
1869
|
-
* Example #6: When we wait 1 minute
|
|
1870
|
-
* Example #7: When we wait 10 minutes
|
|
1871
|
-
* Example #8: When we wait 2m
|
|
1872
|
-
*
|
|
1873
|
-
*/
|
|
1874
|
-
When(/^(I |we )*wait (\d*)( minute| minutes|m)?$/, function (pronounCase, number, withMinuteWord) {
|
|
1875
|
-
var waitTime = number * 1000 * 60;
|
|
1876
|
-
return browser.pause(waitTime);
|
|
1877
|
-
});
|
|
1878
|
-
|
|
1879
|
-
/**
|
|
1880
|
-
* Wait a max number of minutes until the element present.
|
|
1881
|
-
*
|
|
1882
|
-
* Example #1: When I wait 1 minute
|
|
1883
|
-
* Example #2: When I wait 10 minutes
|
|
1884
|
-
* Example #3: When we wait 1m
|
|
1885
|
-
* Example #4: And wait 2s
|
|
1886
|
-
* Example #5: And wait 2 minutes
|
|
1887
|
-
* Example #6: When we wait 1 minute
|
|
1888
|
-
* Example #7: When we wait 10 minutes
|
|
1889
|
-
* Example #8: When we wait 2m
|
|
1890
|
-
*
|
|
1891
|
-
*/
|
|
1892
|
-
When(/^(I |we )*wait max of (\d*)( minute| minutes|m)?$/, function (pronounCase, number, withMinuteWord) {
|
|
1893
|
-
var waitTime = number * 1000 * 60;
|
|
1894
|
-
return browser.waitForElementPresent('body', waitTime);
|
|
1895
|
-
});
|
|
1896
|
-
|
|
1897
|
-
/**
|
|
1898
|
-
* Wait until the page is loaded.
|
|
1899
|
-
*
|
|
1900
|
-
* Example #1: When I wait until the page is loaded
|
|
1901
|
-
* Example #1: When we wait until the page is loaded
|
|
1902
|
-
* Example #2: When wait until page loaded
|
|
1903
|
-
*
|
|
1904
|
-
*/
|
|
1905
|
-
When(/^(I |we )*wait until( the)* page( is)* loaded*$/, function (pronounCase, theCase, withIs) {
|
|
1906
|
-
return browser.waitForElementPresent('body', 10000);
|
|
1907
|
-
});
|
|
1908
|
-
|
|
1909
|
-
/**
|
|
1910
|
-
* Wait for AJAX requests to finish.
|
|
1911
|
-
* This step waits for active XMLHttpRequest and Fetch API requests to complete.
|
|
1912
|
-
*
|
|
1913
|
-
* Example #1: When I wait for AJAX to finish
|
|
1914
|
-
* Example #2: And I wait for AJAX to finish
|
|
1915
|
-
* Example #3: When we wait for AJAX to finish
|
|
1916
|
-
* Example #4: And wait for AJAX to finish
|
|
1917
|
-
*
|
|
1918
|
-
*/
|
|
1919
|
-
When(/^(I |we )*wait for AJAX to finish$/, function (pronounCase) {
|
|
1920
|
-
return browser.executeAsync(function(done) {
|
|
1921
|
-
var maxAttempts = 20; // 20 attempts * 500ms = 10 seconds max
|
|
1922
|
-
var attempts = 0;
|
|
1923
|
-
|
|
1924
|
-
var checkAjax = setInterval(function() {
|
|
1925
|
-
attempts++;
|
|
1926
|
-
|
|
1927
|
-
// Check for active XMLHttpRequest requests
|
|
1928
|
-
var activeXHR = window.XMLHttpRequest && window.XMLHttpRequest.active || 0;
|
|
1929
|
-
|
|
1930
|
-
// Check for active fetch requests (tracked via monkey-patching)
|
|
1931
|
-
var activeFetch = window.__activeFetchCount || 0;
|
|
1932
|
-
|
|
1933
|
-
// Check if document is still loading
|
|
1934
|
-
var documentLoading = document.readyState !== 'complete';
|
|
1935
|
-
|
|
1936
|
-
if (activeXHR === 0 && activeFetch === 0 && !documentLoading) {
|
|
1937
|
-
clearInterval(checkAjax);
|
|
1938
|
-
done({ finished: true, attempts: attempts });
|
|
1939
|
-
} else if (attempts >= maxAttempts) {
|
|
1940
|
-
clearInterval(checkAjax);
|
|
1941
|
-
done({
|
|
1942
|
-
finished: false,
|
|
1943
|
-
attempts: attempts,
|
|
1944
|
-
activeXHR: activeXHR,
|
|
1945
|
-
activeFetch: activeFetch,
|
|
1946
|
-
documentLoading: documentLoading
|
|
1947
|
-
});
|
|
1948
|
-
}
|
|
1949
|
-
}, 500);
|
|
1950
|
-
}, [], function(result) {
|
|
1951
|
-
if (!result || !result.value || !result.value.finished) {
|
|
1952
|
-
var debugInfo = result && result.value ?
|
|
1953
|
-
` (XHR: ${result.value.activeXHR}, Fetch: ${result.value.activeFetch}, DocLoading: ${result.value.documentLoading})` : '';
|
|
1954
|
-
console.warn('AJAX requests did not finish within timeout period' + debugInfo);
|
|
1955
|
-
// Don't fail the test, just log a warning
|
|
1956
|
-
}
|
|
1957
|
-
});
|
|
834
|
+
// ---------------------------------------------------------------------------
|
|
835
|
+
// When I attach the file "profileIcon.jpg" to "#profile-icon-upload"
|
|
836
|
+
// Captures: (pronounCase, theCase, fileName, element) = 4
|
|
837
|
+
// ---------------------------------------------------------------------------
|
|
838
|
+
When(/^(I |we )*attach( the)* file "([^"]*)?" to "([^"]*)?"$/, async function (pronounCase, theCase, fileName, element) {
|
|
839
|
+
await this.page.locator(element).setInputFiles(path.resolve(this.assetsFolder, fileName));
|
|
1958
840
|
});
|
|
1959
841
|
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
*
|
|
1965
|
-
*
|
|
1966
|
-
* Example #2: When I scroll down 800
|
|
1967
|
-
* Example #3: And we scroll down 500
|
|
1968
|
-
* Example #4: When scrolling down 1200
|
|
1969
|
-
*/
|
|
1970
|
-
When(/^(I scroll|we scroll|scrolling)? down( ([^"]*)?)*$/, function(pronounCase, value) {
|
|
1971
|
-
// Default scroll value
|
|
1972
|
-
let scrollValue = 350;
|
|
1973
|
-
|
|
1974
|
-
if (value !== null) {
|
|
1975
|
-
scrollValue = parseInt(String(value).trim(), 10);
|
|
1976
|
-
|
|
1977
|
-
// Validate the parsed value
|
|
1978
|
-
if (isNaN(scrollValue)) {
|
|
1979
|
-
throw new Error(`Invalid scroll value: "${value}". Expected a number.`);
|
|
1980
|
-
}
|
|
1981
|
-
|
|
1982
|
-
if (scrollValue < 0) {
|
|
1983
|
-
throw new Error(`Scroll down value must be positive. Received: ${scrollValue}`);
|
|
1984
|
-
}
|
|
1985
|
-
|
|
1986
|
-
if (scrollValue > 10000) {
|
|
1987
|
-
console.warn(`Large scroll value detected: ${scrollValue}px. Consider if this is intentional.`);
|
|
1988
|
-
}
|
|
1989
|
-
}
|
|
1990
|
-
|
|
1991
|
-
return browser.executeScript(`window.scrollBy(0, ${scrollValue});`);
|
|
842
|
+
// ---------------------------------------------------------------------------
|
|
843
|
+
// When I wait 1 second / 5 seconds
|
|
844
|
+
// Captures: (pronounCase, number, withSecondWord) = 3
|
|
845
|
+
// ---------------------------------------------------------------------------
|
|
846
|
+
When(/^(I |we )*wait (\d*)( second| seconds|s)?$/, async function (pronounCase, number, withSecondWord) {
|
|
847
|
+
await this.page.waitForTimeout(parseInt(number) * 1000);
|
|
1992
848
|
});
|
|
1993
849
|
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
*
|
|
1999
|
-
|
|
2000
|
-
* Example #4: When scrolling up 750
|
|
2001
|
-
*
|
|
2002
|
-
*/
|
|
2003
|
-
When(/^(I scroll|we scroll|scrolling)? up( ([^"]*)?)*$/, function(pronounCase, value) {
|
|
2004
|
-
// Parse and validate the scroll value
|
|
2005
|
-
let scrollValue = 350; // default value
|
|
2006
|
-
|
|
2007
|
-
if (value !== null) {
|
|
2008
|
-
scrollValue = parseInt(String(value).trim(), 10);
|
|
2009
|
-
|
|
2010
|
-
// Validate the parsed value
|
|
2011
|
-
if (isNaN(scrollValue)) {
|
|
2012
|
-
throw new Error(`Invalid scroll value: "${value}". Expected a number.`);
|
|
2013
|
-
}
|
|
2014
|
-
|
|
2015
|
-
if (scrollValue < 0) {
|
|
2016
|
-
throw new Error(`Scroll up value must be positive. Received: ${scrollValue}`);
|
|
2017
|
-
}
|
|
2018
|
-
|
|
2019
|
-
if (scrollValue > 10000) {
|
|
2020
|
-
console.warn(`Large scroll value detected: ${scrollValue}px. Consider if this is intentional.`);
|
|
2021
|
-
}
|
|
2022
|
-
}
|
|
2023
|
-
|
|
2024
|
-
// Make the value negative for scrolling up
|
|
2025
|
-
return browser.executeScript(`window.scrollBy(0, -${scrollValue});`);
|
|
2026
|
-
});
|
|
2027
|
-
|
|
2028
|
-
/**
|
|
2029
|
-
* Scrolls to the very top of the current page, resetting the scroll position to zero.
|
|
2030
|
-
*
|
|
2031
|
-
* Example #1: When I scroll to top
|
|
2032
|
-
* Example #2: And we scrolling to the top
|
|
2033
|
-
* Example #3: When scrolling to the top of the page
|
|
2034
|
-
*/
|
|
2035
|
-
When(/^(I scroll|we scroll|scrolling)? to( the)* top( of the page)*$/, function(pronounCase, theCase, pageCase) {
|
|
2036
|
-
return browser.executeScript('document.documentElement.scrollTop = 0;');
|
|
2037
|
-
});
|
|
2038
|
-
|
|
2039
|
-
/**
|
|
2040
|
-
* Scrolls to the bottom of the current page using the full document height.
|
|
2041
|
-
*
|
|
2042
|
-
* Example #1: When I scroll to the bottom
|
|
2043
|
-
* Example #2: And we scroll to bottom
|
|
2044
|
-
* Example #3: When scrolling to the bottom of the page
|
|
2045
|
-
*/
|
|
2046
|
-
When(/^(I scroll|we scroll|scrolling)? to( the)* bottom( of the page)*$/, function(pronounCase, theCase, pageCase) {
|
|
2047
|
-
return browser.executeScript('window.scrollTo(0, document.body.scrollHeight);');
|
|
2048
|
-
});
|
|
2049
|
-
|
|
2050
|
-
/**
|
|
2051
|
-
* Scrolls to the top of a specific element identified by a CSS selector, resetting its scroll position to zero.
|
|
2052
|
-
*
|
|
2053
|
-
* Example #1: When I scroll to top of "#off-canvas"
|
|
2054
|
-
* Example #2: And we scroll to top of "#sidebar"
|
|
2055
|
-
* Example #3: When scrolling to top of "#main-container"
|
|
2056
|
-
*/
|
|
2057
|
-
When(/^(I scroll|we scroll|scrolling)? to top of "([^"]*)"$/, function(pronounCase, selector) {
|
|
2058
|
-
// Validate selector
|
|
2059
|
-
if (!selector || selector.trim() === '') {
|
|
2060
|
-
throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
|
|
2061
|
-
}
|
|
2062
|
-
|
|
2063
|
-
// Validate selector format (basic check)
|
|
2064
|
-
if (selector.includes('"') || selector.includes("'")) {
|
|
2065
|
-
throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
|
|
2066
|
-
}
|
|
2067
|
-
|
|
2068
|
-
try {
|
|
2069
|
-
// Wait for element to be present (allows dynamic elements to load)
|
|
2070
|
-
browser.waitForElementPresent(selector, 5000);
|
|
2071
|
-
|
|
2072
|
-
// Check if element exists before scrolling
|
|
2073
|
-
const elementExists = browser.executeScript(`
|
|
2074
|
-
return document.querySelector("${selector}") !== null;
|
|
2075
|
-
`);
|
|
2076
|
-
|
|
2077
|
-
if (!elementExists) {
|
|
2078
|
-
throw new Error(`Element with selector "${selector}" not found.`);
|
|
2079
|
-
}
|
|
2080
|
-
|
|
2081
|
-
browser.executeScript(`
|
|
2082
|
-
const element = document.querySelector("${selector}");
|
|
2083
|
-
if (element) {
|
|
2084
|
-
element.scrollTop = 0;
|
|
2085
|
-
}
|
|
2086
|
-
`);
|
|
2087
|
-
|
|
2088
|
-
return browser.pause(2000);
|
|
2089
|
-
} catch (error) {
|
|
2090
|
-
throw new Error(`Failed to scroll to top of element "${selector}": ${error.message}`);
|
|
2091
|
-
}
|
|
850
|
+
// ---------------------------------------------------------------------------
|
|
851
|
+
// When I wait max of 5 seconds
|
|
852
|
+
// Captures: (pronounCase, number, withSecondWord) = 3
|
|
853
|
+
// ---------------------------------------------------------------------------
|
|
854
|
+
When(/^(I |we )*wait max of (\d*)( second| seconds|s)?$/, async function (pronounCase, number, withSecondWord) {
|
|
855
|
+
await this.page.waitForTimeout(parseInt(number) * 1000);
|
|
2092
856
|
});
|
|
2093
857
|
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
*
|
|
2099
|
-
|
|
2100
|
-
*/
|
|
2101
|
-
When(/^(I scroll|we scroll|scrolling)? to bottom of "([^"]*)"$/, function(pronounCase, selector) {
|
|
2102
|
-
// Validate selector
|
|
2103
|
-
if (!selector || selector.trim() === '') {
|
|
2104
|
-
throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
|
|
2105
|
-
}
|
|
2106
|
-
|
|
2107
|
-
// Validate selector format (basic check)
|
|
2108
|
-
if (selector.includes('"') || selector.includes("'")) {
|
|
2109
|
-
throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
|
|
2110
|
-
}
|
|
2111
|
-
|
|
2112
|
-
try {
|
|
2113
|
-
// Wait for element to be present (allows dynamic elements to load)
|
|
2114
|
-
browser.waitForElementPresent(selector, 5000);
|
|
2115
|
-
|
|
2116
|
-
// Check if element exists before scrolling
|
|
2117
|
-
const elementExists = browser.executeScript(`
|
|
2118
|
-
return document.querySelector("${selector}") !== null;
|
|
2119
|
-
`);
|
|
2120
|
-
|
|
2121
|
-
if (!elementExists) {
|
|
2122
|
-
throw new Error(`Element with selector "${selector}" not found.`);
|
|
2123
|
-
}
|
|
2124
|
-
|
|
2125
|
-
browser.executeScript(`
|
|
2126
|
-
const element = document.querySelector("${selector}");
|
|
2127
|
-
if (element) {
|
|
2128
|
-
element.scrollTop = element.scrollHeight;
|
|
2129
|
-
}
|
|
2130
|
-
`);
|
|
2131
|
-
|
|
2132
|
-
return browser.pause(2000);
|
|
2133
|
-
} catch (error) {
|
|
2134
|
-
throw new Error(`Failed to scroll to bottom of element "${selector}": ${error.message}`);
|
|
2135
|
-
}
|
|
858
|
+
// ---------------------------------------------------------------------------
|
|
859
|
+
// When I wait 1 minute
|
|
860
|
+
// Captures: (pronounCase, number, withMinuteWord) = 3
|
|
861
|
+
// ---------------------------------------------------------------------------
|
|
862
|
+
When(/^(I |we )*wait (\d*)( minute| minutes|m)?$/, async function (pronounCase, number, withMinuteWord) {
|
|
863
|
+
await this.page.waitForTimeout(parseInt(number) * 1000 * 60);
|
|
2136
864
|
});
|
|
2137
865
|
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
*
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
*
|
|
2146
|
-
*/
|
|
2147
|
-
When(/^(I scroll|we scroll|scrolling)? right( ([^"]*)?)*$/, function(pronounCase, value) {
|
|
2148
|
-
// Parse and validate the scroll value
|
|
2149
|
-
let scrollValue = 350; // default value
|
|
2150
|
-
|
|
2151
|
-
if (value !== null) {
|
|
2152
|
-
scrollValue = parseInt(String(value).trim(), 10);
|
|
2153
|
-
|
|
2154
|
-
// Validate the parsed value
|
|
2155
|
-
if (isNaN(scrollValue)) {
|
|
2156
|
-
throw new Error(`Invalid scroll value: "${value}". Expected a number.`);
|
|
2157
|
-
}
|
|
2158
|
-
|
|
2159
|
-
if (scrollValue < 0) {
|
|
2160
|
-
throw new Error(`Scroll right value must be positive. Received: ${scrollValue}`);
|
|
2161
|
-
}
|
|
2162
|
-
|
|
2163
|
-
if (scrollValue > 10000) {
|
|
2164
|
-
console.warn(`Large scroll value detected: ${scrollValue}px. Consider if this is intentional.`);
|
|
2165
|
-
}
|
|
2166
|
-
}
|
|
2167
|
-
|
|
2168
|
-
// Make the value negative for scrolling right
|
|
2169
|
-
return browser.executeScript(`window.scrollBy( ${scrollValue}, 0);`);
|
|
2170
|
-
});
|
|
2171
|
-
|
|
2172
|
-
/**
|
|
2173
|
-
* Scrolls left the page by a custom number of pixels specified by the user.
|
|
2174
|
-
*
|
|
2175
|
-
* Example #1: And I scroll left
|
|
2176
|
-
* Example #2: When I scroll left 800
|
|
2177
|
-
* Example #3: And we scroll left 500
|
|
2178
|
-
* Example #4: When scrolling left 1200
|
|
2179
|
-
*/
|
|
2180
|
-
When(/^(I scroll|we scroll|scrolling)? left( ([^"]*)?)*$/, function(pronounCase, value) {
|
|
2181
|
-
// Default scroll value
|
|
2182
|
-
let scrollValue = 350;
|
|
2183
|
-
|
|
2184
|
-
if (value !== null) {
|
|
2185
|
-
scrollValue = parseInt(String(value).trim(), 10);
|
|
2186
|
-
|
|
2187
|
-
// Validate the parsed value
|
|
2188
|
-
if (isNaN(scrollValue)) {
|
|
2189
|
-
throw new Error(`Invalid scroll value: "${value}". Expected a number.`);
|
|
2190
|
-
}
|
|
2191
|
-
|
|
2192
|
-
if (scrollValue < 0) {
|
|
2193
|
-
throw new Error(`Scroll left value must be positive. Received: ${scrollValue}`);
|
|
2194
|
-
}
|
|
866
|
+
// ---------------------------------------------------------------------------
|
|
867
|
+
// When I wait max of 1 minute
|
|
868
|
+
// Captures: (pronounCase, number, withMinuteWord) = 3
|
|
869
|
+
// ---------------------------------------------------------------------------
|
|
870
|
+
When(/^(I |we )*wait max of (\d*)( minute| minutes|m)?$/, async function (pronounCase, number, withMinuteWord) {
|
|
871
|
+
await this.page.waitForTimeout(parseInt(number) * 1000 * 60);
|
|
872
|
+
});
|
|
2195
873
|
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
874
|
+
// ---------------------------------------------------------------------------
|
|
875
|
+
// When I wait until the page is loaded
|
|
876
|
+
// Captures: (pronounCase, theCase, withIs) = 3
|
|
877
|
+
// ---------------------------------------------------------------------------
|
|
878
|
+
When(/^(I |we )*wait until( the)* page( is)* loaded*$/, async function (pronounCase, theCase, withIs) {
|
|
879
|
+
await waitForPageLoad(this.page, 10000);
|
|
880
|
+
});
|
|
2200
881
|
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
* Example #2: And we scrolling to the start
|
|
2209
|
-
* Example #3: When scrolling to the start of the page
|
|
2210
|
-
*/
|
|
2211
|
-
When(/^(I scroll|we scroll|scrolling)? to( the)* start( of the page)*$/, function(pronounCase, theCase, pageCase) {
|
|
2212
|
-
return browser.executeScript('window.scrollTo(0, window.scrollY);');
|
|
2213
|
-
});
|
|
2214
|
-
|
|
2215
|
-
/**
|
|
2216
|
-
* Scrolls to the end of the current page using the full document height.
|
|
2217
|
-
*
|
|
2218
|
-
* Example #1: When I scroll to the end
|
|
2219
|
-
* Example #2: And we scroll to end
|
|
2220
|
-
* Example #3: When scrolling to the end of the page
|
|
2221
|
-
*/
|
|
2222
|
-
When(/^(I scroll|we scroll|scrolling)? to( the)* end( of the page)*$/, function(pronounCase, theCase, pageCase) {
|
|
2223
|
-
return browser.executeScript('window.scrollTo(document.body.scrollWidth, window.scrollY);');
|
|
2224
|
-
});
|
|
2225
|
-
|
|
2226
|
-
/**
|
|
2227
|
-
* Scrolls to the start of a specific element identified by a CSS selector, resetting its scroll position to zero.
|
|
2228
|
-
*
|
|
2229
|
-
* Example #1: When I scroll to start of "#off-canvas"
|
|
2230
|
-
* Example #2: And we scroll to start of "#sidebar"
|
|
2231
|
-
* Example #3: When scrolling to start of "#main-container"
|
|
2232
|
-
*/
|
|
2233
|
-
When(/^(I scroll|we scroll|scrolling)? to start of "([^"]*)"$/, function(pronounCase, selector) {
|
|
2234
|
-
// Validate selector
|
|
2235
|
-
if (!selector || selector.trim() === '') {
|
|
2236
|
-
throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
|
|
2237
|
-
}
|
|
882
|
+
// ---------------------------------------------------------------------------
|
|
883
|
+
// When I wait for AJAX to finish
|
|
884
|
+
// Captures: (pronounCase) = 1
|
|
885
|
+
// ---------------------------------------------------------------------------
|
|
886
|
+
When(/^(I |we )*wait for AJAX to finish$/, async function (pronounCase) {
|
|
887
|
+
await this.page.waitForLoadState('networkidle', { timeout: 10000 }).catch(() => {});
|
|
888
|
+
});
|
|
2238
889
|
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
890
|
+
// ---------------------------------------------------------------------------
|
|
891
|
+
// Scroll steps
|
|
892
|
+
// ---------------------------------------------------------------------------
|
|
893
|
+
When(/^(I scroll|we scroll|scrolling)? down(?: (\d+))?$/, async function (pronounCase, numValue) {
|
|
894
|
+
await this.page.evaluate((v) => window.scrollBy(0, v), numValue ? parseInt(numValue, 10) : 350);
|
|
895
|
+
});
|
|
2243
896
|
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
897
|
+
When(/^(I scroll|we scroll|scrolling)? up(?: (\d+))?$/, async function (pronounCase, numValue) {
|
|
898
|
+
await this.page.evaluate((v) => window.scrollBy(0, -v), numValue ? parseInt(numValue, 10) : 350);
|
|
899
|
+
});
|
|
2247
900
|
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
`);
|
|
901
|
+
When(/^(I scroll|we scroll|scrolling)? to( the)* top( of the page)*$/, async function (pronounCase, theCase, pageCase) {
|
|
902
|
+
await this.page.evaluate(() => window.scrollTo(0, 0));
|
|
903
|
+
});
|
|
2252
904
|
|
|
2253
|
-
|
|
2254
|
-
|
|
905
|
+
When(/^(I scroll|we scroll|scrolling)? to( the)* bottom( of the page)*$/, async function (pronounCase, theCase, pageCase) {
|
|
906
|
+
await this.page.evaluate(() => {
|
|
907
|
+
window.scrollTo(0, document.body.scrollHeight);
|
|
908
|
+
document.querySelectorAll('*').forEach(el => {
|
|
909
|
+
const s = window.getComputedStyle(el);
|
|
910
|
+
if ((s.overflowY === 'scroll' || s.overflowY === 'auto') && el.scrollHeight > el.clientHeight) {
|
|
911
|
+
el.scrollTop = el.scrollHeight;
|
|
912
|
+
el.dispatchEvent(new Event('scroll', { bubbles: true }));
|
|
2255
913
|
}
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
const element = document.querySelector("${selector}");
|
|
2259
|
-
if (element) {
|
|
2260
|
-
element.scrollTop = 0;
|
|
2261
|
-
}
|
|
2262
|
-
`);
|
|
2263
|
-
|
|
2264
|
-
return browser.pause(2000);
|
|
2265
|
-
} catch (error) {
|
|
2266
|
-
throw new Error(`Failed to scroll to top of element "${selector}": ${error.message}`);
|
|
2267
|
-
}
|
|
914
|
+
});
|
|
915
|
+
});
|
|
2268
916
|
});
|
|
2269
917
|
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
*/
|
|
2277
|
-
When(/^(I scroll|we scroll|scrolling)? to end of "([^"]*)"$/, function(pronounCase, selector) {
|
|
2278
|
-
// Validate selector
|
|
2279
|
-
if (!selector || selector.trim() === '') {
|
|
2280
|
-
throw new Error('Selector cannot be empty. Please provide a valid CSS selector.');
|
|
2281
|
-
}
|
|
2282
|
-
|
|
2283
|
-
// Validate selector format (basic check)
|
|
2284
|
-
if (selector.includes('"') || selector.includes("'")) {
|
|
2285
|
-
throw new Error(`Invalid selector format: "${selector}". Selector should not contain quotes.`);
|
|
2286
|
-
}
|
|
2287
|
-
|
|
2288
|
-
try {
|
|
2289
|
-
// Wait for element to be present (allows dynamic elements to load)
|
|
2290
|
-
browser.waitForElementPresent(selector, 5000);
|
|
2291
|
-
|
|
2292
|
-
// Check if element exists before scrolling
|
|
2293
|
-
const elementExists = browser.executeScript(`
|
|
2294
|
-
return document.querySelector("${selector}") !== null;
|
|
2295
|
-
`);
|
|
2296
|
-
|
|
2297
|
-
if (!elementExists) {
|
|
2298
|
-
throw new Error(`Element with selector "${selector}" not found.`);
|
|
2299
|
-
}
|
|
918
|
+
When(/^(I scroll|we scroll|scrolling)? to top of "([^"]*)"$/, async function (pronounCase, selector) {
|
|
919
|
+
await this.page.locator(selector).evaluate(el => {
|
|
920
|
+
el.scrollTop = 0;
|
|
921
|
+
el.dispatchEvent(new Event('scroll', { bubbles: true }));
|
|
922
|
+
});
|
|
923
|
+
});
|
|
2300
924
|
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
925
|
+
When(/^(I scroll|we scroll|scrolling)? to bottom of "([^"]*)"$/, async function (pronounCase, selector) {
|
|
926
|
+
await this.page.locator(selector).evaluate(el => {
|
|
927
|
+
el.scrollTop = el.scrollHeight;
|
|
928
|
+
el.dispatchEvent(new Event('scroll', { bubbles: true }));
|
|
929
|
+
});
|
|
930
|
+
});
|
|
2307
931
|
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
throw new Error(`Failed to scroll to bottom of element "${selector}": ${error.message}`);
|
|
2311
|
-
}
|
|
932
|
+
When(/^(I scroll|we scroll|scrolling)? right(?: (\d+))?$/, async function (pronounCase, numValue) {
|
|
933
|
+
await this.page.evaluate((v) => window.scrollBy(v, 0), numValue ? parseInt(numValue, 10) : 350);
|
|
2312
934
|
});
|
|
2313
935
|
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
*
|
|
2317
|
-
* Example #1: Then I should see a modal
|
|
2318
|
-
* Example #2: Then I should see the modal
|
|
2319
|
-
* Example #3: Then we should see a modal dialog
|
|
2320
|
-
* Example #4: Then I should not see a modal
|
|
2321
|
-
* Example #5: Then I should not see the modal dialog
|
|
2322
|
-
*
|
|
2323
|
-
*/
|
|
2324
|
-
Then(/^(I |we )*should( not)* see (a |the )*modal( dialog)*$/, function (pronounCase, notCase, aTheCase, dialogCase) {
|
|
2325
|
-
// Common selectors for modals
|
|
2326
|
-
const modalSelectors = [
|
|
2327
|
-
'.modal:not([style*="display: none"])',
|
|
2328
|
-
'.modal.show',
|
|
2329
|
-
'.modal.in',
|
|
2330
|
-
'[role="dialog"]',
|
|
2331
|
-
'.dialog:not([style*="display: none"])',
|
|
2332
|
-
'.popup:not([style*="display: none"])',
|
|
2333
|
-
'.overlay:not([style*="display: none"])'
|
|
2334
|
-
];
|
|
2335
|
-
|
|
2336
|
-
return browser.execute(function(selectors) {
|
|
2337
|
-
for (let selector of selectors) {
|
|
2338
|
-
const elements = document.querySelectorAll(selector);
|
|
2339
|
-
for (let element of elements) {
|
|
2340
|
-
const style = window.getComputedStyle(element);
|
|
2341
|
-
if (style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0') {
|
|
2342
|
-
return true;
|
|
2343
|
-
}
|
|
2344
|
-
}
|
|
2345
|
-
}
|
|
2346
|
-
return false;
|
|
2347
|
-
}, [modalSelectors], function(result) {
|
|
2348
|
-
if (notCase) {
|
|
2349
|
-
if (result.value) {
|
|
2350
|
-
throw new Error('Modal dialog is visible, but it should not be.');
|
|
2351
|
-
}
|
|
2352
|
-
} else {
|
|
2353
|
-
if (!result.value) {
|
|
2354
|
-
throw new Error('Modal dialog is not visible, but it should be.');
|
|
2355
|
-
}
|
|
2356
|
-
}
|
|
2357
|
-
});
|
|
936
|
+
When(/^(I scroll|we scroll|scrolling)? left(?: (\d+))?$/, async function (pronounCase, numValue) {
|
|
937
|
+
await this.page.evaluate((v) => window.scrollBy(-v, 0), numValue ? parseInt(numValue, 10) : 350);
|
|
2358
938
|
});
|
|
2359
939
|
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
*
|
|
2363
|
-
* Example #1: Then I should see a modal with title "Confirm Action"
|
|
2364
|
-
* Example #2: Then I should see the modal with title "Welcome"
|
|
2365
|
-
* Example #3: Then we should see a modal with title "Welcome Message"
|
|
2366
|
-
* Example #4: Then I should not see a modal with title "Error"
|
|
2367
|
-
* Example #5: Then I should not see the modal with title "Validation Error"
|
|
2368
|
-
*
|
|
2369
|
-
*/
|
|
2370
|
-
Then(/^(I |we )*should( not)* see (a |the )*modal with title "([^"]*)?"$/, function (pronounCase, notCase, aTheCase, title) {
|
|
2371
|
-
return browser.execute(function(searchTitle) {
|
|
2372
|
-
const modals = document.querySelectorAll('[role="dialog"], .modal, .dialog, .popup');
|
|
2373
|
-
|
|
2374
|
-
for (let modal of modals) {
|
|
2375
|
-
const style = window.getComputedStyle(modal);
|
|
2376
|
-
|
|
2377
|
-
// Only check visible modals
|
|
2378
|
-
if (style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0') {
|
|
2379
|
-
const titleAttr = modal.getAttribute('title') || modal.getAttribute('aria-label') || '';
|
|
2380
|
-
const titleElement = modal.querySelector('.modal-title, .dialog-title, h1, h2, h3');
|
|
2381
|
-
const titleText = titleElement ? (titleElement.textContent || titleElement.innerText || '').trim() : '';
|
|
2382
|
-
|
|
2383
|
-
if (titleAttr.includes(searchTitle) || titleText.includes(searchTitle) || titleText === searchTitle) {
|
|
2384
|
-
return true;
|
|
2385
|
-
}
|
|
2386
|
-
}
|
|
2387
|
-
}
|
|
2388
|
-
return false;
|
|
2389
|
-
}, [title], function(result) {
|
|
2390
|
-
if (notCase) {
|
|
2391
|
-
if (result.value) {
|
|
2392
|
-
throw new Error(`Modal with title "${title}" is visible, but it should not be.`);
|
|
2393
|
-
}
|
|
2394
|
-
} else {
|
|
2395
|
-
if (!result.value) {
|
|
2396
|
-
throw new Error(`Modal with title "${title}" is not visible or not found.`);
|
|
2397
|
-
}
|
|
2398
|
-
}
|
|
2399
|
-
});
|
|
940
|
+
When(/^(I scroll|we scroll|scrolling)? to( the)* start( of the page)*$/, async function (pronounCase, theCase, pageCase) {
|
|
941
|
+
await this.page.evaluate(() => window.scrollTo(0, window.scrollY));
|
|
2400
942
|
});
|
|
2401
943
|
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
* Example #1: Then I should see a "confirmation-modal" modal
|
|
2406
|
-
* Example #2: Then I should see the "#delete-modal" modal
|
|
2407
|
-
* Example #3: Then we should see a "settings-modal" modal
|
|
2408
|
-
* Example #4: Then I should not see a "error-modal" modal
|
|
2409
|
-
* Example #5: Then I should not see the "#success-modal" modal
|
|
2410
|
-
*
|
|
2411
|
-
*/
|
|
2412
|
-
Then(/^(I |we )*should( not)* see (a |the )*"([^"]*)?" modal$/, function (pronounCase, notCase, aTheCase, identifier) {
|
|
2413
|
-
return browser.execute(function(searchId) {
|
|
2414
|
-
// Find modal by ID/class selector
|
|
2415
|
-
let modal = null;
|
|
2416
|
-
if (searchId.startsWith('#') || searchId.startsWith('.')) {
|
|
2417
|
-
modal = document.querySelector(searchId);
|
|
2418
|
-
} else {
|
|
2419
|
-
// Search by various attributes
|
|
2420
|
-
modal = document.querySelector(`#${searchId}`) ||
|
|
2421
|
-
document.querySelector(`.${searchId}`) ||
|
|
2422
|
-
document.querySelector(`[data-modal="${searchId}"]`);
|
|
2423
|
-
}
|
|
944
|
+
When(/^(I scroll|we scroll|scrolling)? to( the)* end( of the page)*$/, async function (pronounCase, theCase, pageCase) {
|
|
945
|
+
await this.page.evaluate(() => window.scrollTo(document.body.scrollWidth, window.scrollY));
|
|
946
|
+
});
|
|
2424
947
|
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
948
|
+
When(/^(I scroll|we scroll|scrolling)? to start of "([^"]*)"$/, async function (pronounCase, selector) {
|
|
949
|
+
await this.page.locator(selector).evaluate(el => { el.scrollLeft = 0; });
|
|
950
|
+
});
|
|
2428
951
|
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
return style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0';
|
|
2432
|
-
}, [identifier], function(result) {
|
|
2433
|
-
if (notCase) {
|
|
2434
|
-
if (result.value) {
|
|
2435
|
-
throw new Error(`Modal "${identifier}" is visible, but it should not be.`);
|
|
2436
|
-
}
|
|
2437
|
-
} else {
|
|
2438
|
-
if (!result.value) {
|
|
2439
|
-
throw new Error(`Modal "${identifier}" is not visible or not found.`);
|
|
2440
|
-
}
|
|
2441
|
-
}
|
|
2442
|
-
});
|
|
952
|
+
When(/^(I scroll|we scroll|scrolling)? to end of "([^"]*)"$/, async function (pronounCase, selector) {
|
|
953
|
+
await this.page.locator(selector).evaluate(el => { el.scrollLeft = el.scrollWidth; });
|
|
2443
954
|
});
|
|
2444
955
|
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
*
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
return browser.execute(function(text) {
|
|
2456
|
-
const modalSelectors = [
|
|
2457
|
-
'.modal:not([style*="display: none"])',
|
|
2458
|
-
'.modal.show',
|
|
2459
|
-
'.modal.in',
|
|
2460
|
-
'[role="dialog"]',
|
|
2461
|
-
'.dialog:not([style*="display: none"])',
|
|
2462
|
-
'.popup:not([style*="display: none"])'
|
|
2463
|
-
];
|
|
2464
|
-
|
|
2465
|
-
for (let selector of modalSelectors) {
|
|
2466
|
-
const elements = document.querySelectorAll(selector);
|
|
2467
|
-
for (let element of elements) {
|
|
2468
|
-
const style = window.getComputedStyle(element);
|
|
2469
|
-
if (style.display !== 'none' && style.visibility !== 'hidden') {
|
|
2470
|
-
const modalText = element.textContent || element.innerText || '';
|
|
2471
|
-
if (modalText.includes(text)) {
|
|
2472
|
-
return true;
|
|
2473
|
-
}
|
|
2474
|
-
}
|
|
2475
|
-
}
|
|
2476
|
-
}
|
|
2477
|
-
return false;
|
|
2478
|
-
}, [expectedText], function(result) {
|
|
2479
|
-
if (notCase) {
|
|
2480
|
-
if (result.value) {
|
|
2481
|
-
throw new Error(`Found "${expectedText}" in modal, but it should not be there.`);
|
|
2482
|
-
}
|
|
2483
|
-
} else {
|
|
2484
|
-
if (!result.value) {
|
|
2485
|
-
throw new Error(`Could not find "${expectedText}" in modal.`);
|
|
2486
|
-
}
|
|
2487
|
-
}
|
|
2488
|
-
});
|
|
956
|
+
// ---------------------------------------------------------------------------
|
|
957
|
+
// Modal steps
|
|
958
|
+
// ---------------------------------------------------------------------------
|
|
959
|
+
Then(/^(I |we )*should( not)* see (a |the )*modal( dialog)*$/, async function (pronounCase, notCase, aTheCase, dialogCase) {
|
|
960
|
+
const visible = await isAnyModalVisible(this.page);
|
|
961
|
+
if (notCase) {
|
|
962
|
+
assert.ok(!visible, 'Modal dialog is visible, but it should not be.');
|
|
963
|
+
} else {
|
|
964
|
+
assert.ok(visible, 'Modal dialog is not visible, but it should be.');
|
|
965
|
+
}
|
|
2489
966
|
});
|
|
2490
967
|
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
return browser.execute(function(btnText) {
|
|
2502
|
-
const modalSelectors = [
|
|
2503
|
-
'.modal:not([style*="display: none"])',
|
|
2504
|
-
'.modal.show',
|
|
2505
|
-
'.modal.in',
|
|
2506
|
-
'[role="dialog"]',
|
|
2507
|
-
'.dialog:not([style*="display: none"])',
|
|
2508
|
-
'.popup:not([style*="display: none"])'
|
|
2509
|
-
];
|
|
2510
|
-
|
|
2511
|
-
for (let selector of modalSelectors) {
|
|
2512
|
-
const modals = document.querySelectorAll(selector);
|
|
2513
|
-
for (let modal of modals) {
|
|
2514
|
-
const style = window.getComputedStyle(modal);
|
|
2515
|
-
if (style.display !== 'none' && style.visibility !== 'hidden') {
|
|
2516
|
-
// Find clickable elements within modal
|
|
2517
|
-
const clickables = modal.querySelectorAll('button, a, [role="button"], input[type="button"], input[type="submit"], .btn');
|
|
2518
|
-
|
|
2519
|
-
for (let element of clickables) {
|
|
2520
|
-
const text = (element.textContent || element.innerText || element.value || '').trim();
|
|
2521
|
-
if (text === btnText || text.includes(btnText)) {
|
|
2522
|
-
element.click();
|
|
2523
|
-
return { success: true };
|
|
2524
|
-
}
|
|
2525
|
-
}
|
|
2526
|
-
|
|
2527
|
-
// If not found in obvious clickables, search by text
|
|
2528
|
-
const allElements = modal.querySelectorAll('*');
|
|
2529
|
-
for (let element of allElements) {
|
|
2530
|
-
const text = (element.textContent || element.innerText || '').trim();
|
|
2531
|
-
if (text === btnText && element.offsetParent !== null) {
|
|
2532
|
-
element.click();
|
|
2533
|
-
return { success: true };
|
|
2534
|
-
}
|
|
2535
|
-
}
|
|
2536
|
-
}
|
|
2537
|
-
}
|
|
2538
|
-
}
|
|
2539
|
-
return { success: false, error: `Could not find "${btnText}" button in modal` };
|
|
2540
|
-
}, [buttonText], function(result) {
|
|
2541
|
-
if (!result.value.success) {
|
|
2542
|
-
throw new Error(result.value.error || `Could not click "${buttonText}" in modal`);
|
|
2543
|
-
}
|
|
2544
|
-
});
|
|
968
|
+
Then(/^(I |we )*should( not)* see (a |the )*modal with title "([^"]*)?"$/, async function (pronounCase, notCase, aTheCase, title) {
|
|
969
|
+
const modal = this.page.locator(MODAL_SELECTOR);
|
|
970
|
+
const byHeading = modal.locator('.modal-title, .dialog-title, h1, h2, h3').filter({ hasText: title });
|
|
971
|
+
const byAttr = modal.locator(`[title*="${title}"], [aria-label*="${title}"]`);
|
|
972
|
+
const found = await byHeading.count() > 0 || await byAttr.count() > 0;
|
|
973
|
+
if (notCase) {
|
|
974
|
+
assert.ok(!found, `Modal with title "${title}" is visible, but it should not be.`);
|
|
975
|
+
} else {
|
|
976
|
+
assert.ok(found, `Modal with title "${title}" is not visible or not found.`);
|
|
977
|
+
}
|
|
2545
978
|
});
|
|
2546
979
|
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
return browser.execute(function() {
|
|
2558
|
-
const modalSelectors = [
|
|
2559
|
-
'.modal:not([style*="display: none"])',
|
|
2560
|
-
'.modal.show',
|
|
2561
|
-
'.modal.in',
|
|
2562
|
-
'[role="dialog"]',
|
|
2563
|
-
'.dialog:not([style*="display: none"])',
|
|
2564
|
-
'.popup:not([style*="display: none"])'
|
|
2565
|
-
];
|
|
2566
|
-
|
|
2567
|
-
for (let selector of modalSelectors) {
|
|
2568
|
-
const modals = document.querySelectorAll(selector);
|
|
2569
|
-
for (let modal of modals) {
|
|
2570
|
-
const style = window.getComputedStyle(modal);
|
|
2571
|
-
if (style.display !== 'none' && style.visibility !== 'hidden') {
|
|
2572
|
-
// Try to find close button
|
|
2573
|
-
const closeButtons = modal.querySelectorAll(
|
|
2574
|
-
'.close, .modal-close, [data-dismiss="modal"], [aria-label="Close"], .btn-close, button[class*="close"]'
|
|
2575
|
-
);
|
|
2576
|
-
|
|
2577
|
-
for (let btn of closeButtons) {
|
|
2578
|
-
if (window.getComputedStyle(btn).display !== 'none') {
|
|
2579
|
-
btn.click();
|
|
2580
|
-
return { success: true, method: 'close button' };
|
|
2581
|
-
}
|
|
2582
|
-
}
|
|
2583
|
-
|
|
2584
|
-
// Try ESC key
|
|
2585
|
-
const escEvent = new KeyboardEvent('keydown', {
|
|
2586
|
-
key: 'Escape',
|
|
2587
|
-
code: 'Escape',
|
|
2588
|
-
keyCode: 27,
|
|
2589
|
-
which: 27,
|
|
2590
|
-
bubbles: true
|
|
2591
|
-
});
|
|
2592
|
-
modal.dispatchEvent(escEvent);
|
|
2593
|
-
|
|
2594
|
-
// Check if modal has data-dismiss or onclick handler
|
|
2595
|
-
if (modal.hasAttribute('data-dismiss')) {
|
|
2596
|
-
modal.click();
|
|
2597
|
-
return { success: true, method: 'modal click' };
|
|
2598
|
-
}
|
|
2599
|
-
|
|
2600
|
-
return { success: true, method: 'escape key' };
|
|
2601
|
-
}
|
|
2602
|
-
}
|
|
2603
|
-
}
|
|
2604
|
-
return { success: false, error: 'No visible modal found to close' };
|
|
2605
|
-
}, [], function(result) {
|
|
2606
|
-
if (!result.value.success) {
|
|
2607
|
-
throw new Error(result.value.error || 'Could not close modal');
|
|
2608
|
-
}
|
|
2609
|
-
});
|
|
980
|
+
Then(/^(I |we )*should( not)* see (a |the )*"([^"]*)?" modal$/, async function (pronounCase, notCase, aTheCase, identifier) {
|
|
981
|
+
const selector = (identifier.startsWith('#') || identifier.startsWith('.'))
|
|
982
|
+
? identifier
|
|
983
|
+
: `#${identifier}, .${identifier}, [data-modal="${identifier}"]`;
|
|
984
|
+
const visible = await this.page.locator(selector).first().isVisible();
|
|
985
|
+
if (notCase) {
|
|
986
|
+
assert.ok(!visible, `Modal "${identifier}" is visible, but it should not be.`);
|
|
987
|
+
} else {
|
|
988
|
+
assert.ok(visible, `Modal "${identifier}" is not visible or not found.`);
|
|
989
|
+
}
|
|
2610
990
|
});
|
|
2611
991
|
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
*/
|
|
2621
|
-
When(/^(I |we )*wait for( the)* modal( dialog)* to (appear|disappear)$/, function (pronounCase, theCase, dialogCase, appearOrDisappear) {
|
|
2622
|
-
const shouldAppear = appearOrDisappear === 'appear';
|
|
2623
|
-
const maxWaitTime = 10000; // 10 seconds
|
|
2624
|
-
const pollInterval = 500; // 500ms
|
|
2625
|
-
|
|
2626
|
-
return browser.executeAsync(function(shouldAppear, maxWaitTime, pollInterval, done) {
|
|
2627
|
-
const modalSelectors = [
|
|
2628
|
-
'.modal:not([style*="display: none"])',
|
|
2629
|
-
'.modal.show',
|
|
2630
|
-
'.modal.in',
|
|
2631
|
-
'[role="dialog"]',
|
|
2632
|
-
'.dialog:not([style*="display: none"])',
|
|
2633
|
-
'.popup:not([style*="display: none"])'
|
|
2634
|
-
];
|
|
2635
|
-
|
|
2636
|
-
function checkModal() {
|
|
2637
|
-
for (let selector of modalSelectors) {
|
|
2638
|
-
const elements = document.querySelectorAll(selector);
|
|
2639
|
-
for (let element of elements) {
|
|
2640
|
-
const style = window.getComputedStyle(element);
|
|
2641
|
-
if (style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0') {
|
|
2642
|
-
return true;
|
|
2643
|
-
}
|
|
2644
|
-
}
|
|
2645
|
-
}
|
|
2646
|
-
return false;
|
|
2647
|
-
}
|
|
992
|
+
Then(/^(I |we )*should( not)* see "([^"]*)?" in( the)* modal( dialog)*$/, async function (pronounCase, notCase, expectedText, theCase, dialogCase) {
|
|
993
|
+
const found = await this.page.locator(MODAL_SELECTOR).filter({ hasText: expectedText }).count() > 0;
|
|
994
|
+
if (notCase) {
|
|
995
|
+
assert.ok(!found, `Found "${expectedText}" in modal, but it should not be there.`);
|
|
996
|
+
} else {
|
|
997
|
+
assert.ok(found, `Could not find "${expectedText}" in modal.`);
|
|
998
|
+
}
|
|
999
|
+
});
|
|
2648
1000
|
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
1001
|
+
When(/^(I |we )*click "([^"]*)?"( button)* in( the)* modal( dialog)*$/, async function (pronounCase, buttonText, buttonCase, theCase, dialogCase) {
|
|
1002
|
+
await waitForModalState(this.page, 'visible', 10000);
|
|
1003
|
+
const modal = await findVisibleModal(this.page);
|
|
1004
|
+
await modal.locator('button, a, [role="button"], input[type="button"], input[type="submit"], .btn')
|
|
1005
|
+
.filter({ hasText: buttonText })
|
|
1006
|
+
.first()
|
|
1007
|
+
.click();
|
|
1008
|
+
});
|
|
2652
1009
|
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
1010
|
+
When(/^(I |we )*(close|dismiss)( the)* modal( dialog)*$/, async function (pronounCase, closeOrDismiss, theCase, dialogCase) {
|
|
1011
|
+
await waitForModalState(this.page, 'visible', 10000);
|
|
1012
|
+
const modal = await findVisibleModal(this.page);
|
|
1013
|
+
const closeBtn = modal.locator('.close, .modal-close, [data-dismiss="modal"], [aria-label="Close"], .btn-close, button[class*="close"]').first();
|
|
1014
|
+
if (await closeBtn.isVisible()) {
|
|
1015
|
+
await closeBtn.click();
|
|
1016
|
+
} else {
|
|
1017
|
+
await modal.press('Escape');
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
2658
1020
|
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
done({
|
|
2663
|
-
success: false,
|
|
2664
|
-
error: `Timeout: Modal did not ${shouldAppear ? 'appear' : 'disappear'} within ${maxWaitTime}ms`
|
|
2665
|
-
});
|
|
2666
|
-
}
|
|
2667
|
-
}, pollInterval);
|
|
2668
|
-
}, [shouldAppear, maxWaitTime, pollInterval], function(result) {
|
|
2669
|
-
if (!result.value.success) {
|
|
2670
|
-
throw new Error(result.value.error || `Modal did not ${appearOrDisappear}`);
|
|
2671
|
-
}
|
|
2672
|
-
});
|
|
1021
|
+
When(/^(I |we )*wait for( the)* modal( dialog)* to (appear|disappear)$/, async function (pronounCase, theCase, dialogCase, appearOrDisappear) {
|
|
1022
|
+
const state = appearOrDisappear === 'appear' ? 'visible' : 'hidden';
|
|
1023
|
+
await waitForModalState(this.page, state, 10000);
|
|
2673
1024
|
});
|