codeceptjs 4.0.2-beta.8 → 4.0.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 (326) hide show
  1. package/README.md +39 -28
  2. package/bin/codecept.js +15 -2
  3. package/bin/codeceptq.js +49 -0
  4. package/bin/mcp-server.js +1189 -0
  5. package/docs/advanced.md +201 -0
  6. package/docs/agents.md +181 -0
  7. package/docs/ai.md +489 -0
  8. package/docs/aitrace.md +266 -0
  9. package/docs/api.md +332 -0
  10. package/docs/architecture.md +235 -0
  11. package/docs/assertions.md +415 -0
  12. package/docs/auth.md +318 -0
  13. package/docs/basics.md +424 -0
  14. package/docs/bdd.md +539 -0
  15. package/docs/best.md +240 -0
  16. package/docs/bootstrap.md +132 -0
  17. package/docs/commands.md +352 -0
  18. package/docs/community-helpers.md +63 -0
  19. package/docs/configuration.md +185 -0
  20. package/docs/continuous-integration.md +431 -0
  21. package/docs/custom-helpers.md +297 -0
  22. package/docs/data.md +448 -0
  23. package/docs/debugging.md +332 -0
  24. package/docs/detox.md +235 -0
  25. package/docs/docker.md +107 -0
  26. package/docs/effects.md +179 -0
  27. package/docs/element-based-testing.md +295 -0
  28. package/docs/element-selection.md +125 -0
  29. package/docs/els.md +328 -0
  30. package/docs/environment-variables.md +131 -0
  31. package/docs/examples.md +160 -0
  32. package/docs/heal.md +213 -0
  33. package/docs/helpers/ApiDataFactory.md +267 -0
  34. package/docs/helpers/Appium.md +1419 -0
  35. package/docs/helpers/Detox.md +665 -0
  36. package/docs/helpers/ExpectHelper.md +275 -0
  37. package/docs/helpers/FileSystem.md +152 -0
  38. package/docs/helpers/GraphQL.md +152 -0
  39. package/docs/helpers/GraphQLDataFactory.md +226 -0
  40. package/docs/helpers/JSONResponse.md +255 -0
  41. package/docs/helpers/MockRequest.md +377 -0
  42. package/docs/helpers/Playwright.md +2970 -0
  43. package/docs/helpers/Puppeteer-firefox.md +86 -0
  44. package/docs/helpers/Puppeteer.md +2583 -0
  45. package/docs/helpers/REST.md +289 -0
  46. package/docs/helpers/WebDriver.md +2639 -0
  47. package/docs/hooks.md +148 -0
  48. package/docs/index.md +111 -0
  49. package/docs/installation.md +121 -0
  50. package/docs/internal-test-server.md +89 -0
  51. package/docs/locators.md +355 -0
  52. package/docs/mcp.md +485 -0
  53. package/docs/migrate-from-cypress.md +98 -0
  54. package/docs/migrate-from-java.md +108 -0
  55. package/docs/migrate-from-protractor.md +101 -0
  56. package/docs/migrate-from-testcafe.md +99 -0
  57. package/docs/migration-4.md +745 -0
  58. package/docs/mobile.md +338 -0
  59. package/docs/pageobjects.md +399 -0
  60. package/docs/parallel.md +187 -0
  61. package/docs/playwright.md +714 -0
  62. package/docs/plugins/aiTrace.md +49 -0
  63. package/docs/plugins/analyze.md +66 -0
  64. package/docs/plugins/auth.md +241 -0
  65. package/docs/plugins/autoDelay.md +48 -0
  66. package/docs/plugins/browser.md +41 -0
  67. package/docs/plugins/coverage.md +39 -0
  68. package/docs/plugins/customLocator.md +119 -0
  69. package/docs/plugins/customReporter.md +16 -0
  70. package/docs/plugins/expose.md +75 -0
  71. package/docs/plugins/heal.md +44 -0
  72. package/docs/plugins/junitReporter.md +51 -0
  73. package/docs/plugins/pageInfo.md +34 -0
  74. package/docs/plugins/pause.md +43 -0
  75. package/docs/plugins/pauseOnFail.md +18 -0
  76. package/docs/plugins/retryFailedStep.md +75 -0
  77. package/docs/plugins/screencast.md +55 -0
  78. package/docs/plugins/screenshot.md +58 -0
  79. package/docs/plugins/screenshotOnFail.md +18 -0
  80. package/docs/plugins/stepTimeout.md +65 -0
  81. package/docs/plugins.md +87 -0
  82. package/docs/puppeteer.md +314 -0
  83. package/docs/quickstart.md +120 -0
  84. package/docs/reports.md +195 -0
  85. package/docs/retry.md +311 -0
  86. package/docs/secrets.md +150 -0
  87. package/docs/sessions.md +80 -0
  88. package/docs/shadow.md +68 -0
  89. package/docs/store.md +94 -0
  90. package/docs/test-structure.md +275 -0
  91. package/docs/timeouts.md +183 -0
  92. package/docs/translation.md +247 -0
  93. package/docs/tutorial.md +323 -0
  94. package/docs/typescript.md +159 -0
  95. package/docs/web-element.md +251 -0
  96. package/docs/webdriver.md +641 -0
  97. package/docs/within.md +55 -0
  98. package/lib/actor.js +1 -36
  99. package/lib/ai.js +3 -2
  100. package/lib/aria.js +260 -0
  101. package/lib/assertions.js +18 -0
  102. package/lib/codecept.js +34 -25
  103. package/lib/command/check.js +2 -1
  104. package/lib/command/definitions.js +6 -7
  105. package/lib/command/dryRun.js +24 -5
  106. package/lib/command/generate.js +3 -1
  107. package/lib/command/gherkin/snippets.js +5 -4
  108. package/lib/command/init.js +249 -270
  109. package/lib/command/list.js +150 -10
  110. package/lib/command/query.js +218 -0
  111. package/lib/command/run-multiple.js +3 -1
  112. package/lib/command/run-workers.js +2 -14
  113. package/lib/command/run.js +3 -17
  114. package/lib/command/utils.js +14 -0
  115. package/lib/command/workers/runTests.js +91 -37
  116. package/lib/config.js +96 -18
  117. package/lib/container.js +115 -17
  118. package/lib/effects.js +17 -0
  119. package/lib/element/WebElement.js +246 -2
  120. package/lib/els.js +12 -6
  121. package/lib/globals.js +32 -19
  122. package/lib/heal.js +7 -4
  123. package/lib/helper/ApiDataFactory.js +2 -1
  124. package/lib/helper/Appium.js +8 -8
  125. package/lib/helper/FileSystem.js +3 -2
  126. package/lib/helper/GraphQLDataFactory.js +2 -1
  127. package/lib/helper/Playwright.js +358 -467
  128. package/lib/helper/Puppeteer.js +335 -192
  129. package/lib/helper/WebDriver.js +324 -111
  130. package/lib/helper/errors/ElementNotFound.js +5 -2
  131. package/lib/helper/errors/MultipleElementsFound.js +52 -0
  132. package/lib/helper/errors/NonFocusedType.js +8 -0
  133. package/lib/helper/extras/Download.js +45 -0
  134. package/lib/helper/extras/PlaywrightLocator.js +7 -107
  135. package/lib/helper/extras/elementSelection.js +58 -0
  136. package/lib/helper/extras/focusCheck.js +43 -0
  137. package/lib/helper/extras/richTextEditor.js +178 -0
  138. package/lib/helper/scripts/dropFile.js +11 -0
  139. package/lib/history.js +3 -2
  140. package/lib/html.js +103 -16
  141. package/lib/index.js +9 -1
  142. package/lib/listener/config.js +6 -4
  143. package/lib/listener/emptyRun.js +2 -1
  144. package/lib/listener/globalRetry.js +32 -6
  145. package/lib/listener/helpers.js +4 -1
  146. package/lib/listener/mocha.js +2 -1
  147. package/lib/listener/pageobjects.js +43 -0
  148. package/lib/listener/result.js +3 -2
  149. package/lib/locator.js +158 -16
  150. package/lib/mocha/cli.js +19 -1
  151. package/lib/mocha/factory.js +11 -1
  152. package/lib/mocha/inject.js +1 -1
  153. package/lib/mocha/scenarioConfig.js +2 -1
  154. package/lib/mocha/ui.js +5 -6
  155. package/lib/parser.js +2 -2
  156. package/lib/pause.js +38 -4
  157. package/lib/plugin/aiTrace.js +457 -0
  158. package/lib/plugin/analyze.js +9 -9
  159. package/lib/plugin/auth.js +5 -4
  160. package/lib/plugin/browser.js +77 -0
  161. package/lib/plugin/expose.js +159 -0
  162. package/lib/plugin/heal.js +47 -3
  163. package/lib/plugin/junitReporter.js +303 -0
  164. package/lib/plugin/pageInfo.js +54 -52
  165. package/lib/plugin/pause.js +131 -0
  166. package/lib/plugin/pauseOnFail.js +11 -33
  167. package/lib/plugin/retryFailedStep.js +43 -32
  168. package/lib/plugin/screencast.js +289 -0
  169. package/lib/plugin/screenshot.js +558 -0
  170. package/lib/plugin/screenshotOnFail.js +9 -170
  171. package/lib/plugin/stepTimeout.js +3 -2
  172. package/lib/recorder.js +1 -1
  173. package/lib/rerun.js +2 -1
  174. package/lib/result.js +2 -1
  175. package/lib/step/base.js +10 -9
  176. package/lib/step/comment.js +2 -2
  177. package/lib/step/config.js +15 -2
  178. package/lib/step/helper.js +4 -4
  179. package/lib/step/meta.js +3 -3
  180. package/lib/step/record.js +5 -5
  181. package/lib/store.js +72 -3
  182. package/lib/translation.js +2 -1
  183. package/lib/utils/loaderCheck.js +28 -0
  184. package/lib/utils/mask_data.js +2 -1
  185. package/lib/utils/pluginParser.js +151 -0
  186. package/lib/utils/trace.js +297 -0
  187. package/lib/utils/typescript.js +188 -23
  188. package/lib/utils.js +77 -3
  189. package/lib/workers.js +65 -40
  190. package/package.json +35 -30
  191. package/typings/index.d.ts +119 -8
  192. package/typings/promiseBasedTypes.d.ts +3158 -6065
  193. package/typings/types.d.ts +3453 -6494
  194. package/docs/webapi/amOnPage.mustache +0 -11
  195. package/docs/webapi/appendField.mustache +0 -11
  196. package/docs/webapi/attachFile.mustache +0 -12
  197. package/docs/webapi/blur.mustache +0 -18
  198. package/docs/webapi/checkOption.mustache +0 -13
  199. package/docs/webapi/clearCookie.mustache +0 -9
  200. package/docs/webapi/clearField.mustache +0 -9
  201. package/docs/webapi/click.mustache +0 -29
  202. package/docs/webapi/clickLink.mustache +0 -8
  203. package/docs/webapi/closeCurrentTab.mustache +0 -7
  204. package/docs/webapi/closeOtherTabs.mustache +0 -8
  205. package/docs/webapi/dontSee.mustache +0 -11
  206. package/docs/webapi/dontSeeCheckboxIsChecked.mustache +0 -10
  207. package/docs/webapi/dontSeeCookie.mustache +0 -8
  208. package/docs/webapi/dontSeeCurrentUrlEquals.mustache +0 -10
  209. package/docs/webapi/dontSeeElement.mustache +0 -8
  210. package/docs/webapi/dontSeeElementInDOM.mustache +0 -8
  211. package/docs/webapi/dontSeeInCurrentUrl.mustache +0 -4
  212. package/docs/webapi/dontSeeInField.mustache +0 -11
  213. package/docs/webapi/dontSeeInSource.mustache +0 -8
  214. package/docs/webapi/dontSeeInTitle.mustache +0 -8
  215. package/docs/webapi/dontSeeTraffic.mustache +0 -13
  216. package/docs/webapi/doubleClick.mustache +0 -13
  217. package/docs/webapi/downloadFile.mustache +0 -12
  218. package/docs/webapi/dragAndDrop.mustache +0 -9
  219. package/docs/webapi/dragSlider.mustache +0 -11
  220. package/docs/webapi/executeAsyncScript.mustache +0 -24
  221. package/docs/webapi/executeScript.mustache +0 -26
  222. package/docs/webapi/fillField.mustache +0 -16
  223. package/docs/webapi/flushNetworkTraffics.mustache +0 -5
  224. package/docs/webapi/focus.mustache +0 -13
  225. package/docs/webapi/forceClick.mustache +0 -28
  226. package/docs/webapi/forceRightClick.mustache +0 -18
  227. package/docs/webapi/grabAllWindowHandles.mustache +0 -7
  228. package/docs/webapi/grabAttributeFrom.mustache +0 -10
  229. package/docs/webapi/grabAttributeFromAll.mustache +0 -9
  230. package/docs/webapi/grabBrowserLogs.mustache +0 -9
  231. package/docs/webapi/grabCookie.mustache +0 -11
  232. package/docs/webapi/grabCssPropertyFrom.mustache +0 -11
  233. package/docs/webapi/grabCssPropertyFromAll.mustache +0 -10
  234. package/docs/webapi/grabCurrentUrl.mustache +0 -9
  235. package/docs/webapi/grabCurrentWindowHandle.mustache +0 -6
  236. package/docs/webapi/grabDataFromPerformanceTiming.mustache +0 -20
  237. package/docs/webapi/grabElementBoundingRect.mustache +0 -20
  238. package/docs/webapi/grabGeoLocation.mustache +0 -8
  239. package/docs/webapi/grabHTMLFrom.mustache +0 -10
  240. package/docs/webapi/grabHTMLFromAll.mustache +0 -9
  241. package/docs/webapi/grabNumberOfOpenTabs.mustache +0 -8
  242. package/docs/webapi/grabNumberOfVisibleElements.mustache +0 -9
  243. package/docs/webapi/grabPageScrollPosition.mustache +0 -8
  244. package/docs/webapi/grabPopupText.mustache +0 -5
  245. package/docs/webapi/grabRecordedNetworkTraffics.mustache +0 -10
  246. package/docs/webapi/grabSource.mustache +0 -8
  247. package/docs/webapi/grabTextFrom.mustache +0 -10
  248. package/docs/webapi/grabTextFromAll.mustache +0 -9
  249. package/docs/webapi/grabTitle.mustache +0 -8
  250. package/docs/webapi/grabValueFrom.mustache +0 -9
  251. package/docs/webapi/grabValueFromAll.mustache +0 -8
  252. package/docs/webapi/grabWebElement.mustache +0 -9
  253. package/docs/webapi/grabWebElements.mustache +0 -9
  254. package/docs/webapi/moveCursorTo.mustache +0 -12
  255. package/docs/webapi/openNewTab.mustache +0 -7
  256. package/docs/webapi/pressKey.mustache +0 -12
  257. package/docs/webapi/pressKeyDown.mustache +0 -12
  258. package/docs/webapi/pressKeyUp.mustache +0 -12
  259. package/docs/webapi/pressKeyWithKeyNormalization.mustache +0 -60
  260. package/docs/webapi/refreshPage.mustache +0 -6
  261. package/docs/webapi/resizeWindow.mustache +0 -6
  262. package/docs/webapi/rightClick.mustache +0 -14
  263. package/docs/webapi/saveElementScreenshot.mustache +0 -10
  264. package/docs/webapi/saveScreenshot.mustache +0 -12
  265. package/docs/webapi/say.mustache +0 -10
  266. package/docs/webapi/scrollIntoView.mustache +0 -11
  267. package/docs/webapi/scrollPageToBottom.mustache +0 -6
  268. package/docs/webapi/scrollPageToTop.mustache +0 -6
  269. package/docs/webapi/scrollTo.mustache +0 -12
  270. package/docs/webapi/see.mustache +0 -11
  271. package/docs/webapi/seeAttributesOnElements.mustache +0 -9
  272. package/docs/webapi/seeCheckboxIsChecked.mustache +0 -10
  273. package/docs/webapi/seeCookie.mustache +0 -8
  274. package/docs/webapi/seeCssPropertiesOnElements.mustache +0 -9
  275. package/docs/webapi/seeCurrentUrlEquals.mustache +0 -11
  276. package/docs/webapi/seeElement.mustache +0 -8
  277. package/docs/webapi/seeElementInDOM.mustache +0 -8
  278. package/docs/webapi/seeInCurrentUrl.mustache +0 -8
  279. package/docs/webapi/seeInField.mustache +0 -12
  280. package/docs/webapi/seeInPopup.mustache +0 -8
  281. package/docs/webapi/seeInSource.mustache +0 -7
  282. package/docs/webapi/seeInTitle.mustache +0 -8
  283. package/docs/webapi/seeNumberOfElements.mustache +0 -11
  284. package/docs/webapi/seeNumberOfVisibleElements.mustache +0 -10
  285. package/docs/webapi/seeTextEquals.mustache +0 -9
  286. package/docs/webapi/seeTitleEquals.mustache +0 -8
  287. package/docs/webapi/seeTraffic.mustache +0 -36
  288. package/docs/webapi/selectOption.mustache +0 -21
  289. package/docs/webapi/setCookie.mustache +0 -16
  290. package/docs/webapi/setGeoLocation.mustache +0 -12
  291. package/docs/webapi/startRecordingTraffic.mustache +0 -8
  292. package/docs/webapi/startRecordingWebSocketMessages.mustache +0 -8
  293. package/docs/webapi/stopRecordingTraffic.mustache +0 -5
  294. package/docs/webapi/stopRecordingWebSocketMessages.mustache +0 -7
  295. package/docs/webapi/switchTo.mustache +0 -9
  296. package/docs/webapi/switchToNextTab.mustache +0 -10
  297. package/docs/webapi/switchToPreviousTab.mustache +0 -10
  298. package/docs/webapi/type.mustache +0 -21
  299. package/docs/webapi/uncheckOption.mustache +0 -13
  300. package/docs/webapi/wait.mustache +0 -8
  301. package/docs/webapi/waitForClickable.mustache +0 -11
  302. package/docs/webapi/waitForCookie.mustache +0 -9
  303. package/docs/webapi/waitForDetached.mustache +0 -10
  304. package/docs/webapi/waitForDisabled.mustache +0 -6
  305. package/docs/webapi/waitForElement.mustache +0 -11
  306. package/docs/webapi/waitForEnabled.mustache +0 -6
  307. package/docs/webapi/waitForFunction.mustache +0 -17
  308. package/docs/webapi/waitForInvisible.mustache +0 -10
  309. package/docs/webapi/waitForNumberOfTabs.mustache +0 -9
  310. package/docs/webapi/waitForText.mustache +0 -13
  311. package/docs/webapi/waitForValue.mustache +0 -10
  312. package/docs/webapi/waitForVisible.mustache +0 -10
  313. package/docs/webapi/waitInUrl.mustache +0 -9
  314. package/docs/webapi/waitNumberOfVisibleElements.mustache +0 -10
  315. package/docs/webapi/waitToHide.mustache +0 -10
  316. package/docs/webapi/waitUrlEquals.mustache +0 -10
  317. package/lib/helper/AI.js +0 -214
  318. package/lib/helper/Mochawesome.js +0 -96
  319. package/lib/helper/extras/PlaywrightReactVueLocator.js +0 -52
  320. package/lib/helper/extras/React.js +0 -65
  321. package/lib/listener/enhancedGlobalRetry.js +0 -110
  322. package/lib/plugin/enhancedRetryFailedStep.js +0 -99
  323. package/lib/plugin/htmlReporter.js +0 -3648
  324. package/lib/plugin/stepByStepReport.js +0 -427
  325. package/lib/plugin/subtitles.js +0 -89
  326. package/lib/retryCoordinator.js +0 -207
