codeceptjs 3.5.12 → 3.5.13-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.
Files changed (127) hide show
  1. package/README.md +2 -2
  2. package/docs/webapi/amOnPage.mustache +11 -0
  3. package/docs/webapi/appendField.mustache +11 -0
  4. package/docs/webapi/attachFile.mustache +12 -0
  5. package/docs/webapi/blur.mustache +18 -0
  6. package/docs/webapi/checkOption.mustache +13 -0
  7. package/docs/webapi/clearCookie.mustache +9 -0
  8. package/docs/webapi/clearField.mustache +9 -0
  9. package/docs/webapi/click.mustache +25 -0
  10. package/docs/webapi/clickLink.mustache +8 -0
  11. package/docs/webapi/closeCurrentTab.mustache +7 -0
  12. package/docs/webapi/closeOtherTabs.mustache +8 -0
  13. package/docs/webapi/dontSee.mustache +11 -0
  14. package/docs/webapi/dontSeeCheckboxIsChecked.mustache +10 -0
  15. package/docs/webapi/dontSeeCookie.mustache +8 -0
  16. package/docs/webapi/dontSeeCurrentUrlEquals.mustache +10 -0
  17. package/docs/webapi/dontSeeElement.mustache +8 -0
  18. package/docs/webapi/dontSeeElementInDOM.mustache +8 -0
  19. package/docs/webapi/dontSeeInCurrentUrl.mustache +4 -0
  20. package/docs/webapi/dontSeeInField.mustache +11 -0
  21. package/docs/webapi/dontSeeInSource.mustache +8 -0
  22. package/docs/webapi/dontSeeInTitle.mustache +8 -0
  23. package/docs/webapi/doubleClick.mustache +13 -0
  24. package/docs/webapi/downloadFile.mustache +12 -0
  25. package/docs/webapi/dragAndDrop.mustache +9 -0
  26. package/docs/webapi/dragSlider.mustache +11 -0
  27. package/docs/webapi/executeAsyncScript.mustache +24 -0
  28. package/docs/webapi/executeScript.mustache +26 -0
  29. package/docs/webapi/fillField.mustache +16 -0
  30. package/docs/webapi/focus.mustache +13 -0
  31. package/docs/webapi/forceClick.mustache +28 -0
  32. package/docs/webapi/forceRightClick.mustache +18 -0
  33. package/docs/webapi/grabAllWindowHandles.mustache +7 -0
  34. package/docs/webapi/grabAttributeFrom.mustache +10 -0
  35. package/docs/webapi/grabAttributeFromAll.mustache +9 -0
  36. package/docs/webapi/grabBrowserLogs.mustache +9 -0
  37. package/docs/webapi/grabCookie.mustache +11 -0
  38. package/docs/webapi/grabCssPropertyFrom.mustache +11 -0
  39. package/docs/webapi/grabCssPropertyFromAll.mustache +10 -0
  40. package/docs/webapi/grabCurrentUrl.mustache +9 -0
  41. package/docs/webapi/grabCurrentWindowHandle.mustache +6 -0
  42. package/docs/webapi/grabDataFromPerformanceTiming.mustache +20 -0
  43. package/docs/webapi/grabElementBoundingRect.mustache +20 -0
  44. package/docs/webapi/grabGeoLocation.mustache +8 -0
  45. package/docs/webapi/grabHTMLFrom.mustache +10 -0
  46. package/docs/webapi/grabHTMLFromAll.mustache +9 -0
  47. package/docs/webapi/grabNumberOfOpenTabs.mustache +8 -0
  48. package/docs/webapi/grabNumberOfVisibleElements.mustache +9 -0
  49. package/docs/webapi/grabPageScrollPosition.mustache +8 -0
  50. package/docs/webapi/grabPopupText.mustache +5 -0
  51. package/docs/webapi/grabSource.mustache +8 -0
  52. package/docs/webapi/grabTextFrom.mustache +10 -0
  53. package/docs/webapi/grabTextFromAll.mustache +9 -0
  54. package/docs/webapi/grabTitle.mustache +8 -0
  55. package/docs/webapi/grabValueFrom.mustache +9 -0
  56. package/docs/webapi/grabValueFromAll.mustache +8 -0
  57. package/docs/webapi/grabWebElement.mustache +9 -0
  58. package/docs/webapi/grabWebElements.mustache +9 -0
  59. package/docs/webapi/moveCursorTo.mustache +12 -0
  60. package/docs/webapi/openNewTab.mustache +7 -0
  61. package/docs/webapi/pressKey.mustache +12 -0
  62. package/docs/webapi/pressKeyDown.mustache +12 -0
  63. package/docs/webapi/pressKeyUp.mustache +12 -0
  64. package/docs/webapi/pressKeyWithKeyNormalization.mustache +60 -0
  65. package/docs/webapi/refreshPage.mustache +6 -0
  66. package/docs/webapi/resizeWindow.mustache +6 -0
  67. package/docs/webapi/rightClick.mustache +14 -0
  68. package/docs/webapi/saveElementScreenshot.mustache +10 -0
  69. package/docs/webapi/saveScreenshot.mustache +12 -0
  70. package/docs/webapi/say.mustache +10 -0
  71. package/docs/webapi/scrollIntoView.mustache +11 -0
  72. package/docs/webapi/scrollPageToBottom.mustache +6 -0
  73. package/docs/webapi/scrollPageToTop.mustache +6 -0
  74. package/docs/webapi/scrollTo.mustache +12 -0
  75. package/docs/webapi/see.mustache +11 -0
  76. package/docs/webapi/seeAttributesOnElements.mustache +9 -0
  77. package/docs/webapi/seeCheckboxIsChecked.mustache +10 -0
  78. package/docs/webapi/seeCookie.mustache +8 -0
  79. package/docs/webapi/seeCssPropertiesOnElements.mustache +9 -0
  80. package/docs/webapi/seeCurrentUrlEquals.mustache +11 -0
  81. package/docs/webapi/seeElement.mustache +8 -0
  82. package/docs/webapi/seeElementInDOM.mustache +8 -0
  83. package/docs/webapi/seeInCurrentUrl.mustache +8 -0
  84. package/docs/webapi/seeInField.mustache +12 -0
  85. package/docs/webapi/seeInPopup.mustache +8 -0
  86. package/docs/webapi/seeInSource.mustache +7 -0
  87. package/docs/webapi/seeInTitle.mustache +8 -0
  88. package/docs/webapi/seeNumberOfElements.mustache +11 -0
  89. package/docs/webapi/seeNumberOfVisibleElements.mustache +10 -0
  90. package/docs/webapi/seeTextEquals.mustache +9 -0
  91. package/docs/webapi/seeTitleEquals.mustache +8 -0
  92. package/docs/webapi/selectOption.mustache +21 -0
  93. package/docs/webapi/setCookie.mustache +16 -0
  94. package/docs/webapi/setGeoLocation.mustache +12 -0
  95. package/docs/webapi/switchTo.mustache +9 -0
  96. package/docs/webapi/switchToNextTab.mustache +10 -0
  97. package/docs/webapi/switchToPreviousTab.mustache +10 -0
  98. package/docs/webapi/type.mustache +21 -0
  99. package/docs/webapi/uncheckOption.mustache +13 -0
  100. package/docs/webapi/wait.mustache +8 -0
  101. package/docs/webapi/waitForClickable.mustache +11 -0
  102. package/docs/webapi/waitForCookie.mustache +9 -0
  103. package/docs/webapi/waitForDetached.mustache +10 -0
  104. package/docs/webapi/waitForElement.mustache +11 -0
  105. package/docs/webapi/waitForEnabled.mustache +6 -0
  106. package/docs/webapi/waitForFunction.mustache +17 -0
  107. package/docs/webapi/waitForInvisible.mustache +10 -0
  108. package/docs/webapi/waitForNumberOfTabs.mustache +9 -0
  109. package/docs/webapi/waitForText.mustache +13 -0
  110. package/docs/webapi/waitForValue.mustache +10 -0
  111. package/docs/webapi/waitForVisible.mustache +10 -0
  112. package/docs/webapi/waitInUrl.mustache +9 -0
  113. package/docs/webapi/waitNumberOfVisibleElements.mustache +10 -0
  114. package/docs/webapi/waitToHide.mustache +10 -0
  115. package/docs/webapi/waitUrlEquals.mustache +10 -0
  116. package/lib/helper/Appium.js +36 -12
  117. package/lib/helper/Expect.js +10 -7
  118. package/lib/helper/JSONResponse.js +8 -8
  119. package/lib/helper/MockServer.js +221 -0
  120. package/lib/helper/Playwright.js +36 -4
  121. package/lib/helper/Puppeteer.js +33 -0
  122. package/lib/helper/WebDriver.js +32 -0
  123. package/lib/locator.js +1 -1
  124. package/package.json +12 -10
  125. package/typings/index.d.ts +16 -0
  126. package/typings/promiseBasedTypes.d.ts +30 -0
  127. package/typings/types.d.ts +33 -0
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeceptjs",
3
- "version": "3.5.12",
3
+ "version": "3.5.13-beta.2",
4
4
  "description": "Supercharged End 2 End Testing Framework for NodeJS",
