codeceptjs 3.5.12-beta.9 → 3.5.13-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -313,10 +313,10 @@ Thanks all to those who are and will have contributing to this awesome project!
313
313
  <a href="https://github.com/tsuemura"><img src="https://avatars.githubusercontent.com/u/17092259?v=4" title="tsuemura" width="80" height="80"></a>
314
314
  <a href="https://github.com/EgorBodnar"><img src="https://avatars.githubusercontent.com/u/63167966?v=4" title="EgorBodnar" width="80" height="80"></a>
315
315
  <a href="https://github.com/VikalpP"><img src="https://avatars.githubusercontent.com/u/11846339?v=4" title="VikalpP" width="80" height="80"></a>
316
- <a href="https://github.com/BorisOsipov"><img src="https://avatars.githubusercontent.com/u/6514276?v=4" title="BorisOsipov" width="80" height="80"></a>
317
316
  <a href="https://github.com/elaichenkov"><img src="https://avatars.githubusercontent.com/u/29764053?v=4" title="elaichenkov" width="80" height="80"></a>
318
- <a href="https://github.com/nitschSB"><img src="https://avatars.githubusercontent.com/u/39341455?v=4" title="nitschSB" width="80" height="80"></a>
317
+ <a href="https://github.com/BorisOsipov"><img src="https://avatars.githubusercontent.com/u/6514276?v=4" title="BorisOsipov" width="80" height="80"></a>
319
318
  <a href="https://github.com/hubidu"><img src="https://avatars.githubusercontent.com/u/13134082?v=4" title="hubidu" width="80" height="80"></a>
319
+ <a href="https://github.com/nitschSB"><img src="https://avatars.githubusercontent.com/u/39341455?v=4" title="nitschSB" width="80" height="80"></a>
320
320
  <a href="https://github.com/jploskonka"><img src="https://avatars.githubusercontent.com/u/669483?v=4" title="jploskonka" width="80" height="80"></a>
321
321
  <a href="https://github.com/ngraf"><img src="https://avatars.githubusercontent.com/u/7094389?v=4" title="ngraf" width="80" height="80"></a>
322
322
  <a href="https://github.com/maojunxyz"><img src="https://avatars.githubusercontent.com/u/28778042?v=4" title="maojunxyz" width="80" height="80"></a>
package/lib/actor.js CHANGED
@@ -13,15 +13,18 @@ const output = require('./output');
13
13
  */
