codeceptjs 3.6.1 → 3.6.2-beta.2

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.
@@ -417,7 +417,14 @@ class Playwright extends Helper {
417
417
  }
418
418
 
419
419
  if (this.options.video) {
420
- this.options.recordVideo = { size: parseWindowSize(this.options.windowSize) };
420
+ // set the video resolution with window size
421
+ let size = parseWindowSize(this.options.windowSize);
422
+
423
+ // if the video resolution is passed, set the record resoultion with that resolution
424
+ if (this.options.recordVideo && this.options.recordVideo.size) {
425
+ size = parseWindowSize(this.options.recordVideo.size);
426
+ }
427
+ this.options.recordVideo = { size };
421
428
  }
422
429
  if (this.options.recordVideo && !this.options.recordVideo.dir) {
423
430
  this.options.recordVideo.dir = `${global.output_dir}/videos/`;
@@ -2984,7 +2991,7 @@ class Playwright extends Helper {
2984
2991
  }
2985
2992
 
2986
2993
  /**
2987
- * {{> flushNetworkTraffics }}
2994
+ * {{> startRecordingTraffic }}
2988
2995
  *
2989
2996
  */
2990
2997
  startRecordingTraffic() {
@@ -3656,6 +3663,11 @@ async function targetCreatedHandler(page) {
3656
3663
 
3657
3664
  function parseWindowSize(windowSize) {
3658
3665
  if (!windowSize) return { width: 800, height: 600 };
3666
+
3667
+ if (windowSize.width && windowSize.height) {
3668
+ return { width: parseInt(windowSize.width, 10), height: parseInt(windowSize.height, 10) };
3669
+ }
3670
+
3659
3671
  const dimensions = windowSize.split('x');
3660
3672
  if (dimensions.length < 2 || windowSize === 'maximize') {
3661
3673
  console.log('Invalid window size, setting window to default values');
@@ -1,5 +1,6 @@
1
1
  const axios = require('axios').default;
2
2
  const Helper = require('@codeceptjs/helper');
3
+ const { Agent } = require('https');
3
4
  const Secret = require('../secret');
4
5
 
5
6
  const { beautify } = require('../utils');
@@ -13,6 +14,7 @@ const { beautify } = require('../utils');
13
14
  * @prop {boolean} [prettyPrintJson=false] - pretty print json for response/request on console logs
14
15
  * @prop {number} [timeout=1000] - timeout for requests in milliseconds. 10000ms by default
15
16
  * @prop {object} [defaultHeaders] - a list of default headers
17
+ * @prop {object} [httpAgent] - create an agent with SSL certificate
16
18
  * @prop {function} [onRequest] - a async function which can update request object.
17
19
  * @prop {function} [onResponse] - a async function which can update response object.
18
20
  * @prop {number} [maxUploadFileSize] - set the max content file size in MB when performing api calls.
@@ -40,6 +42,24 @@ const config = {};
40
42
  * }
41
43
  *}
42
44
  * ```
45
+ * With httpAgent
46
+ *
47
+ * ```js
48
+ * {
49
+ * helpers: {
50
+ * REST: {
51
+ * endpoint: 'http://site.com/api',
52
+ * prettyPrintJson: true,
53
+ * httpAgent: {
54
+ * key: fs.readFileSync(__dirname + '/path/to/keyfile.key'),
55
+ * cert: fs.readFileSync(__dirname + '/path/to/certfile.cert'),
56
+ * rejectUnauthorized: false,
57
+ * keepAlive: true
58
+ * }
59
+ * }
60
+ * }
61
+ * }
62
+ * ```
43
63
  *
44
64
  * ## Access From Helpers
45
65
  *
@@ -76,7 +96,14 @@ class REST extends Helper {
76
96
  this._setConfig(config);
77
97
 
78
98
  this.headers = { ...this.options.defaultHeaders };
79
- this.axios = axios.create();
99
+
100
+ // Create an agent with SSL certificate
101
+ if (this.options.httpAgent) {
102
+ if (!this.options.httpAgent.key || !this.options.httpAgent.cert) throw Error('Please recheck your httpAgent config!');
103
+ this.httpsAgent = new Agent(this.options.httpAgent);
104
+ }
105
+
106
+ this.axios = this.httpsAgent ? axios.create({ httpsAgent: this.httpsAgent }) : axios.create();
80
107
  // @ts-ignore
81
108
  this.axios.defaults.headers = this.options.defaultHeaders;
82
109
  }
package/lib/locator.js CHANGED
@@ -299,6 +299,15 @@ class Locator {
299
299
  return new Locator({ xpath });
300
300
  }
301
301
 
302
+ /**
303
+ * @param {String} text
304
+ * @returns {Locator}
305
+ */
306
+ withClassAttr(text) {
307
+ const xpath = sprintf('%s[%s]', this.toXPath(), `contains(@class, '${text}')`);
308
+ return new Locator({ xpath });
309
+ }
310
+
302
311
  /**
303
312
  * @param {string} output
304
313
  * @returns {Locator}
@@ -541,7 +550,7 @@ function removePrefix(xpath) {
541
550
  * @returns {boolean}
542
551
  */
543
552
  function isPlaywrightLocator(locator) {
544
- return locator.includes('_react') || locator.includes('_vue') || locator.includes('data-testid');
553
+ return locator.includes('_react') || locator.includes('_vue');
545
554
  }
546
555
 
547
556
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeceptjs",
3
- "version": "3.6.1",
3
+ "version": "3.6.2-beta.2",
4
4
  "description": "Supercharged End 2 End Testing Framework for NodeJS",
5
5
  "keywords": [
6
6
  "acceptance",
@@ -98,16 +98,16 @@
98
98
  "glob": "6.0.1",
99
99
  "html-minifier-terser": "7.2.0",
100
100
  "inquirer": "6.5.2",
101
- "joi": "17.12.2",
101
+ "joi": "17.12.3",
102
102
  "js-beautify": "1.15.1",
103
103
  "lodash.clonedeep": "4.5.0",
104
104
  "lodash.merge": "4.6.2",
105
105
  "mkdirp": "1.0.4",
106
- "mocha": "10.3.0",
106
+ "mocha": "10.4.0",
107
107
  "monocart-coverage-reports": "2.7.4",
108
108
  "ms": "2.1.3",
109
109
  "ora-classic": "5.4.2",
110
- "pactum": "3.6.6",
110
+ "pactum": "3.6.7",
111
111
  "parse-function": "5.6.10",
112
112
  "parse5": "7.1.2",
113
113
  "promise-retry": "1.1.1",
@@ -135,7 +135,7 @@
135
135
  "chai-subset": "1.6.0",
136
136
  "contributor-faces": "1.1.0",
137
137
  "documentation": "12.3.0",
138
- "electron": "28.2.1",
138
+ "electron": "30.0.1",
139
139
  "eslint": "8.56.0",
140
140
  "eslint-config-airbnb-base": "15.0.0",
141
141
  "eslint-plugin-import": "2.29.1",
@@ -148,7 +148,7 @@
148
148
  "jsdoc": "3.6.11",
149
149
  "jsdoc-typeof-plugin": "1.0.0",
150
150
  "json-server": "0.10.1",
151
- "playwright": "1.43.0",
151
+ "playwright": "1.43.1",
152
152
  "puppeteer": "22.6.3",
153
153
  "qrcode-terminal": "0.12.0",
154
154
  "rosie": "2.1.1",
@@ -179,4 +179,4 @@
179
179
  "strict": false
180
180
  }
181
181
  }
182
- }
182
+ }
@@ -4765,10 +4765,11 @@ declare namespace CodeceptJS {
4765
4765
  */
4766
4766
  stopMockingRoute(url?: string | RegExp, handler?: (...params: any[]) => any): Promise<any>;
4767
4767
  /**
4768
- * Resets all recorded network requests.
4768
+ * Starts recording the network traffics.
4769
+ * This also resets recorded network requests.
4769
4770
  *
4770
4771
  * ```js
4771
- * I.flushNetworkTraffics();
4772
+ * I.startRecordingTraffic();
4772
4773
  * ```
4773
4774
  */
4774
4775
  startRecordingTraffic(): Promise<any>;
@@ -8027,6 +8028,24 @@ declare namespace CodeceptJS {
8027
8028
  * }
8028
8029
  * }
8029
8030
  * ```
8031
+ * With httpAgent
8032
+ *
8033
+ * ```js
8034
+ * {
8035
+ * helpers: {
8036
+ * REST: {
8037
+ * endpoint: 'http://site.com/api',
8038
+ * prettyPrintJson: true,
8039
+ * httpAgent: {
8040
+ * key: fs.readFileSync(__dirname + '/path/to/keyfile.key'),
8041
+ * cert: fs.readFileSync(__dirname + '/path/to/certfile.cert'),
8042
+ * rejectUnauthorized: false,
8043
+ * keepAlive: true
8044
+ * }
8045
+ * }
8046
+ * }
8047
+ * }
8048
+ * ```
8030
8049
  *
8031
8050
  * ## Access From Helpers
8032
8051
  *
@@ -5015,11 +5015,13 @@ declare namespace CodeceptJS {
5015
5015
  */
5016
5016
  stopMockingRoute(url?: string | RegExp, handler?: (...params: any[]) => any): void;
5017
5017
  /**
5018
- * Resets all recorded network requests.
5018
+ * Starts recording the network traffics.
5019
+ * This also resets recorded network requests.
5019
5020
  *
5020
5021
  * ```js
5021
- * I.flushNetworkTraffics();
5022
+ * I.startRecordingTraffic();
5022
5023
  * ```
5024
+ * @returns automatically synchronized promise through #recorder
5023
5025
  */
5024
5026
  startRecordingTraffic(): void;
5025
5027
  /**
@@ -8523,6 +8525,7 @@ declare namespace CodeceptJS {
8523
8525
  * @property [prettyPrintJson = false] - pretty print json for response/request on console logs
8524
8526
  * @property [timeout = 1000] - timeout for requests in milliseconds. 10000ms by default
8525
8527
  * @property [defaultHeaders] - a list of default headers
8528
+ * @property [httpAgent] - create an agent with SSL certificate
8526
8529
  * @property [onRequest] - a async function which can update request object.
8527
8530
  * @property [onResponse] - a async function which can update response object.
8528
8531
  * @property [maxUploadFileSize] - set the max content file size in MB when performing api calls.
@@ -8532,6 +8535,7 @@ declare namespace CodeceptJS {
8532
8535
  prettyPrintJson?: boolean;
8533
8536
  timeout?: number;
8534
8537
  defaultHeaders?: any;
8538
+ httpAgent?: any;
8535
8539
  onRequest?: (...params: any[]) => any;
8536
8540
  onResponse?: (...params: any[]) => any;
8537
8541
  maxUploadFileSize?: number;
@@ -8557,6 +8561,24 @@ declare namespace CodeceptJS {
8557
8561
  * }
8558
8562
  * }
8559
8563
  * ```
8564
+ * With httpAgent
8565
+ *
8566
+ * ```js
8567
+ * {
8568
+ * helpers: {
8569
+ * REST: {
8570
+ * endpoint: 'http://site.com/api',
8571
+ * prettyPrintJson: true,
8572
+ * httpAgent: {
8573
+ * key: fs.readFileSync(__dirname + '/path/to/keyfile.key'),
8574
+ * cert: fs.readFileSync(__dirname + '/path/to/certfile.cert'),
8575
+ * rejectUnauthorized: false,
8576
+ * keepAlive: true
8577
+ * }
8578
+ * }
8579
+ * }
8580
+ * }
8581
+ * ```
8560
8582
  *
8561
8583
  * ## Access From Helpers
8562
8584
  *
@@ -12153,6 +12175,7 @@ declare namespace CodeceptJS {
12153
12175
  withAttr(attributes: {
12154
12176
  [key: string]: string;
12155
12177
  }): Locator;
12178
+ withClassAttr(text: string): Locator;
12156
12179
  as(output: string): Locator;
12157
12180
  inside(locator: CodeceptJS.LocatorOrString): Locator;
12158
12181
  after(locator: CodeceptJS.LocatorOrString): Locator;
@@ -12377,14 +12400,14 @@ declare namespace CodeceptJS {
12377
12400
  * Detox provides a grey box testing for mobile applications, playing especially good for React Native apps.
12378
12401
  *
12379
12402
  * Detox plays quite differently from Appium. To establish detox testing you need to build a mobile application in a special way to inject Detox code.
12380
- * This why **Detox is grey box testing** solution, so you need an access to application source code, and a way to build and execute it on emulator.
12403
+ * This why **Detox is grey box testing** solution, so you need access to application source code, and a way to build and execute it on emulator.
12381
12404
  *
12382
12405
  * Comparing to Appium, Detox runs faster and more stable but requires an additional setup for build.
12383
12406
  *
12384
12407
  * ### Setup
12385
12408
  *
12386
- * 1. [Install and configure Detox for iOS](https://github.com/wix/Detox/blob/master/docs/Introduction.GettingStarted.md) and [Android](https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md)
12387
- * 2. [Build an application](https://github.com/wix/Detox/blob/master/docs/Introduction.GettingStarted.md#step-4-build-your-app-and-run-detox-tests) using `detox build` command.
12409
+ * 1. [Install and configure Detox](https://wix.github.io/Detox/docs/introduction/project-setup)
12410
+ * 2. [Build an application](https://wix.github.io/Detox/docs/introduction/project-setup#step-5-build-the-app) using `detox build` command.
12388
12411
  * 3. Install [CodeceptJS](https://codecept.io) and detox-helper:
12389
12412
  *
12390
12413
  * ```
@@ -12397,15 +12420,28 @@ declare namespace CodeceptJS {
12397
12420
  *
12398
12421
  * ```js
12399
12422
  * "detox": {
12400
- * "configurations": {
12401
- * "ios.sim.debug": {
12402
- * "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/example.app",
12403
- * "build": "xcodebuild -project ios/example.xcodeproj -scheme example -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
12404
- * "type": "ios.simulator",
12405
- * "name": "iPhone 7"
12406
- * }
12407
- * }
12408
- * }
12423
+ * "configurations": {
12424
+ * "ios.sim.debug": {
12425
+ * "device": "simulator",
12426
+ * "app": "ios.debug"
12427
+ * }
12428
+ * },
12429
+ * "apps": {
12430
+ * "ios.debug": {
12431
+ * "type": "ios.app",
12432
+ * "binaryPath": "../test/ios/build/Build/Products/Debug-iphonesimulator/MyTestApp.app",
12433
+ * "build": "xcodebuild -workspace ../test/ios/MyTestApp.xcworkspace -scheme MyTestApp -configuration Debug -sdk iphonesimulator -derivedDataPath ../test/ios/build"
12434
+ * }
12435
+ * },
12436
+ * "devices": {
12437
+ * "simulator": {
12438
+ * "type": "ios.simulator",
12439
+ * "device": {
12440
+ * "type": "iPhone 15"
12441
+ * }
12442
+ * }
12443
+ * }
12444
+ * }
12409
12445
  * ```
12410
12446
  *
12411
12447
  *
@@ -12500,6 +12536,14 @@ declare namespace CodeceptJS {
12500
12536
  * ```
12501
12537
  */
12502
12538
  setPortraitOrientation(): void;
12539
+ /**
12540
+ * Grab the device platform
12541
+ *
12542
+ * ```js
12543
+ * const platform = await I.grabPlatform();
12544
+ * ```
12545
+ */
12546
+ grabPlatform(): void;
12503
12547
  /**
12504
12548
  * Execute code only on iOS
12505
12549
  *
@@ -12589,6 +12633,19 @@ declare namespace CodeceptJS {
12589
12633
  * ```
12590
12634
  */
12591
12635
  click(locator: CodeceptJS.LocatorOrString, context?: CodeceptJS.LocatorOrString | null): void;
12636
+ /**
12637
+ * Clicks on an element.
12638
+ * Element can be located by its label
12639
+ *
12640
+ * The second parameter is a context (id | type | accessibility id) to narrow the search.
12641
+ *
12642
+ *
12643
+ * ```js
12644
+ * I.tapByLabel('Login'); // locate by text
12645
+ * I.tapByLabel('Login', '#nav'); // locate by text inside #nav
12646
+ * ```
12647
+ */
12648
+ tapByLabel(locator: CodeceptJS.LocatorOrString, context?: CodeceptJS.LocatorOrString | null): void;
12592
12649
  /**
12593
12650
  * Performs click on element with horizontal and vertical offset.
12594
12651
  * An element is located by text, id, accessibility id.
@@ -12639,6 +12696,17 @@ declare namespace CodeceptJS {
12639
12696
  * @param [context = null] - context element
12640
12697
  */
12641
12698
  seeElement(locator: CodeceptJS.LocatorOrString, context?: CodeceptJS.LocatorOrString | null): void;
12699
+ /**
12700
+ * Checks if an element exists.
12701
+ *
12702
+ * ```js
12703
+ * I.checkIfElementExists('~edit'); // located by accessibility id
12704
+ * I.checkIfElementExists('~edit', '#menu'); // element inside #menu
12705
+ * ```
12706
+ * @param locator - element to locate
12707
+ * @param [context = null] - context element
12708
+ */
12709
+ checkIfElementExists(locator: CodeceptJS.LocatorOrString, context?: CodeceptJS.LocatorOrString | null): void;
12642
12710
  /**
12643
12711
  * Checks that element is not visible.
12644
12712
  * Use second parameter to narrow down the search.
@@ -12688,6 +12756,18 @@ declare namespace CodeceptJS {
12688
12756
  * @param value - value to fill
12689
12757
  */
12690
12758
  fillField(field: CodeceptJS.LocatorOrString, value: string): void;
12759
+ /**
12760
+ * Taps return key.
12761
+ * A field can be located by text, accessibility id, id.
12762
+ *
12763
+ * ```js
12764
+ * I.tapReturnKey('Username');
12765
+ * I.tapReturnKey('~name');
12766
+ * I.tapReturnKey({ android: 'NAME', ios: 'name' });
12767
+ * ```
12768
+ * @param field - an input element to fill in
12769
+ */
12770
+ tapReturnKey(field: CodeceptJS.LocatorOrString): void;
12691
12771
  /**
12692
12772
  * Clears a text field.
12693
12773
  * A field can be located by text, accessibility id, id.
@@ -12813,7 +12893,7 @@ declare namespace CodeceptJS {
12813
12893
  */
12814
12894
  waitForElementVisible(locator: CodeceptJS.LocatorOrString, sec?: number): void;
12815
12895
  /**
12816
- * Waits an elment to become not visible.
12896
+ * Waits an elmenet to become not visible.
12817
12897
  *
12818
12898
  * ```js
12819
12899
  * I.waitToHide('#message', 2); // wait for 2 seconds
@@ -12822,6 +12902,14 @@ declare namespace CodeceptJS {
12822
12902
  * @param [sec = 5] - number of seconds to wait
12823
12903
  */
12824
12904
  waitToHide(locator: CodeceptJS.LocatorOrString, sec?: number): void;
12905
+ /**
12906
+ * Scrolls within a scrollable container to an element.
12907
+ * @param targetLocator - Locator of the element to scroll to
12908
+ * @param containerLocator - Locator of the scrollable container
12909
+ * @param direction - 'up' or 'down'
12910
+ * @param [offset = 100] - Offset for scroll, can be adjusted based on need
12911
+ */
12912
+ scrollToElement(targetLocator: CodeceptJS.LocatorOrString, containerLocator: CodeceptJS.LocatorOrString, direction?: string, offset?: number): void;
12825
12913
  }
12826
12914
  /**
12827
12915
  * Abstract class.