5
5
  "keywords": [
6
6
  "acceptance",
@@ -25,7 +25,8 @@
25
25
  "bin",
26
26
  "lib",
27
27
  "translations",
28
- "typings/**/*.d.ts"
28
+ "typings/**/*.d.ts",
29
+ "docs/webapi/**"
29
30
  ],
30
31
  "main": "lib/index.js",
31
32
  "typings": "typings/index.d.ts",
@@ -55,6 +56,7 @@
55
56
  "test:unit:webbapi:webDriver:devtools": "mocha test/helper/WebDriver_devtools_test.js --exit",
56
57
  "test:unit:webbapi:testCafe": "mocha test/helper/TestCafe_test.js",
57
58
  "test:unit:expect": "mocha test/helper/Expect_test.js",
59
+ "test:unit:mockServer": "mocha test/helper/MockServer_test.js",
58
60
  "test:plugin": "mocha test/plugin/plugin_test.js",
59
61
  "def": "./runok.js def",
60
62
  "dev:graphql": "node test/data/graphql/index.js",
@@ -71,10 +73,10 @@
71
73
  "@cucumber/gherkin": "26",
72
74
  "@cucumber/messages": "24.0.1",
73
75
  "@xmldom/xmldom": "0.8.10",
74
- "acorn": "8.11.2",
76
+ "acorn": "8.11.3",
75
77
  "arrify": "2.0.1",