14
14
  class Actor {
15
15
  /**
16
- * add print comment method`
16
+ * Print the comment on log. Also, adding a step in the `Test.steps` object
17
17
  * @param {string} msg
18
18
  * @param {string} color
19
19
  * @inner
20
20
  *
21
21
  * ⚠️ returns a promise which is synchronized internally by recorder
22
22
  */
23
- say(msg, color = 'cyan') {
24
- return recorder.add(`say ${msg}`, () => {
23
+ async say(msg, color = 'cyan') {
24
+ const step = new Step('say', 'say');
25
+ step.status = 'passed';
26
+ return recordStep(step, [msg]).then(() => {
27
+ // this is backward compatibility as this event may be used somewhere
25
28
  event.emit(event.step.comment, msg);
26
29
  output.say(msg, `${color}`);
27
30
  });
@@ -2,6 +2,7 @@ let webdriverio;
2
2
 
3
3
  const fs = require('fs');
4
4
  const axios = require('axios').default;
5
+ const { v4: uuidv4 } = require('uuid');
5
6
 
6
7
  const Webdriver = require('./WebDriver');
7
8
  const AssertionFailedError = require('../assert/error');
@@ -1088,17 +1089,40 @@ class Appium extends Webdriver {
1088
1089
  * Appium: support Android and iOS
1089
1090
  */
1090
1091
  async performSwipe(from, to) {
1091
- await this.browser.touchPerform([{
1092
- action: 'press',
1093
- options: from,
1094
- }, {
1095
- action: 'wait',
1096
- options: { ms: 1000 },
1097
- }, {
1098
- action: 'moveTo',
1099
- options: to,
1100
- }, {
1101
- action: 'release',
1092
+ await this.browser.performActions([{
1093
+ id: uuidv4(),
1094
+ type: 'pointer',
1095
+ parameters: {
1096
+ pointerType: 'touch',
1097
+ },
1098
+ actions: [
1099
+ {
1100
+ duration: 0,
1101
+ x: from.x,
1102
+ y: from.y,
1103
+ type: 'pointerMove',
1104
+ origin: 'viewport',
1105
+ },
1106
+ {
1107
+ button: 1,
1108
+ type: 'pointerDown',
1109
+ },
1110
+ {
1111
+ duration: 200,
1112
+ type: 'pause',
1113
+ },
1114
+ {
1115
+ duration: 600,
1116
+ x: to.x,
1117
+ y: to.y,
1118
+ type: 'pointerMove',
1119
+ origin: 'viewport',
1120
+ },
1121
+ {
1122
+ button: 1,
1123
+ type: 'pointerUp',
1124
+ },
1125
+ ],
1102
1126
  }]);
1103
1127
  await this.browser.pause(1000);
1104
1128
  }
@@ -1128,7 +1152,7 @@ class Appium extends Webdriver {
1128
1152
  yoffset = 100;
1129
1153
  }
1130
1154
 
1131
- return this.swipe(locator, 0, yoffset, speed);
1155
+ return this.swipe(parseLocator.call(this, locator), 0, yoffset, speed);
1132
1156
  }
1133
1157
 
1134
1158
  /**
@@ -1,12 +1,15 @@
1
- const chai = require('chai');
2
1
  const output = require('../output');
3
2
 
4
- const { expect } = chai;
3
+ let expect;
5
4
 
6
- chai.use(require('chai-string'));
7
- // @ts-ignore
8
- chai.use(require('chai-exclude'));
9
- chai.use(require('chai-match-pattern'));
5
+ import('chai').then(chai => {
6
+ expect = chai.expect;
7
+ chai.use(require('chai-string'));
8
+ // @ts-ignore
9
+ chai.use(require('chai-exclude'));
10
+ chai.use(require('chai-match-pattern'));
11
+ chai.use(require('chai-json-schema'));
12
+ });
10
13
 
11
14
  /**
12
15
  * This helper allows performing assertions based on Chai.
@@ -179,7 +182,7 @@ class ExpectHelper {
179
182
  expectJsonSchema(targetData, jsonSchema, customErrorMsg = '') {
180
183
  // @ts-ignore
181
184
  output.step(`I expect "${JSON.stringify(targetData)}" to match this JSON schema "${JSON.stringify(jsonSchema)}"`);
182
- chai.use(require('chai-json-schema'));
185
+
183
186
  return expect(targetData, customErrorMsg).to.be.jsonSchema(jsonSchema);
184
187
  }
185
188
 
@@ -1,12 +1,13 @@
1
- const assert = require('assert');
2
- const chai = require('chai');
3
- const joi = require('joi');
4
- const chaiDeepMatch = require('chai-deep-match');
5
1
  const Helper = require('@codeceptjs/helper');
6
2
 
7
- chai.use(chaiDeepMatch);
3
+ let expect;
4
+
5
+ import('chai').then(chai => {
6
+ expect = chai.expect;
7
+ chai.use(require('chai-deep-match'));
8
+ });
8
9
 
9
- const { expect } = chai;
10
+ const joi = require('joi');
10
11
 
11
12
  /**
12
13
  * This helper allows performing assertions on JSON responses paired with following helpers:
@@ -91,7 +92,6 @@ class JSONResponse extends Helper {
91
92
  static _checkRequirements() {
92
93
  try {
93
94
  require('joi');
94
- require('chai');
95
95
  } catch (e) {
96
96
  return ['joi'];
97
97
  }
@@ -194,7 +194,7 @@ class JSONResponse extends Helper {
194
194
  fails++;
195
195
  }
196
196
  }
197
- assert.ok(fails < this.response.data.length, `No elements in array matched ${JSON.stringify(json)}`);
197
+ expect(fails < this.response.data.length, `No elements in array matched ${JSON.stringify(json)}`).to.be.true;
198
198
  } else {
199
199
  expect(this.response.data).to.deep.match(json);
200
200
  }
@@ -4,6 +4,7 @@ const fs = require('fs');
4
4
  const Helper = require('@codeceptjs/helper');
5
5
  const { v4: uuidv4 } = require('uuid');
6
6
  const assert = require('assert');
7
+ const promiseRetry = require('promise-retry');
7
8
  const Locator = require('../locator');
8
9
  const store = require('../store');
9
10
  const recorder = require('../recorder');
@@ -50,6 +51,7 @@ const { createValueEngine, createDisabledEngine } = require('./extras/Playwright
50
51
  const {
51
52
  seeElementError, dontSeeElementError, dontSeeElementInDOMError, seeElementInDOMError,
52
53
  } = require('./errors/ElementAssertion');
54
+ const { log } = require('../output');
53
55
 
54
56
  const pathSeparator = path.sep;
55
57
 
@@ -748,9 +750,7 @@ class Playwright extends Helper {
748
750
  });
749
751
  this.context = await this.page;
750
752
  this.contextLocator = null;
751
- if (this.options.browser === 'chrome') {
752
- await page.bringToFront();
753
- }
753
+ await page.bringToFront();
754
754
  }
755
755
 
756
756
  /**
@@ -1805,7 +1805,7 @@ class Playwright extends Helper {
1805
1805
  let optionToSelect = '';
1806
1806
 
1807
1807
  try {
1808
- optionToSelect = await el.locator('option', { hasText: option }).textContent();
1808
+ optionToSelect = (await el.locator('option', { hasText: option }).textContent()).trim();
1809
1809
  } catch (e) {
1810
1810
  optionToSelect = option;
1811
1811
  }
@@ -2890,6 +2890,38 @@ class Playwright extends Helper {
2890
2890
  }
2891
2891
  }
2892
2892
 
2893
+ /**
2894
+ * {{> waitForCookie }}
2895
+ */
2896
+ async waitForCookie(name, sec) {
2897
+ // by default, we will retry 3 times
2898
+ let retries = 3;
2899
+ const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout;
2900
+
2901
+ if (sec) {
2902
+ retries = sec;
2903
+ } else {
2904
+ retries = Math.ceil(waitTimeout / 1000) - 1;
2905
+ }
2906
+
2907
+ return promiseRetry(async (retry, number) => {
2908
+ const _grabCookie = async (name) => {
2909
+ const cookies = await this.browserContext.cookies();
2910
+ const cookie = cookies.filter(c => c.name === name);
2911
+ if (cookie.length === 0) throw Error(`Cookie ${name} is not found after ${retries}s`);
2912
+ };
2913
+
2914
+ this.debugSection('Wait for cookie: ', name);
2915
+ if (number > 1) this.debugSection('Retrying... Attempt #', number);
2916
+
2917
+ try {
2918
+ await _grabCookie(name);
2919
+ } catch (e) {
2920
+ retry(e);
2921
+ }
2922
+ }, { retries, maxTimeout: 1000 });
2923
+ }
2924
+
2893
2925
  async _waitForAction() {
2894
2926
  return this.wait(this.options.waitForAction / 1000);
2895
2927
  }
@@ -5,6 +5,7 @@ const path = require('path');
5
5
 
6
6
  const Helper = require('@codeceptjs/helper');
7
7
  const { v4: uuidv4 } = require('uuid');
8
+ const promiseRetry = require('promise-retry');
8
9
  const Locator = require('../locator');
9
10
  const recorder = require('../recorder');
10
11
  const store = require('../store');
@@ -1635,6 +1636,38 @@ class Puppeteer extends Helper {
1635
1636
  if (cookie[0]) return cookie[0];
1636
1637
  }
1637
1638
 
1639
+ /**
1640
+ * {{> waitForCookie }}
1641
+ */
1642
+ async waitForCookie(name, sec) {
1643
+ // by default, we will retry 3 times
1644
+ let retries = 3;
1645
+ const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout;
1646
+
1647
+ if (sec) {
1648
+ retries = sec;
1649
+ } else {
1650
+ retries = Math.ceil(waitTimeout / 1000) - 1;
1651
+ }
1652
+
1653
+ return promiseRetry(async (retry, number) => {
1654
+ const _grabCookie = async (name) => {
1655
+ const cookies = await this.page.cookies();
1656
+ const cookie = cookies.filter(c => c.name === name);
1657
+ if (cookie.length === 0) throw Error(`Cookie ${name} is not found after ${retries}s`);
1658
+ };
1659
+
1660
+ this.debugSection('Wait for cookie: ', name);
1661
+ if (number > 1) this.debugSection('Retrying... Attempt #', number);
1662
+
1663
+ try {
1664
+ await _grabCookie(name);
1665
+ } catch (e) {
1666
+ retry(e);
1667
+ }
1668
+ }, { retries, maxTimeout: 1000 });
1669
+ }
1670
+
1638
1671
  /**
1639
1672
  * {{> clearCookie }}
1640
1673
  */
@@ -6,6 +6,7 @@ const fs = require('fs');
6
6
 
7
7
  const Helper = require('@codeceptjs/helper');
8
8
  const crypto = require('crypto');
9
+ const promiseRetry = require('promise-retry');
9
10
  const stringIncludes = require('../assert/include').includes;
10
11
  const { urlEquals, equals } = require('../assert/equal');
11
12
  const { debug } = require('../output');
@@ -1860,6 +1861,37 @@ class WebDriver extends Helper {
1860
1861
  return cookie[0];
1861
1862
  }
1862
1863
 
1864
+ /**
1865
+ * {{> waitForCookie }}
1866
+ */
1867
+ async waitForCookie(name, sec) {
1868
+ // by default, we will retry 3 times
1869
+ let retries = 3;
1870
+ const waitTimeout = sec || this.options.waitForTimeoutInSeconds;
1871
+
1872
+ if (sec) {
1873
+ retries = sec;
1874
+ } else {
1875
+ retries = waitTimeout - 1;
1876
+ }
1877
+
1878
+ return promiseRetry(async (retry, number) => {
1879
+ const _grabCookie = async (name) => {
1880
+ const cookie = await this.browser.getCookies([name]);
1881
+ if (cookie.length === 0) throw Error(`Cookie ${name} is not found after ${retries}s`);
1882
+ };
1883
+
1884
+ this.debugSection('Wait for cookie: ', name);
1885
+ if (number > 1) this.debugSection('Retrying... Attempt #', number);
1886
+
1887
+ try {
1888
+ await _grabCookie(name);
1889
+ } catch (e) {
1890
+ retry(e);
1891
+ }
1892
+ }, { retries, maxTimeout: 1000 });
1893
+ }
1894
+
1863
1895
  /**
1864
1896
  * Accepts the active JavaScript native popup window, as created by window.alert|window.confirm|window.prompt.
1865
1897
  * Don't confuse popups with modal windows, as created by [various
package/lib/locator.js CHANGED
@@ -163,7 +163,7 @@ class Locator {
163
163
  */
164
164
  toXPath(pseudoSelector = '') {
165
165
  const locator = `${this.value}${pseudoSelector}`;
166
- const limitation = [':nth-of-type', ':first-of-type', ':last-of-type', ':nth-last-child', ':nth-last-of-type', ':checked', ':disabled', ':enabled', ':required', ':lang'];
166
+ const limitation = [':nth-of-type', ':first-of-type', ':last-of-type', ':nth-last-child', ':nth-last-of-type', ':checked', ':disabled', ':enabled', ':required', ':lang', ':nth-child'];
167
167
 
168
168
  if (limitation.some(item => locator.includes(item))) {
169
169
  cssToXPath = require('css-to-xpath');
package/lib/step.js CHANGED
@@ -119,7 +119,9 @@ class Step {
119
119
  }
120
120
  let result;
121
121
  try {
122
- result = this.helper[this.helperMethod].apply(this.helper, this.args);
122
+ if (this.helperMethod !== 'say') {
123
+ result = this.helper[this.helperMethod].apply(this.helper, this.args);
124
+ }
123
125
  this.setStatus('success');
124
126
  } catch (err) {
125
127
  this.setStatus('failed');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeceptjs",
3
- "version": "3.5.12-beta.9",
3
+ "version": "3.5.13-beta.1",
4
4
  "description": "Supercharged End 2 End Testing Framework for NodeJS",
5
5
  "keywords": [
6
6
  "acceptance",
@@ -72,10 +72,10 @@
72
72
  "@cucumber/gherkin": "26",
73
73
  "@cucumber/messages": "24.0.1",
74
74
  "@xmldom/xmldom": "0.8.10",
75
- "acorn": "8.11.2",
75
+ "acorn": "8.11.3",
76
76
  "arrify": "2.0.1",
77
77
  "axios": "1.6.3",
78
- "chai": "4.3.8",
78
+ "chai": "5.0.3",
79
79
  "chai-deep-match": "1.2.1",
80
80
  "chai-exclude": "2.1.0",
81
81
  "chai-json-schema": "1.5.1",
@@ -87,7 +87,7 @@
87
87
  "cross-spawn": "7.0.3",
88
88
  "css-to-xpath": "0.1.0",
89
89
  "csstoxpath": "1.6.0",
90
- "devtools": "8.27.2",
90
+ "devtools": "8.29.1",
91
91
  "envinfo": "7.11.0",
92
92
  "escape-string-regexp": "4.0.0",
93
93
  "figures": "3.2.0",
@@ -96,7 +96,6 @@
96
96
  "glob": "6.0.1",
97
97
  "html-minifier-terser": "7.2.0",
98
98
  "inquirer": "6.5.2",
99
- "joi": "17.11.0",
100
99
  "js-beautify": "1.14.11",
101
100
  "lodash.clonedeep": "4.5.0",
102
101
  "lodash.merge": "4.6.2",
@@ -123,10 +122,10 @@
123
122
  "@pollyjs/core": "5.1.0",
124
123
  "@types/chai": "4.3.7",
125
124
  "@types/inquirer": "9.0.3",
126
- "@types/node": "20.10.7",
127
- "@wdio/sauce-service": "8.27.0",
125
+ "@types/node": "20.11.16",
126
+ "@wdio/sauce-service": "8.29.1",
128
127
  "@wdio/selenium-standalone-service": "8.3.2",
129
- "@wdio/utils": "8.27.2",
128
+ "@wdio/utils": "8.28.8",
130
129
  "@xmldom/xmldom": "0.8.10",
131
130
  "apollo-server-express": "2.25.3",
132
131
  "chai-as-promised": "7.1.1",
@@ -154,7 +153,7 @@
154
153
  "runok": "0.9.3",
155
154
  "sinon": "17.0.1",
156
155
  "sinon-chai": "3.7.0",
157
- "testcafe": "3.3.0",
156
+ "testcafe": "3.5.0",
158
157
  "ts-morph": "21.0.1",
159
158
  "ts-node": "10.9.2",
160
159
  "tsd-jsdoc": "2.5.0",
@@ -4646,6 +4646,16 @@ declare namespace CodeceptJS {
4646
4646
  * @param [sec = 1] - (optional, `1` by default) time in seconds to wait
4647
4647
  */
4648
4648
  waitForDetached(locator: CodeceptJS.LocatorOrString, sec?: number): Promise<any>;
4649
+ /**
4650
+ * Waits for the specified cookie in the cookies.
4651
+ *
4652
+ * ```js
4653
+ * I.waitForCookie("token");
4654
+ * ```
4655
+ * @param name - expected cookie name.
4656
+ * @param [sec = 3] - (optional, `3` by default) time in seconds to wait
4657
+ */
4658
+ waitForCookie(name: string, sec?: number): Promise<any>;
4649
4659
  /**
4650
4660
  * Grab the data from performance timing using Navigation Timing API.
4651
4661
  * The returned data will contain following things in ms:
@@ -7296,6 +7306,16 @@ declare namespace CodeceptJS {
7296
7306
  * @param [name = null] - cookie name.
7297
7307
  */
7298
7308
  grabCookie(name?: string): Promise<any>;
7309
+ /**
7310
+ * Waits for the specified cookie in the cookies.
7311
+ *
7312
+ * ```js
7313
+ * I.waitForCookie("token");
7314
+ * ```
7315
+ * @param name - expected cookie name.
7316
+ * @param [sec = 3] - (optional, `3` by default) time in seconds to wait
7317
+ */
7318
+ waitForCookie(name: string, sec?: number): Promise<any>;
7299
7319
  /**
7300
7320
  * Clears a cookie by name,
7301
7321
  * if none provided clears all cookies.
@@ -10146,6 +10166,16 @@ declare namespace CodeceptJS {
10146
10166
  * @param [name = null] - cookie name.
10147
10167
  */
10148
10168
  grabCookie(name?: string): Promise<any>;
10169
+ /**
10170
+ * Waits for the specified cookie in the cookies.
10171
+ *
10172
+ * ```js
10173
+ * I.waitForCookie("token");
10174
+ * ```
10175
+ * @param name - expected cookie name.
10176
+ * @param [sec = 3] - (optional, `3` by default) time in seconds to wait
10177
+ */
10178
+ waitForCookie(name: string, sec?: number): Promise<any>;
10149
10179
  /**
10150
10180
  * Accepts the active JavaScript native popup window, as created by window.alert|window.confirm|window.prompt.
10151
10181
  * Don't confuse popups with modal windows, as created by [various
@@ -4892,6 +4892,17 @@ declare namespace CodeceptJS {
4892
4892
  * @returns automatically synchronized promise through #recorder
4893
4893
  */
4894
4894
  waitForDetached(locator: CodeceptJS.LocatorOrString, sec?: number): void;
4895
+ /**
4896
+ * Waits for the specified cookie in the cookies.
4897
+ *
4898
+ * ```js
4899
+ * I.waitForCookie("token");
4900
+ * ```
4901
+ * @param name - expected cookie name.
4902
+ * @param [sec = 3] - (optional, `3` by default) time in seconds to wait
4903
+ * @returns automatically synchronized promise through #recorder
4904
+ */
4905
+ waitForCookie(name: string, sec?: number): void;
4895
4906
  /**
4896
4907
  * Grab the data from performance timing using Navigation Timing API.
4897
4908
  * The returned data will contain following things in ms:
@@ -7757,6 +7768,17 @@ declare namespace CodeceptJS {
7757
7768
  * Returns cookie in JSON format. If name not passed returns all cookies for this domain.
7758
7769
  */
7759
7770
  grabCookie(name?: string): any;
7771
+ /**
7772
+ * Waits for the specified cookie in the cookies.
7773
+ *
7774
+ * ```js
7775
+ * I.waitForCookie("token");
7776
+ * ```
7777
+ * @param name - expected cookie name.
7778
+ * @param [sec = 3] - (optional, `3` by default) time in seconds to wait
7779
+ * @returns automatically synchronized promise through #recorder
7780
+ */
7781
+ waitForCookie(name: string, sec?: number): void;
7760
7782
  /**
7761
7783
  * Clears a cookie by name,
7762
7784
  * if none provided clears all cookies.
@@ -10852,6 +10874,17 @@ declare namespace CodeceptJS {
10852
10874
  * @returns attribute value
10853
10875
  */
10854
10876
  grabCookie(name?: string): any;
10877
+ /**
10878
+ * Waits for the specified cookie in the cookies.
10879
+ *
10880
+ * ```js
10881
+ * I.waitForCookie("token");
10882
+ * ```
10883
+ * @param name - expected cookie name.
10884
+ * @param [sec = 3] - (optional, `3` by default) time in seconds to wait
10885
+ * @returns automatically synchronized promise through #recorder
10886
+ */
10887
+ waitForCookie(name: string, sec?: number): void;
10855
10888
  /**
10856
10889
  * Accepts the active JavaScript native popup window, as created by window.alert|window.confirm|window.prompt.
10857
10890
  * Don't confuse popups with modal windows, as created by [various
@@ -11448,7 +11481,7 @@ declare namespace CodeceptJS {
11448
11481
  }
11449
11482
  interface ActorStatic {
11450
11483
  /**
11451
- * add print comment method`
11484
+ * Print the comment on log. Also, adding a step in the `Test.steps` object
11452
11485
  */
11453
11486
  say(msg: string, color?: string): void;
11454
11487
  /**