package/docs/hooks.md ADDED
@@ -0,0 +1,148 @@
1
+ ---
2
+ permalink: /hooks
3
+ title: Extending CodeceptJS
4
+ ---
5
+
6
+ # Extending CodeceptJS
7
+
8
+ CodeceptJS has four extension points. Pick the lightest one that does the job:
9
+
10
+ | Use | To |
11
+ | --- | --- |
12
+ | [`bootstrap` / `teardown`](/bootstrap) | run setup or teardown code once, around the whole suite |
13
+ | [Event listeners](#event-listeners) | react to test, suite, or step events without packaging anything |
14
+ | [Plugins](#plugins) | bundle reusable behavior — listeners, recorder hooks, config — into a module |
15
+ | [Custom helpers](/helpers) | add new `I.*` actions backed by a browser or an HTTP library |
16
+
17
+ Listeners and plugins use CodeceptJS internals — the `event` dispatcher, the `recorder` promise chain, the `container`, `output`. See [Architecture](/architecture) for what those are and how a test runs.
18
+
19
+ ## Event Listeners
20
+
21
+ Attach a listener to `event.dispatcher` to run code at any point in the [test lifecycle](/architecture#events). A listener can live in a [plugin](#plugins) or in your [`bootstrap`](/bootstrap) script.
22
+
23
+ ```js
24
+ import { event } from 'codeceptjs'
25
+
26
+ event.dispatcher.on(event.test.before, test => {
27
+ console.log(`starting ${test.title}`)
28
+ })
29
+ ```
30
+
31
+ [Sync events](/architecture#events) run inline. For async work, queue it on the recorder so it runs in order with the test's steps:
32
+
33
+ ```js
34
+ import { event, recorder } from 'codeceptjs'
35
+
36
+ event.dispatcher.on(event.test.before, () => {
37
+ recorder.add('seed fixture data', async () => {
38
+ await api.post('/users', { name: 'john', email: 'john@example.com' })
39
+ })
40
+ })
41
+ ```
42
+
43
+ A listener often needs to know *where* in the run it is — which test is active, or whether this is a dry run. Read that from [`store`](/store) instead of tracking it yourself:
44
+
45
+ ```js
46
+ import { event, store } from 'codeceptjs'
47
+
48
+ event.dispatcher.on(event.step.before, () => {
49
+ if (store.dryRun) return // skip side effects on a dry run
50
+ })
51
+ ```
52
+
53
+ See [Architecture › Events](/architecture#events) for the full event list and the test and step object fields, and the [Store reference](/store) for every state field.
54
+
55
+ ## Plugins
56
+
57
+ A plugin packages listeners, recorder hooks, container changes, and config into one module. CodeceptJS ships [built-in plugins](/plugins) — [their source](https://github.com/codeceptjs/CodeceptJS/tree/master/lib/plugin) doubles as example code.
58
+
59
+ A plugin is a module that exports a function. CodeceptJS calls it once at startup with the plugin's config:
60
+
61
+ ```js
62
+ import { event } from 'codeceptjs'
63
+
64
+ const defaultConfig = {
65
+ someOption: true,
66
+ }
67
+
68
+ export default function (config) {
69
+ config = { ...defaultConfig, ...config }
70
+
71
+ event.dispatcher.on(event.test.before, test => {
72
+ // use config, register listeners, hook into the recorder
73
+ })
74
+ }
75
+ ```
76
+
77
+ ### Enabling a plugin
78
+
79
+ Add it to the `plugins` section of the config and point `require` at the module:
80
+
81
+ ```js
82
+ plugins: {
83
+ myPlugin: {
84
+ require: './path/to/plugin', // relative to the config file
85
+ enabled: true,
86
+ }
87
+ }
88
+ ```
89
+
90
+ - `require` — path to the plugin file, relative to the config file.
91
+ - `enabled` — set `true` to load it.
92
+ - any other key is passed straight to the plugin function as config.
93
+
94
+ A disabled or unlisted plugin can be turned on for a single run from the command line:
95
+
96
+ ```
97
+ npx codeceptjs run --plugin myPlugin
98
+ npx codeceptjs run --plugin myPlugin,allure
99
+ ```
100
+
101
+ ### Example: run code for a tagged group of tests
102
+
103
+ [Tag](/test-structure#tags) the tests you want to target, then check the tag on `event.test.before`:
104
+
105
+ ```js
106
+ import { event, recorder } from 'codeceptjs'
107
+
108
+ export default function () {
109
+ event.dispatcher.on(event.test.before, test => {
110
+ if (!test.tags.includes('@populate')) return
111
+
112
+ recorder.add('populate database', async () => {
113
+ // seed data for this test
114
+ })
115
+ })
116
+ }
117
+ ```
118
+
119
+ ### Example: run async setup before all tests
120
+
121
+ `event.all.before` can fire before the recorder chain is running, so start it first:
122
+
123
+ ```js
124
+ import { event, recorder } from 'codeceptjs'
125
+
126
+ export default function () {
127
+ event.dispatcher.on(event.all.before, () => {
128
+ recorder.startUnlessRunning()
129
+ recorder.add('warm up cache', async () => {
130
+ // your async setup
131
+ })
132
+ })
133
+ }
134
+ ```
135
+
136
+ Wrapping bootstrap logic in a plugin like this lets you share it across projects and combine several setup scripts.
137
+
138
+ ## Custom Helpers
139
+
140
+ To add new `I.*` actions — a higher-level step, a wrapper around a browser SDK, an assertion against your backend — write a helper class. Helpers can also be published as npm packages. See [Custom Helpers](/helpers).
141
+
142
+ ## Bootstrap & Teardown
143
+
144
+ For setup and teardown that needs no packaging — start a server, create a database — use the `bootstrap` and `teardown` config hooks. In [parallel runs](/parallel), `bootstrapAll` / `teardownAll` run once in the parent process. See [Bootstrap & Teardown](/bootstrap).
145
+
146
+ ---
147
+
148
+ **See also:** [Architecture](/architecture) · [Plugins reference](/plugins) · [Custom Helpers](/helpers) · [Bootstrap & Teardown](/bootstrap)
package/docs/index.md ADDED
@@ -0,0 +1,111 @@
1
+ ---
2
+ layout: Landing
3
+ sidebar: false
4
+ actionText: Quickstart
5
+ actionLink: /quickstart
6
+ ---
7
+
8
+ ::: slot pause
9
+ ## Write a Test with Interactive Pause
10
+
11
+ Open a browser on an empty page and pause execution.
12
+ Type in commands to complete the test scenario.
13
+
14
+ Successful commands will be saved into a file.
15
+
16
+ ```js
17
+ Scenario('Checkout test', ({ I }) => {
18
+ I.amOnPage('/checkout');
19
+ pause();
20
+ })
21
+ ```
22
+ Copy commands from a file into a test. A test is ready!
23
+ :::
24
+
25
+ ::: slot write
26
+ ## Write Tests from UI
27
+
28
+ With CodeceptUI you can write your tests without closing a browser at all.
29
+
30
+ Write initial commands and execute a test. An interactive pause will be started when test finishes.
31
+
32
+ Share one browser accross test runs to save time on opening a browser.
33
+ :::
34
+
35
+
36
+ ::: slot autocomplete
37
+ ## Powered with IntelliSense
38
+
39
+ Use auto-completion writing a test fast.
40
+
41
+ We use TypeScript type definitions that are automatically updated for custom steps and page objects.
42
+
43
+ Writing a test in Visual Studio Code is as easy as picking a correct action and putting a parameter. It's really that nice!
44
+
45
+ :::
46
+
47
+
48
+ ::: slot ui
49
+
50
+ ## Watch & Run Tests from UI
51
+
52
+ We have a flexible interactive web runner which allows you to watch, debug, and write your tests in a web mode.
53
+
54
+ Features:
55
+
56
+ * Toggle headless/window mode with one click
57
+ * See HTML snapshot of each step
58
+ * Works with WebDriver, Puppeteer, Playwright
59
+ * Shows step-by-step execution
60
+ * Integrated with your local IDE
61
+
62
+ :::
63
+
64
+
65
+ ::: slot run
66
+
67
+ ## Print a Test
68
+
69
+ Each executed step will be printed on screen when running with `--steps`
70
+ ```js
71
+ Scenario('Checkout test', ({ I }) => {
72
+ I.amOnPage('/checkout');
73
+ I.fillField('First name', 'davert');
74
+ I.fillField('#lastName', 'mik');
75
+ I.fillField('Promo code', '123345')
76
+ //...
77
+ })
78
+ ```
79
+
80
+ :::
81
+
82
+ ::: slot code
83
+
84
+ ## Realworld Example
85
+
86
+ Can we use it for long scenarios? Sure!
87
+
88
+ ```js
89
+ import { faker } from '@faker-js/faker' // Use 3rd-party JS code
90
+
91
+ Feature('Store');
92
+
93
+ Scenario('Create a new store', async ({ I, login, SettingsPage }) => {
94
+ const storeName = faker.lorem.slug();
95
+ login('customer'); // Login customer from saved cookies
96
+ SettingsPage.open(); // Use Page objects
97
+ I.dontSee(storeName, '.settings'); // Assert text not present inside an element (located by CSS)
98
+ I.click('Add', '.settings'); // Click link by text inside element (located by CSS)
99
+ I.fillField('Store Name', storeName); // Fill fields by labels or placeholders
100
+ I.fillField('Email', faker.internet.email());
101
+ I.fillField('Telephone', faker.phone.phoneNumberFormat());
102
+ I.selectInDropdown('Status', 'Active'); // Use custom methods
103
+ I.click('Create', step.retry(2)); // Retry flaky step
104
+ I.waitInUrl('/settings/setup/stores'); // Explicit waiter
105
+ I.see(storeName, '.settings'); // Assert text present inside an element (located by CSS)
106
+ const storeId = await I.grabTextFrom('#store-id'); // Use await to get information from browser
107
+ I.say(`Created a store with ${storeId}`); // Print custom comments
108
+ }).tag('stores');`;
109
+
110
+ ```
111
+ :::
@@ -0,0 +1,121 @@
1
+ ---
2
+ permalink: /installation
3
+ title: Installation
4
+ ---
5
+
6
+ # Installation
7
+
8
+ For the quickest start (CodeceptJS + Playwright) follow the [Quickstart](/quickstart). This page covers every browser, mobile, and API helper and what each one needs installed.
9
+
10
+ ## Set up a project
11
+
12
+ ```sh
13
+ npm init -y # if you don't have a package.json yet
14
+ npm i codeceptjs --save-dev
15
+ ```
16
+
17
+ Install one of the helpers below, then scaffold the config and a sample test:
18
+
19
+ ```sh
20
+ npx codeceptjs init
21
+ ```
22
+
23
+ `init` runs a short wizard, writes `codecept.conf.js` and a sample test, and installs the helper's driver package if it's missing. The [Quickstart](/quickstart) walks through the questions.
24
+
25
+ ## Playwright
26
+
27
+ Fast, modern browser automation — the recommended helper for web testing.
28
+
29
+ ```sh
30
+ npm i playwright --save-dev
31
+ npx playwright install --with-deps
32
+ ```
33
+
34
+ `playwright install` downloads the browser binaries; `--with-deps` also installs the Linux system libraries they need (run it with `sudo` if your user can't install packages).
35
+
36
+ Set `browser` in the helper config to one of:
37
+
38
+ - `chromium` — default
39
+ - `firefox`
40
+ - `webkit` — the open-source Safari engine
41
+ - `electron` — test an Electron app (set `electron.executablePath`)
42
+
43
+ To drive branded Chrome or Edge instead of bundled Chromium, install that channel — `npx playwright install chrome` (or `msedge`) — and set `channel` in the config. See the [Playwright helper](/playwright).
44
+
45
+ ## Puppeteer
46
+
47
+ Chrome/Chromium automation over the DevTools protocol.
48
+
49
+ ```sh
50
+ npm i puppeteer --save-dev
51
+ ```
52
+
53
+ Puppeteer downloads a matching Chromium when it installs — nothing else to set up. To drive an existing Chrome instead, set `chrome.executablePath` in the helper config (or install `puppeteer-core` and point it at your browser). See the [Puppeteer helper](/puppeteer).
54
+
55
+ ## WebDriver
56
+
57
+ W3C WebDriver — runs Chrome, Firefox, Edge, Safari, and remote or cloud grids.
58
+
59
+ ```sh
60
+ npm i webdriverio --save-dev
61
+ ```
62
+
63
+ WebdriverIO 9 downloads and starts the matching driver automatically — no Selenium server, ChromeDriver, or GeckoDriver to install or run. Just set `browser` (`chrome`, `firefox`, `MicrosoftEdge`, `safari`) in `codecept.conf.js` — see the [WebDriver helper](/webdriver).
64
+
65
+ To run against a cloud grid (Sauce Labs, BrowserStack, LambdaTest, and so on) instead, set the grid's `host`, `port`, `user`, and `key` (or `protocol` / `path`) in the helper config. For running this on CI, see [Continuous Integration](/continuous-integration).
66
+
67
+ ## Appium (mobile)
68
+
69
+ Native iOS and Android testing. Appium speaks the WebDriver protocol, so CodeceptJS drives it through `webdriverio`:
70
+
71
+ ```sh
72
+ npm i webdriverio --save-dev
73
+ npm i -g appium
74
+ ```
75
+
76
+ Install the platform driver(s) and start the server:
77
+
78
+ ```sh
79
+ appium driver install uiautomator2 # Android
80
+ appium driver install xcuitest # iOS
81
+ appium
82
+ ```
83
+
84
+ You'll also need the Android SDK and an emulator or device, or Xcode and a simulator or device (or a device-cloud account). Set `platformName`, `deviceName`, and `app` in the helper config — see [Mobile Testing](/mobile).
85
+
86
+ ## API testing
87
+
88
+ REST and GraphQL tests need no browser — the helpers are built in (they use `axios`, already a dependency):
89
+
90
+ ```sh
91
+ npm i codeceptjs --save-dev
92
+ ```
93
+
94
+ Choose `REST` or `GraphQL` when `init` asks, set `endpoint` in the config, and add the `JSONResponse` helper if you want response assertions. See [Testing APIs](/api).
95
+
96
+ ## ESM
97
+
98
+ CodeceptJS 4.x uses ECMAScript Modules. A project created by `init` is set up for it; an existing project needs `"type": "module"` in `package.json` and `import` syntax in the config and tests. Coming from 3.x — see the [Migration Guide](/migration-4).
99
+
100
+ ## TypeScript
101
+
102
+ `npx codeceptjs init` scaffolds a TypeScript project when you answer **Yes** to "Do you plan to write tests in TypeScript?" — it writes `codecept.conf.ts` and `*_test.ts` files.
103
+
104
+ The config file (`codecept.conf.ts`) and helpers are transpiled automatically. Test files need a loader; install [`tsx`](https://tsx.is) and add it to `require`:
105
+
106
+ ```sh
107
+ npm i tsx --save-dev
108
+ ```
109
+
110
+ ```ts
111
+ // codecept.conf.ts
112
+ export const config = {
113
+ tests: './**/*_test.ts',
114
+ require: ['tsx/cjs'], // loads the *_test.ts files
115
+ helpers: {
116
+ Playwright: { url: 'http://localhost', browser: 'chromium' },
117
+ },
118
+ }
119
+ ```
120
+
121
+ Run tests as usual with `npx codeceptjs run`. For promise-based typings, types for page objects and custom helpers, and custom locator types, see the [TypeScript guide](/typescript).
@@ -0,0 +1,89 @@
1
+ # Internal API Test Server
2
+
3
+ This directory contains the internal API test server implementation that replaces the third-party `json-server` dependency.
4
+
5
+ ## Files
6
+
7
+ - `lib/test-server.js` - Main TestServer class implementation
8
+ - `bin/test-server.js` - CLI script to run the server standalone
9
+
10
+ ## Usage
11
+
12
+ ### As npm script:
13
+
14
+ ```bash
15
+ npm run test-server
16
+ ```
17
+
18
+ ### Directly:
19
+
20
+ ```bash
21
+ node bin/test-server.js [options] [db-file]
22
+ ```
23
+
24
+ ### Options:
25
+
26
+ - `-p, --port <port>` - Port to listen on (default: 8010)
27
+ - `--host <host>` - Host to bind to (default: 0.0.0.0)
28
+ - `db-file` - Path to JSON database file (default: test/data/rest/db.json)
29
+
30
+ ## Features
31
+
32
+ - **Full REST API compatibility** with json-server
33
+ - **Automatic file watching** - Reloads data when db.json file changes
34
+ - **CORS support** - Allows cross-origin requests for testing
35
+ - **Custom headers support** - Handles special headers like X-Test
36
+ - **File upload endpoints** - Basic file upload simulation
37
+ - **Express.js based** - Uses familiar Express.js framework
38
+
39
+ ## API Endpoints
40
+
41
+ The server provides the same API endpoints as json-server:
42
+
43
+ ### Users
44
+
45
+ - `GET /user` - Get user data
46
+ - `POST /user` - Create/update user
47
+ - `PATCH /user` - Partially update user
48
+ - `PUT /user` - Replace user
49
+
50
+ ### Posts
51
+
52
+ - `GET /posts` - Get all posts
53
+ - `GET /posts/:id` - Get specific post
54
+ - `POST /posts` - Create new post
55
+ - `PUT /posts/:id` - Replace specific post
56
+ - `PATCH /posts/:id` - Partially update specific post
57
+ - `DELETE /posts/:id` - Delete specific post
58
+
59
+ ### Comments
60
+
61
+ - `GET /comments` - Get all comments
62
+ - `POST /comments` - Create new comment
63
+ - `DELETE /comments/:id` - Delete specific comment
64
+
65
+ ### Utility
66
+
67
+ - `GET /headers` - Return request headers (for testing)
68
+ - `POST /headers` - Return request headers (for testing)
69
+ - `POST /upload` - File upload simulation
70
+ - `POST /_reload` - Manually reload database file
71
+
72
+ ## Migration from json-server
73
+
74
+ This server is designed as a drop-in replacement for json-server. The key differences:
75
+
76
+ 1. **No CLI options** - Configuration is done through constructor options or CLI args
77
+ 2. **Automatic file watching** - No need for `--watch` flag
78
+ 3. **Built-in middleware** - Headers and CORS are handled automatically
79
+ 4. **Simpler file upload** - Basic implementation without full multipart support
80
+
81
+ ## Testing
82
+
83
+ The server is used by the following test suites:
84
+
85
+ - `test/rest/REST_test.js` - REST helper tests
86
+ - `test/rest/ApiDataFactory_test.js` - API data factory tests
87
+ - `test/helper/JSONResponse_test.js` - JSON response helper tests
88
+
89
+ All tests pass with the internal server, proving full compatibility.