76
78
  "axios": "1.6.3",
77
- "chai": "4.3.8",
79
+ "chai": "5.0.3",
78
80
  "chai-deep-match": "1.2.1",
79
81
  "chai-exclude": "2.1.0",
80
82
  "chai-json-schema": "1.5.1",
@@ -86,7 +88,7 @@
86
88
  "cross-spawn": "7.0.3",
87
89
  "css-to-xpath": "0.1.0",
88
90
  "csstoxpath": "1.6.0",
89
- "devtools": "8.27.2",
91
+ "devtools": "8.29.1",
90
92
  "envinfo": "7.11.0",
91
93
  "escape-string-regexp": "4.0.0",
92
94
  "figures": "3.2.0",
@@ -95,7 +97,6 @@
95
97
  "glob": "6.0.1",
96
98
  "html-minifier-terser": "7.2.0",
97
99
  "inquirer": "6.5.2",
98
- "joi": "17.11.0",
99
100
  "js-beautify": "1.14.11",
100
101
  "lodash.clonedeep": "4.5.0",
101
102
  "lodash.merge": "4.6.2",
@@ -104,6 +105,7 @@
104
105
  "ms": "2.1.3",
105
106
  "openai": "3.2.1",
106
107
  "ora-classic": "5.4.2",
108
+ "pactum": "3.6.0",
107
109
  "parse-function": "5.6.4",
108
110
  "parse5": "7.1.2",
109
111
  "promise-retry": "1.1.1",
@@ -121,8 +123,8 @@
121
123
  "@pollyjs/core": "5.1.0",
122
124
  "@types/chai": "4.3.7",
123
125
  "@types/inquirer": "9.0.3",
124
- "@types/node": "20.10.7",
125
- "@wdio/sauce-service": "8.27.0",
126
+ "@types/node": "20.11.16",
127
+ "@wdio/sauce-service": "8.29.1",
126
128
  "@wdio/selenium-standalone-service": "8.3.2",
127
129
  "@wdio/utils": "8.28.8",
128
130
  "@xmldom/xmldom": "0.8.10",
@@ -152,7 +154,7 @@
152
154
  "runok": "0.9.3",
153
155
  "sinon": "17.0.1",
154
156
  "sinon-chai": "3.7.0",
155
- "testcafe": "3.3.0",
157
+ "testcafe": "3.5.0",
156
158
  "ts-morph": "21.0.1",
157
159
  "ts-node": "10.9.2",
158
160
  "tsd-jsdoc": "2.5.0",
@@ -169,4 +171,4 @@
169
171
  "npm": ">=5.6.0"
170
172
  },
171
173
  "es6": true
172
- }
174
+ }
@@ -382,6 +382,22 @@ declare namespace CodeceptJS {
382
382
  [key: string]: any;
383
383
  };
384
384
 
385
+ type MockRequest = {
386
+ method: 'GET'|'PUT'|'POST'|'PATCH'|'DELETE'|string;
387
+ path: string;
388
+ queryParams?: object;
389
+ }
390
+
391
+ type MockResponse = {
392
+ status: number;
393
+ body?: object;
394
+ }
395
+
396
+ type MockInteraction = {
397
+ request: MockRequest;
398
+ response: MockResponse;
399
+ }
400
+
385
401
  interface PageScrollPosition {
386
402
  x: number;
387
403
  y: number;
@@ -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