codeceptjs 3.2.3 → 3.3.0-beta.4
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/CHANGELOG.md +50 -0
- package/docs/advanced.md +0 -4
- package/docs/api.md +227 -188
- package/docs/build/ApiDataFactory.js +13 -6
- package/docs/build/Appium.js +36 -36
- package/docs/build/GraphQL.js +11 -0
- package/docs/build/JSONResponse.js +297 -0
- package/docs/build/Nightmare.js +48 -48
- package/docs/build/Playwright.js +261 -146
- package/docs/build/Puppeteer.js +76 -67
- package/docs/build/REST.js +36 -0
- package/docs/build/TestCafe.js +44 -44
- package/docs/build/WebDriver.js +69 -69
- package/docs/helpers/ApiDataFactory.md +7 -0
- package/docs/helpers/Appium.md +3 -3
- package/docs/helpers/JSONResponse.md +230 -0
- package/docs/helpers/Playwright.md +282 -218
- package/docs/helpers/Puppeteer.md +9 -1
- package/docs/helpers/REST.md +30 -9
- package/docs/installation.md +2 -0
- package/docs/internal-api.md +265 -0
- package/docs/playwright.md +70 -15
- package/docs/plugins.md +125 -29
- package/docs/puppeteer.md +24 -8
- package/docs/quickstart.md +2 -3
- package/docs/reports.md +43 -2
- package/docs/translation.md +1 -1
- package/docs/videos.md +2 -2
- package/docs/webdriver.md +90 -2
- package/lib/command/init.js +5 -15
- package/lib/config.js +17 -13
- package/lib/helper/ApiDataFactory.js +13 -6
- package/lib/helper/Appium.js +3 -3
- package/lib/helper/GraphQL.js +11 -0
- package/lib/helper/JSONResponse.js +297 -0
- package/lib/helper/Playwright.js +199 -84
- package/lib/helper/Puppeteer.js +12 -3
- package/lib/helper/REST.js +36 -0
- package/lib/helper/extras/Console.js +8 -0
- package/lib/helper/extras/PlaywrightRestartOpts.js +35 -0
- package/lib/interfaces/bdd.js +3 -1
- package/lib/plugin/allure.js +12 -0
- package/lib/plugin/eachElement.js +127 -0
- package/lib/utils.js +20 -0
- package/package.json +24 -23
- package/translations/pt-BR.js +8 -0
- package/typings/index.d.ts +2 -0
- package/typings/types.d.ts +237 -11
package/lib/helper/Playwright.js
CHANGED
|
@@ -19,6 +19,7 @@ const {
|
|
|
19
19
|
getNormalizedKeyAttributeValue,
|
|
20
20
|
isModifierKey,
|
|
21
21
|
clearString,
|
|
22
|
+
requireWithFallback,
|
|
22
23
|
} = require('../utils');
|
|
23
24
|
const {
|
|
24
25
|
isColorProperty,
|
|
@@ -38,6 +39,9 @@ const popupStore = new Popup();
|
|
|
38
39
|
const consoleLogStore = new Console();
|
|
39
40
|
const availableBrowsers = ['chromium', 'webkit', 'firefox', 'electron'];
|
|
40
41
|
|
|
42
|
+
const {
|
|
43
|
+
setRestartStrategy, restartsSession, restartsContext, restartsBrowser,
|
|
44
|
+
} = require('./extras/PlaywrightRestartOpts');
|
|
41
45
|
const { createValueEngine, createDisabledEngine } = require('./extras/PlaywrightPropEngine');
|
|
42
46
|
|
|
43
47
|
/**
|
|
@@ -49,12 +53,18 @@ const { createValueEngine, createDisabledEngine } = require('./extras/Playwright
|
|
|
49
53
|
*
|
|
50
54
|
* This helper works with a browser out of the box with no additional tools required to install.
|
|
51
55
|
*
|
|
52
|
-
* Requires `playwright` package version ^1 to be installed:
|
|
56
|
+
* Requires `playwright` or `playwright-core` package version ^1 to be installed:
|
|
53
57
|
*
|
|
54
58
|
* ```
|
|
55
|
-
* npm i playwright@^1 --save
|
|
59
|
+
* npm i playwright@^1.18 --save
|
|
60
|
+
* ```
|
|
61
|
+
* or
|
|
62
|
+
* ```
|
|
63
|
+
* npm i playwright-core@^1.18 --save
|
|
56
64
|
* ```
|
|
57
65
|
*
|
|
66
|
+
* Using playwright-core package, will prevent the download of browser binaries and allow connecting to an existing browser installation or for connecting to a remote one.
|
|
67
|
+
*
|
|
58
68
|
* ## Configuration
|
|
59
69
|
*
|
|
60
70
|
* This helper should be configured in codecept.json or codecept.conf.js
|
|
@@ -62,15 +72,19 @@ const { createValueEngine, createDisabledEngine } = require('./extras/Playwright
|
|
|
62
72
|
* * `url`: base url of website to be tested
|
|
63
73
|
* * `browser`: a browser to test on, either: `chromium`, `firefox`, `webkit`, `electron`. Default: chromium.
|
|
64
74
|
* * `show`: (optional, default: false) - show browser window.
|
|
65
|
-
* * `restart`: (optional, default:
|
|
75
|
+
* * `restart`: (optional, default: false) - restart strategy between tests. Possible values:
|
|
76
|
+
* * 'context' or **false** - restarts [browser context](https://playwright.dev/docs/api/class-browsercontext) but keeps running browser. Recommended by Playwright team to keep tests isolated.
|
|
77
|
+
* * 'browser' or **true** - closes browser and opens it again between tests.
|
|
78
|
+
* * 'session' or 'keep' - keeps browser context and session, but cleans up cookies and localStorage between tests. The fastest option when running tests in windowed mode. Works with `keepCookies` and `keepBrowserState` options. This behavior was default before CodeceptJS 3.1
|
|
79
|
+
* * `timeout`: (optional, default: 1000) - [timeout](https://playwright.dev/docs/api/class-page#page-set-default-timeout) in ms of all Playwright actions .
|
|
66
80
|
* * `disableScreenshots`: (optional, default: false) - don't save screenshot on failure.
|
|
67
81
|
* * `emulate`: (optional, default: {}) launch browser in device emulation mode.
|
|
68
82
|
* * `video`: (optional, default: false) enables video recording for failed tests; videos are saved into `output/videos` folder
|
|
69
83
|
* * `trace`: (optional, default: false) record [tracing information](https://playwright.dev/docs/trace-viewer) with screenshots and snapshots.
|
|
70
84
|
* * `fullPageScreenshots` (optional, default: false) - make full page screenshots on failure.
|
|
71
85
|
* * `uniqueScreenshotNames`: (optional, default: false) - option to prevent screenshot override if you have scenarios with the same name in different suites.
|
|
72
|
-
* * `keepBrowserState`: (optional, default: false) - keep browser state between tests when `restart` is set to
|
|
73
|
-
* * `keepCookies`: (optional, default: false) - keep cookies between tests when `restart` is set to
|
|
86
|
+
* * `keepBrowserState`: (optional, default: false) - keep browser state between tests when `restart` is set to 'session'.
|
|
87
|
+
* * `keepCookies`: (optional, default: false) - keep cookies between tests when `restart` is set to 'session'.
|
|
74
88
|
* * `waitForAction`: (optional) how long to wait after click, doubleClick or PressKey actions in ms. Default: 100.
|
|
75
89
|
* * `waitForNavigation`: (optional, default: 'load'). When to consider navigation succeeded. Possible options: `load`, `domcontentloaded`, `networkidle`. Choose one of those options is possible. See [Playwright API](https://github.com/microsoft/playwright/blob/main/docs/api.md#pagewaitfornavigationoptions).
|
|
76
90
|
* * `pressKeyDelay`: (optional, default: '10'). Delay between key presses in ms. Used when calling Playwrights page.type(...) in fillField/appendField
|
|
@@ -235,7 +249,7 @@ class Playwright extends Helper {
|
|
|
235
249
|
constructor(config) {
|
|
236
250
|
super(config);
|
|
237
251
|
|
|
238
|
-
playwright =
|
|
252
|
+
playwright = requireWithFallback('playwright', 'playwright-core');
|
|
239
253
|
|
|
240
254
|
// set defaults
|
|
241
255
|
this.isRemoteBrowser = false;
|
|
@@ -259,8 +273,10 @@ class Playwright extends Helper {
|
|
|
259
273
|
waitForAction: 100,
|
|
260
274
|
waitForTimeout: 1000,
|
|
261
275
|
pressKeyDelay: 10,
|
|
276
|
+
timeout: 1000,
|
|
262
277
|
fullPageScreenshots: false,
|
|
263
278
|
disableScreenshots: false,
|
|
279
|
+
ignoreLog: ['warning', 'log'],
|
|
264
280
|
uniqueScreenshotNames: false,
|
|
265
281
|
manualStart: false,
|
|
266
282
|
getPageTimeout: 0,
|
|
@@ -270,6 +286,7 @@ class Playwright extends Helper {
|
|
|
270
286
|
keepBrowserState: false,
|
|
271
287
|
show: false,
|
|
272
288
|
defaultPopupAction: 'accept',
|
|
289
|
+
use: { actionTimeout: 0 },
|
|
273
290
|
ignoreHTTPSErrors: false, // Adding it here o that context can be set up to ignore the SSL errors
|
|
274
291
|
};
|
|
275
292
|
|
|
@@ -297,6 +314,7 @@ class Playwright extends Helper {
|
|
|
297
314
|
|
|
298
315
|
_setConfig(config) {
|
|
299
316
|
this.options = this._validateConfig(config);
|
|
317
|
+
setRestartStrategy(this.options);
|
|
300
318
|
this.playwrightOptions = {
|
|
301
319
|
headless: !this.options.show,
|
|
302
320
|
...this._getOptionsForBrowser(config),
|
|
@@ -334,9 +352,9 @@ class Playwright extends Helper {
|
|
|
334
352
|
|
|
335
353
|
static _checkRequirements() {
|
|
336
354
|
try {
|
|
337
|
-
|
|
355
|
+
requireWithFallback('playwright', 'playwright-core');
|
|
338
356
|
} catch (e) {
|
|
339
|
-
return ['playwright@^1'];
|
|
357
|
+
return ['playwright@^1.18'];
|
|
340
358
|
}
|
|
341
359
|
}
|
|
342
360
|
|
|
@@ -353,7 +371,7 @@ class Playwright extends Helper {
|
|
|
353
371
|
}
|
|
354
372
|
|
|
355
373
|
_beforeSuite() {
|
|
356
|
-
if (
|
|
374
|
+
if ((restartsSession() || restartsContext()) && !this.options.manualStart && !this.isRunning) {
|
|
357
375
|
this.debugSection('Session', 'Starting singleton browser session');
|
|
358
376
|
return this._startBrowser();
|
|
359
377
|
}
|
|
@@ -371,7 +389,7 @@ class Playwright extends Helper {
|
|
|
371
389
|
},
|
|
372
390
|
});
|
|
373
391
|
|
|
374
|
-
if (
|
|
392
|
+
if (restartsBrowser() && !this.options.manualStart) await this._startBrowser();
|
|
375
393
|
if (!this.isRunning && !this.options.manualStart) await this._startBrowser();
|
|
376
394
|
|
|
377
395
|
this.isAuthenticated = false;
|
|
@@ -393,7 +411,9 @@ class Playwright extends Helper {
|
|
|
393
411
|
if (this.storageState) contextOptions.storageState = this.storageState;
|
|
394
412
|
if (this.options.userAgent) contextOptions.userAgent = this.options.userAgent;
|
|
395
413
|
if (this.options.locale) contextOptions.locale = this.options.locale;
|
|
396
|
-
this.browserContext
|
|
414
|
+
if (!this.browserContext || !restartsSession()) {
|
|
415
|
+
this.browserContext = await this.browser.newContext(contextOptions); // Adding the HTTPSError ignore in the context so that we can ignore those errors
|
|
416
|
+
}
|
|
397
417
|
}
|
|
398
418
|
|
|
399
419
|
let mainPage;
|
|
@@ -421,7 +441,11 @@ class Playwright extends Helper {
|
|
|
421
441
|
return;
|
|
422
442
|
}
|
|
423
443
|
|
|
424
|
-
if (
|
|
444
|
+
if (restartsSession()) {
|
|
445
|
+
return refreshContextSession.bind(this)();
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if (restartsBrowser()) {
|
|
425
449
|
this.isRunning = false;
|
|
426
450
|
return this._stopBrowser();
|
|
427
451
|
}
|
|
@@ -443,11 +467,10 @@ class Playwright extends Helper {
|
|
|
443
467
|
return this.browser;
|
|
444
468
|
}
|
|
445
469
|
|
|
446
|
-
_afterSuite() {
|
|
447
|
-
}
|
|
470
|
+
_afterSuite() {}
|
|
448
471
|
|
|
449
|
-
_finishTest() {
|
|
450
|
-
if (
|
|
472
|
+
async _finishTest() {
|
|
473
|
+
if ((restartsSession() || restartsContext()) && this.isRunning) return this._stopBrowser();
|
|
451
474
|
}
|
|
452
475
|
|
|
453
476
|
_session() {
|
|
@@ -506,16 +529,16 @@ class Playwright extends Helper {
|
|
|
506
529
|
* First argument is a description of an action.
|
|
507
530
|
* Second argument is async function that gets this helper as parameter.
|
|
508
531
|
*
|
|
509
|
-
* { [`page`](https://github.com/microsoft/playwright/blob/main/docs/src/api/class-page.md), [`
|
|
532
|
+
* { [`page`](https://github.com/microsoft/playwright/blob/main/docs/src/api/class-page.md), [`browserContext`](https://github.com/microsoft/playwright/blob/main/docs/src/api/class-browsercontext.md) [`browser`](https://github.com/microsoft/playwright/blob/main/docs/src/api/class-browser.md) } objects from Playwright API are available.
|
|
510
533
|
*
|
|
511
534
|
* ```js
|
|
512
|
-
* I.usePlaywrightTo('emulate offline mode', async ({
|
|
513
|
-
* await
|
|
535
|
+
* I.usePlaywrightTo('emulate offline mode', async ({ browserContext }) => {
|
|
536
|
+
* await browserContext.setOffline(true);
|
|
514
537
|
* });
|
|
515
538
|
* ```
|
|
516
539
|
*
|
|
517
540
|
* @param {string} description used to show in logs.
|
|
518
|
-
* @param {function} fn async
|
|
541
|
+
* @param {function} fn async function that executed with Playwright helper as argument
|
|
519
542
|
*/
|
|
520
543
|
usePlaywrightTo(description, fn) {
|
|
521
544
|
return this._useTo(...arguments);
|
|
@@ -583,7 +606,9 @@ class Playwright extends Helper {
|
|
|
583
606
|
this._addPopupListener(page);
|
|
584
607
|
this.page = page;
|
|
585
608
|
if (!page) return;
|
|
609
|
+
this.browserContext.setDefaultTimeout(0);
|
|
586
610
|
page.setDefaultNavigationTimeout(this.options.getPageTimeout);
|
|
611
|
+
page.setDefaultTimeout(this.options.timeout);
|
|
587
612
|
|
|
588
613
|
page.on('crash', async () => {
|
|
589
614
|
console.log('ERROR: Page has crashed, closing page!');
|
|
@@ -684,7 +709,6 @@ class Playwright extends Helper {
|
|
|
684
709
|
this._setPage(null);
|
|
685
710
|
this.context = null;
|
|
686
711
|
popupStore.clear();
|
|
687
|
-
|
|
688
712
|
await this.browser.close();
|
|
689
713
|
}
|
|
690
714
|
|
|
@@ -826,9 +850,21 @@ class Playwright extends Helper {
|
|
|
826
850
|
|
|
827
851
|
/**
|
|
828
852
|
* {{> dragAndDrop }}
|
|
853
|
+
*
|
|
854
|
+
* [Additional options](https://playwright.dev/docs/api/class-page#page-drag-and-drop) can be passed as 3rd argument.
|
|
855
|
+
*
|
|
856
|
+
* ```js
|
|
857
|
+
* // specify coordinates for source position
|
|
858
|
+
* I.dragAndDrop('img.src', 'img.dst', { sourcePosition: {x: 10, y: 10} })
|
|
859
|
+
* ```
|
|
860
|
+
*
|
|
861
|
+
* > By default option `force: true` is set
|
|
829
862
|
*/
|
|
830
|
-
async dragAndDrop(srcElement, destElement) {
|
|
831
|
-
|
|
863
|
+
async dragAndDrop(srcElement, destElement, options = { force: true }) {
|
|
864
|
+
const src = new Locator(srcElement, 'css');
|
|
865
|
+
const dst = new Locator(destElement, 'css');
|
|
866
|
+
|
|
867
|
+
return this.page.dragAndDrop(buildLocatorString(src), buildLocatorString(dst), options);
|
|
832
868
|
}
|
|
833
869
|
|
|
834
870
|
/**
|
|
@@ -1168,10 +1204,21 @@ class Playwright extends Helper {
|
|
|
1168
1204
|
/**
|
|
1169
1205
|
* {{> click }}
|
|
1170
1206
|
*
|
|
1207
|
+
* [Additional options](https://playwright.dev/docs/api/class-page#page-click) for click available as 3rd argument.
|
|
1208
|
+
*
|
|
1209
|
+
* Examples:
|
|
1210
|
+
*
|
|
1211
|
+
* ```js
|
|
1212
|
+
* // click on element at position
|
|
1213
|
+
* I.click('canvas', '.model', { position: { x: 20, y: 40 } })
|
|
1214
|
+
*
|
|
1215
|
+
* // make ctrl-click
|
|
1216
|
+
* I.click('.edit', null, { modifiers: ['Ctrl'] } )
|
|
1217
|
+
* ```
|
|
1171
1218
|
*
|
|
1172
1219
|
*/
|
|
1173
|
-
async click(locator, context = null) {
|
|
1174
|
-
return proceedClick.call(this, locator, context);
|
|
1220
|
+
async click(locator, context = null, opts = {}) {
|
|
1221
|
+
return proceedClick.call(this, locator, context, opts);
|
|
1175
1222
|
}
|
|
1176
1223
|
|
|
1177
1224
|
/**
|
|
@@ -1210,30 +1257,40 @@ class Playwright extends Helper {
|
|
|
1210
1257
|
|
|
1211
1258
|
/**
|
|
1212
1259
|
* {{> checkOption }}
|
|
1260
|
+
*
|
|
1261
|
+
* [Additional options](https://playwright.dev/docs/api/class-elementhandle#element-handle-check) for check available as 3rd argument.
|
|
1262
|
+
*
|
|
1263
|
+
* Examples:
|
|
1264
|
+
*
|
|
1265
|
+
* ```js
|
|
1266
|
+
* // click on element at position
|
|
1267
|
+
* I.checkOption('Agree', '.signup', { position: { x: 5, y: 5 } })
|
|
1268
|
+
* ```
|
|
1269
|
+
* > ⚠️ To avoid flakiness, option `force: true` is set by default
|
|
1213
1270
|
*/
|
|
1214
|
-
async checkOption(field, context = null) {
|
|
1271
|
+
async checkOption(field, context = null, options = { force: true }) {
|
|
1215
1272
|
const elm = await this._locateCheckable(field, context);
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
// Only check if NOT currently checked
|
|
1219
|
-
if (!curentlyChecked) {
|
|
1220
|
-
await elm.click();
|
|
1221
|
-
return this._waitForAction();
|
|
1222
|
-
}
|
|
1273
|
+
await elm.check(options);
|
|
1274
|
+
return this._waitForAction();
|
|
1223
1275
|
}
|
|
1224
1276
|
|
|
1225
1277
|
/**
|
|
1226
1278
|
* {{> uncheckOption }}
|
|
1279
|
+
*
|
|
1280
|
+
* [Additional options](https://playwright.dev/docs/api/class-elementhandle#element-handle-uncheck) for uncheck available as 3rd argument.
|
|
1281
|
+
*
|
|
1282
|
+
* Examples:
|
|
1283
|
+
*
|
|
1284
|
+
* ```js
|
|
1285
|
+
* // click on element at position
|
|
1286
|
+
* I.uncheckOption('Agree', '.signup', { position: { x: 5, y: 5 } })
|
|
1287
|
+
* ```
|
|
1288
|
+
* > ⚠️ To avoid flakiness, option `force: true` is set by default
|
|
1227
1289
|
*/
|
|
1228
|
-
async uncheckOption(field, context = null) {
|
|
1290
|
+
async uncheckOption(field, context = null, options = { force: true }) {
|
|
1229
1291
|
const elm = await this._locateCheckable(field, context);
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
// Only uncheck if currently checked
|
|
1233
|
-
if (curentlyChecked) {
|
|
1234
|
-
await elm.click();
|
|
1235
|
-
return this._waitForAction();
|
|
1236
|
-
}
|
|
1292
|
+
await elm.uncheck(options);
|
|
1293
|
+
return this._waitForAction();
|
|
1237
1294
|
}
|
|
1238
1295
|
|
|
1239
1296
|
/**
|
|
@@ -1881,6 +1938,53 @@ class Playwright extends Helper {
|
|
|
1881
1938
|
return this.page.screenshot({ path: outputFile, fullPage: fullPageOption, type: 'png' });
|
|
1882
1939
|
}
|
|
1883
1940
|
|
|
1941
|
+
/**
|
|
1942
|
+
* Performs [api request](https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-get) using
|
|
1943
|
+
* the cookies from the current browser session.
|
|
1944
|
+
*
|
|
1945
|
+
* ```js
|
|
1946
|
+
* const users = await I.makeApiRequest('GET', '/api/users', { params: { page: 1 }});
|
|
1947
|
+
* users[0]
|
|
1948
|
+
* I.makeApiRequest('PATCH', )
|
|
1949
|
+
* ```
|
|
1950
|
+
*
|
|
1951
|
+
* > This is Playwright's built-in alternative to using REST helper's sendGet, sendPost, etc methods.
|
|
1952
|
+
*
|
|
1953
|
+
* @param {string} method HTTP method
|
|
1954
|
+
* @param {string} url endpoint
|
|
1955
|
+
* @param {object} options request options depending on method used
|
|
1956
|
+
* @returns {Promise<object>} response
|
|
1957
|
+
*/
|
|
1958
|
+
async makeApiRequest(method, url, options) {
|
|
1959
|
+
method = method.toLowerCase();
|
|
1960
|
+
const allowedMethods = ['get', 'post', 'patch', 'head', 'fetch', 'delete'];
|
|
1961
|
+
if (!allowedMethods.includes(method)) {
|
|
1962
|
+
throw new Error(`Method ${method} is not allowed, use the one from a list ${allowedMethods} or switch to using REST helper`);
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
if (url.startsWith('/')) { // local url
|
|
1966
|
+
url = this.options.url + url;
|
|
1967
|
+
this.debugSection('URL', url);
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
const response = await this.page.request[method](url, options);
|
|
1971
|
+
this.debugSection('Status', response.status());
|
|
1972
|
+
this.debugSection('Response', await response.text());
|
|
1973
|
+
|
|
1974
|
+
// hook to allow JSON response handle this
|
|
1975
|
+
if (this.config.onResponse) {
|
|
1976
|
+
const axiosResponse = {
|
|
1977
|
+
data: await response.json(),
|
|
1978
|
+
status: response.status(),
|
|
1979
|
+
statusText: response.statusText(),
|
|
1980
|
+
headers: response.headers(),
|
|
1981
|
+
};
|
|
1982
|
+
this.config.onResponse(axiosResponse);
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
return response;
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1884
1988
|
async _failed(test) {
|
|
1885
1989
|
await this._withinEnd();
|
|
1886
1990
|
|
|
@@ -2489,8 +2593,7 @@ async function findCheckable(locator, context) {
|
|
|
2489
2593
|
async function proceedIsChecked(assertType, option) {
|
|
2490
2594
|
let els = await findCheckable.call(this, option);
|
|
2491
2595
|
assertElementExists(els, option, 'Checkable');
|
|
2492
|
-
els = await Promise.all(els.map(el => el.
|
|
2493
|
-
els = await Promise.all(els.map(el => el.jsonValue()));
|
|
2596
|
+
els = await Promise.all(els.map(el => el.isChecked()));
|
|
2494
2597
|
const selected = els.reduce((prev, cur) => prev || cur);
|
|
2495
2598
|
return truth(`checkable ${option}`, 'to be checked')[assertType](selected);
|
|
2496
2599
|
}
|
|
@@ -2518,36 +2621,6 @@ async function findFields(locator) {
|
|
|
2518
2621
|
return this._locate({ css: locator });
|
|
2519
2622
|
}
|
|
2520
2623
|
|
|
2521
|
-
async function proceedDragAndDrop(sourceLocator, destinationLocator) {
|
|
2522
|
-
// modern drag and drop in Playwright
|
|
2523
|
-
if (this.page.dragAndDrop) {
|
|
2524
|
-
const source = new Locator(sourceLocator);
|
|
2525
|
-
const dest = new Locator(destinationLocator);
|
|
2526
|
-
if (source.isBasic() && dest.isBasic()) {
|
|
2527
|
-
return this.page.dragAndDrop(source.simplify(), dest.simplify());
|
|
2528
|
-
}
|
|
2529
|
-
}
|
|
2530
|
-
|
|
2531
|
-
const src = await this._locate(sourceLocator);
|
|
2532
|
-
assertElementExists(src, sourceLocator, 'Source Element');
|
|
2533
|
-
|
|
2534
|
-
const dst = await this._locate(destinationLocator);
|
|
2535
|
-
assertElementExists(dst, destinationLocator, 'Destination Element');
|
|
2536
|
-
|
|
2537
|
-
// Note: Using clickablePoint private api becaues the .BoundingBox does not take into account iframe offsets!
|
|
2538
|
-
const dragSource = await clickablePoint(src[0]);
|
|
2539
|
-
const dragDestination = await clickablePoint(dst[0]);
|
|
2540
|
-
|
|
2541
|
-
// Drag start point
|
|
2542
|
-
await this.page.mouse.move(dragSource.x, dragSource.y, { steps: 5 });
|
|
2543
|
-
await this.page.mouse.down();
|
|
2544
|
-
|
|
2545
|
-
// Drag destination
|
|
2546
|
-
await this.page.mouse.move(dragDestination.x, dragDestination.y, { steps: 5 });
|
|
2547
|
-
await this.page.mouse.up();
|
|
2548
|
-
await this._waitForAction();
|
|
2549
|
-
}
|
|
2550
|
-
|
|
2551
2624
|
async function proceedSeeInField(assertType, field, value) {
|
|
2552
2625
|
const els = await findFields.call(this, field);
|
|
2553
2626
|
assertElementExists(els, field, 'Field');
|
|
@@ -2574,14 +2647,15 @@ async function proceedSeeInField(assertType, field, value) {
|
|
|
2574
2647
|
};
|
|
2575
2648
|
|
|
2576
2649
|
if (tag === 'SELECT') {
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2650
|
+
if (await el.getProperty('multiple')) {
|
|
2651
|
+
const selectedOptions = await el.$$('option:checked');
|
|
2652
|
+
if (!selectedOptions.length) return null;
|
|
2653
|
+
|
|
2654
|
+
const options = await filterFieldsByValue(selectedOptions, value, true);
|
|
2655
|
+
return proceedMultiple(options);
|
|
2581
2656
|
}
|
|
2582
2657
|
|
|
2583
|
-
|
|
2584
|
-
return proceedMultiple(options);
|
|
2658
|
+
return el.inputValue();
|
|
2585
2659
|
}
|
|
2586
2660
|
|
|
2587
2661
|
if (tag === 'INPUT') {
|
|
@@ -2597,7 +2671,8 @@ async function proceedSeeInField(assertType, field, value) {
|
|
|
2597
2671
|
}
|
|
2598
2672
|
return proceedMultiple(els[0]);
|
|
2599
2673
|
}
|
|
2600
|
-
|
|
2674
|
+
|
|
2675
|
+
const fieldVal = await el.inputValue();
|
|
2601
2676
|
return stringIncludes(`fields by ${field}`)[assertType](value, fieldVal);
|
|
2602
2677
|
}
|
|
2603
2678
|
|
|
@@ -2628,10 +2703,10 @@ async function filterFieldsBySelectionState(elements, state) {
|
|
|
2628
2703
|
}
|
|
2629
2704
|
|
|
2630
2705
|
async function elementSelected(element) {
|
|
2631
|
-
const type = await element.getProperty('type').then(el => el.jsonValue());
|
|
2706
|
+
const type = await element.getProperty('type').then(el => !!el && el.jsonValue());
|
|
2632
2707
|
|
|
2633
2708
|
if (type === 'checkbox' || type === 'radio') {
|
|
2634
|
-
return element.
|
|
2709
|
+
return element.isChecked();
|
|
2635
2710
|
}
|
|
2636
2711
|
return element.getProperty('selected').then(el => el.jsonValue());
|
|
2637
2712
|
}
|
|
@@ -2679,12 +2754,18 @@ async function targetCreatedHandler(page) {
|
|
|
2679
2754
|
});
|
|
2680
2755
|
});
|
|
2681
2756
|
page.on('console', (msg) => {
|
|
2682
|
-
|
|
2757
|
+
if (!consoleLogStore.includes(msg) && this.options.ignoreLog && !this.options.ignoreLog.includes(msg.type())) {
|
|
2758
|
+
this.debugSection(`Browser:${ucfirst(msg.type())}`, (msg.text && msg.text() || msg._text || '') + msg.args().join(' '));
|
|
2759
|
+
}
|
|
2683
2760
|
consoleLogStore.add(msg);
|
|
2684
2761
|
});
|
|
2685
2762
|
|
|
2686
2763
|
if (this.options.windowSize && this.options.windowSize.indexOf('x') > 0 && this._getType() === 'Browser') {
|
|
2687
|
-
|
|
2764
|
+
try {
|
|
2765
|
+
await page.setViewportSize(parseWindowSize(this.options.windowSize));
|
|
2766
|
+
} catch (err) {
|
|
2767
|
+
// target can be already closed, ignoring...
|
|
2768
|
+
}
|
|
2688
2769
|
}
|
|
2689
2770
|
}
|
|
2690
2771
|
|
|
@@ -2774,3 +2855,37 @@ async function clickablePoint(el) {
|
|
|
2774
2855
|
} = rect;
|
|
2775
2856
|
return { x: x + width / 2, y: y + height / 2 };
|
|
2776
2857
|
}
|
|
2858
|
+
|
|
2859
|
+
async function refreshContextSession() {
|
|
2860
|
+
// close other sessions
|
|
2861
|
+
try {
|
|
2862
|
+
const contexts = await this.browser.contexts();
|
|
2863
|
+
contexts.shift();
|
|
2864
|
+
|
|
2865
|
+
await Promise.all(contexts.map(c => c.close()));
|
|
2866
|
+
} catch (e) {
|
|
2867
|
+
console.log(e);
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
if (this.page) {
|
|
2871
|
+
const existingPages = await this.browserContext.pages();
|
|
2872
|
+
await this._setPage(existingPages[0]);
|
|
2873
|
+
}
|
|
2874
|
+
|
|
2875
|
+
if (this.options.keepBrowserState) return;
|
|
2876
|
+
|
|
2877
|
+
if (!this.options.keepCookies) {
|
|
2878
|
+
this.debugSection('Session', 'cleaning cookies and localStorage');
|
|
2879
|
+
await this.clearCookie();
|
|
2880
|
+
}
|
|
2881
|
+
const currentUrl = await this.grabCurrentUrl();
|
|
2882
|
+
|
|
2883
|
+
if (currentUrl.startsWith('http')) {
|
|
2884
|
+
await this.executeScript('localStorage.clear();').catch((err) => {
|
|
2885
|
+
if (!(err.message.indexOf("Storage is disabled inside 'data:' URLs.") > -1)) throw err;
|
|
2886
|
+
});
|
|
2887
|
+
await this.executeScript('sessionStorage.clear();').catch((err) => {
|
|
2888
|
+
if (!(err.message.indexOf("Storage is disabled inside 'data:' URLs.") > -1)) throw err;
|
|
2889
|
+
});
|
|
2890
|
+
}
|
|
2891
|
+
}
|
package/lib/helper/Puppeteer.js
CHANGED
|
@@ -22,6 +22,7 @@ const {
|
|
|
22
22
|
screenshotOutputFolder,
|
|
23
23
|
getNormalizedKeyAttributeValue,
|
|
24
24
|
isModifierKey,
|
|
25
|
+
requireWithFallback,
|
|
25
26
|
} = require('../utils');
|
|
26
27
|
const {
|
|
27
28
|
isColorProperty,
|
|
@@ -43,7 +44,15 @@ const consoleLogStore = new Console();
|
|
|
43
44
|
* Browser control is executed via DevTools Protocol (instead of Selenium).
|
|
44
45
|
* This helper works with a browser out of the box with no additional tools required to install.
|
|
45
46
|
*
|
|
46
|
-
* Requires `puppeteer` package to be installed.
|
|
47
|
+
* Requires `puppeteer` or `puppeteer-core` package to be installed.
|
|
48
|
+
* ```
|
|
49
|
+
* npm i puppeteer --save
|
|
50
|
+
* ```
|
|
51
|
+
* or
|
|
52
|
+
* ```
|
|
53
|
+
* npm i puppeteer-core --save
|
|
54
|
+
* ```
|
|
55
|
+
* Using `puppeteer-core` package, will prevent the download of browser binaries and allow connecting to an existing browser installation or for connecting to a remote one.
|
|
47
56
|
*
|
|
48
57
|
* > Experimental Firefox support [can be activated](https://codecept.io/helpers/Puppeteer-firefox).
|
|
49
58
|
*
|
|
@@ -182,7 +191,7 @@ class Puppeteer extends Helper {
|
|
|
182
191
|
constructor(config) {
|
|
183
192
|
super(config);
|
|
184
193
|
|
|
185
|
-
puppeteer =
|
|
194
|
+
puppeteer = requireWithFallback('puppeteer', 'puppeteer-core');
|
|
186
195
|
|
|
187
196
|
// set defaults
|
|
188
197
|
this.isRemoteBrowser = false;
|
|
@@ -245,7 +254,7 @@ class Puppeteer extends Helper {
|
|
|
245
254
|
|
|
246
255
|
static _checkRequirements() {
|
|
247
256
|
try {
|
|
248
|
-
|
|
257
|
+
requireWithFallback('puppeteer', 'puppeteer-core');
|
|
249
258
|
} catch (e) {
|
|
250
259
|
return ['puppeteer'];
|
|
251
260
|
}
|
package/lib/helper/REST.js
CHANGED
|
@@ -63,6 +63,12 @@ class REST extends Helper {
|
|
|
63
63
|
this.axios.defaults.headers = this.options.defaultHeaders;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
static _config() {
|
|
67
|
+
return [
|
|
68
|
+
{ name: 'endpoint', message: 'Endpoint of API you are going to test', default: 'http://localhost:3000/api' },
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
|
|
66
72
|
static _checkRequirements() {
|
|
67
73
|
try {
|
|
68
74
|
require('axios');
|
|
@@ -71,6 +77,33 @@ class REST extends Helper {
|
|
|
71
77
|
}
|
|
72
78
|
}
|
|
73
79
|
|
|
80
|
+
_before() {
|
|
81
|
+
this.headers = { ...this.options.defaultHeaders };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Sets request headers for all requests of this test
|
|
86
|
+
*
|
|
87
|
+
* @param {object} headers headers list
|
|
88
|
+
*/
|
|
89
|
+
haveRequestHeaders(headers) {
|
|
90
|
+
this.headers = { ...headers, ...this.headers };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Adds a header for Bearer authentication
|
|
95
|
+
*
|
|
96
|
+
* ```js
|
|
97
|
+
* // we use secret function to hide token from logs
|
|
98
|
+
* I.amBearerAuthenticated(secret('heregoestoken'))
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @param {string} accessToken Bearer access token
|
|
102
|
+
*/
|
|
103
|
+
amBearerAuthenticated(accessToken) {
|
|
104
|
+
this.haveRequestHeaders({ Authorization: `Bearer ${accessToken}` });
|
|
105
|
+
}
|
|
106
|
+
|
|
74
107
|
/**
|
|
75
108
|
* Executes axios request
|
|
76
109
|
*
|
|
@@ -111,6 +144,9 @@ class REST extends Helper {
|
|
|
111
144
|
this.debugSection('Response', `Response error. Status code: ${err.response.status}`);
|
|
112
145
|
response = err.response;
|
|
113
146
|
}
|
|
147
|
+
if (this.config.onResponse) {
|
|
148
|
+
await this.config.onResponse(response);
|
|
149
|
+
}
|
|
114
150
|
this.debugSection('Response', JSON.stringify(response.data));
|
|
115
151
|
return response;
|
|
116
152
|
}
|
|
@@ -14,6 +14,14 @@ class Console {
|
|
|
14
14
|
this._logEntries = [];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
includes(msg) {
|
|
18
|
+
const prev = this._logEntries[this._logEntries.length - 1];
|
|
19
|
+
if (!prev) return false;
|
|
20
|
+
const text = msg.text && msg.text() || msg._text || '';
|
|
21
|
+
const prevText = prev.text && prev.text() || prev._text || '';
|
|
22
|
+
return text === prevText;
|
|
23
|
+
}
|
|
24
|
+
|
|
17
25
|
add(entry) {
|
|
18
26
|
if (Array.isArray(entry)) {
|
|
19
27
|
this._logEntries = this._logEntries.concat(entry);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const RESTART_OPTS = {
|
|
2
|
+
session: 'keep',
|
|
3
|
+
browser: true,
|
|
4
|
+
context: false,
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
let restarts = null;
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
|
|
11
|
+
setRestartStrategy(options) {
|
|
12
|
+
const { restart } = options;
|
|
13
|
+
const stringOpts = Object.keys(RESTART_OPTS);
|
|
14
|
+
|
|
15
|
+
if (stringOpts.includes(restart)) {
|
|
16
|
+
return restarts = restart;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
restarts = Object.keys(RESTART_OPTS).find(key => RESTART_OPTS[key] === restart);
|
|
20
|
+
|
|
21
|
+
console.log(restarts);
|
|
22
|
+
|
|
23
|
+
if (restarts === null || restarts === undefined) throw new Error('No restart strategy set, use the following values for restart: session, context, browser');
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
restartsSession() {
|
|
27
|
+
return restarts === 'session';
|
|
28
|
+
},
|
|
29
|
+
restartsContext() {
|
|
30
|
+
return restarts === 'context';
|
|
31
|
+
},
|
|
32
|
+
restartsBrowser() {
|
|
33
|
+
return restarts === 'browser';
|
|
34
|
+
},
|
|
35
|
+
};
|
package/lib/interfaces/bdd.js
CHANGED
|
@@ -25,7 +25,8 @@ const parameterTypeRegistry = new ParameterTypeRegistry();
|
|
|
25
25
|
const matchStep = (step) => {
|
|
26
26
|
for (const stepName in steps) {
|
|
27
27
|
if (stepName.indexOf('/') === 0) {
|
|
28
|
-
const
|
|
28
|
+
const regExpArr = stepName.match(new RegExp('^/(.*?)/([gimy]*)$')) || [];
|
|
29
|
+
const res = step.match(new RegExp(regExpArr[1], regExpArr[2]));
|
|
29
30
|
if (res) {
|
|
30
31
|
const fn = steps[stepName];
|
|
31
32
|
fn.params = res.slice(1);
|
|
@@ -56,6 +57,7 @@ module.exports = {
|
|
|
56
57
|
Given: addStep,
|
|
57
58
|
When: addStep,
|
|
58
59
|
Then: addStep,
|
|
60
|
+
And: addStep,
|
|
59
61
|
matchStep,
|
|
60
62
|
getSteps,
|
|
61
63
|
clearSteps,
|