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.
- package/README.md +39 -28
- package/bin/codecept.js +15 -2
- package/bin/codeceptq.js +49 -0
- package/bin/mcp-server.js +1189 -0
- package/docs/advanced.md +201 -0
- package/docs/agents.md +181 -0
- package/docs/ai.md +489 -0
- package/docs/aitrace.md +266 -0
- package/docs/api.md +332 -0
- package/docs/architecture.md +235 -0
- package/docs/assertions.md +415 -0
- package/docs/auth.md +318 -0
- package/docs/basics.md +424 -0
- package/docs/bdd.md +539 -0
- package/docs/best.md +240 -0
- package/docs/bootstrap.md +132 -0
- package/docs/commands.md +352 -0
- package/docs/community-helpers.md +63 -0
- package/docs/configuration.md +185 -0
- package/docs/continuous-integration.md +431 -0
- package/docs/custom-helpers.md +297 -0
- package/docs/data.md +448 -0
- package/docs/debugging.md +332 -0
- package/docs/detox.md +235 -0
- package/docs/docker.md +107 -0
- package/docs/effects.md +179 -0
- package/docs/element-based-testing.md +295 -0
- package/docs/element-selection.md +125 -0
- package/docs/els.md +328 -0
- package/docs/environment-variables.md +131 -0
- package/docs/examples.md +160 -0
- package/docs/heal.md +213 -0
- package/docs/helpers/ApiDataFactory.md +267 -0
- package/docs/helpers/Appium.md +1419 -0
- package/docs/helpers/Detox.md +665 -0
- package/docs/helpers/ExpectHelper.md +275 -0
- package/docs/helpers/FileSystem.md +152 -0
- package/docs/helpers/GraphQL.md +152 -0
- package/docs/helpers/GraphQLDataFactory.md +226 -0
- package/docs/helpers/JSONResponse.md +255 -0
- package/docs/helpers/MockRequest.md +377 -0
- package/docs/helpers/Playwright.md +2970 -0
- package/docs/helpers/Puppeteer-firefox.md +86 -0
- package/docs/helpers/Puppeteer.md +2583 -0
- package/docs/helpers/REST.md +289 -0
- package/docs/helpers/WebDriver.md +2639 -0
- package/docs/hooks.md +148 -0
- package/docs/index.md +111 -0
- package/docs/installation.md +121 -0
- package/docs/internal-test-server.md +89 -0
- package/docs/locators.md +355 -0
- package/docs/mcp.md +485 -0
- package/docs/migrate-from-cypress.md +98 -0
- package/docs/migrate-from-java.md +108 -0
- package/docs/migrate-from-protractor.md +101 -0
- package/docs/migrate-from-testcafe.md +99 -0
- package/docs/migration-4.md +745 -0
- package/docs/mobile.md +338 -0
- package/docs/pageobjects.md +399 -0
- package/docs/parallel.md +187 -0
- package/docs/playwright.md +714 -0
- package/docs/plugins/aiTrace.md +49 -0
- package/docs/plugins/analyze.md +66 -0
- package/docs/plugins/auth.md +241 -0
- package/docs/plugins/autoDelay.md +48 -0
- package/docs/plugins/browser.md +41 -0
- package/docs/plugins/coverage.md +39 -0
- package/docs/plugins/customLocator.md +119 -0
- package/docs/plugins/customReporter.md +16 -0
- package/docs/plugins/expose.md +75 -0
- package/docs/plugins/heal.md +44 -0
- package/docs/plugins/junitReporter.md +51 -0
- package/docs/plugins/pageInfo.md +34 -0
- package/docs/plugins/pause.md +43 -0
- package/docs/plugins/pauseOnFail.md +18 -0
- package/docs/plugins/retryFailedStep.md +75 -0
- package/docs/plugins/screencast.md +55 -0
- package/docs/plugins/screenshot.md +58 -0
- package/docs/plugins/screenshotOnFail.md +18 -0
- package/docs/plugins/stepTimeout.md +65 -0
- package/docs/plugins.md +87 -0
- package/docs/puppeteer.md +314 -0
- package/docs/quickstart.md +120 -0
- package/docs/reports.md +195 -0
- package/docs/retry.md +311 -0
- package/docs/secrets.md +150 -0
- package/docs/sessions.md +80 -0
- package/docs/shadow.md +68 -0
- package/docs/store.md +94 -0
- package/docs/test-structure.md +275 -0
- package/docs/timeouts.md +183 -0
- package/docs/translation.md +247 -0
- package/docs/tutorial.md +323 -0
- package/docs/typescript.md +159 -0
- package/docs/web-element.md +251 -0
- package/docs/webdriver.md +641 -0
- package/docs/within.md +55 -0
- package/lib/actor.js +1 -36
- package/lib/ai.js +3 -2
- package/lib/aria.js +260 -0
- package/lib/assertions.js +18 -0
- package/lib/codecept.js +34 -25
- package/lib/command/check.js +2 -1
- package/lib/command/definitions.js +6 -7
- package/lib/command/dryRun.js +24 -5
- package/lib/command/generate.js +3 -1
- package/lib/command/gherkin/snippets.js +5 -4
- package/lib/command/init.js +249 -270
- package/lib/command/list.js +150 -10
- package/lib/command/query.js +218 -0
- package/lib/command/run-multiple.js +3 -1
- package/lib/command/run-workers.js +2 -14
- package/lib/command/run.js +3 -17
- package/lib/command/utils.js +14 -0
- package/lib/command/workers/runTests.js +91 -37
- package/lib/config.js +96 -18
- package/lib/container.js +115 -17
- package/lib/effects.js +17 -0
- package/lib/element/WebElement.js +246 -2
- package/lib/els.js +12 -6
- package/lib/globals.js +32 -19
- package/lib/heal.js +7 -4
- package/lib/helper/ApiDataFactory.js +2 -1
- package/lib/helper/Appium.js +8 -8
- package/lib/helper/FileSystem.js +3 -2
- package/lib/helper/GraphQLDataFactory.js +2 -1
- package/lib/helper/Playwright.js +358 -467
- package/lib/helper/Puppeteer.js +335 -192
- package/lib/helper/WebDriver.js +324 -111
- package/lib/helper/errors/ElementNotFound.js +5 -2
- package/lib/helper/errors/MultipleElementsFound.js +52 -0
- package/lib/helper/errors/NonFocusedType.js +8 -0
- package/lib/helper/extras/Download.js +45 -0
- package/lib/helper/extras/PlaywrightLocator.js +7 -107
- package/lib/helper/extras/elementSelection.js +58 -0
- package/lib/helper/extras/focusCheck.js +43 -0
- package/lib/helper/extras/richTextEditor.js +178 -0
- package/lib/helper/scripts/dropFile.js +11 -0
- package/lib/history.js +3 -2
- package/lib/html.js +103 -16
- package/lib/index.js +9 -1
- package/lib/listener/config.js +6 -4
- package/lib/listener/emptyRun.js +2 -1
- package/lib/listener/globalRetry.js +32 -6
- package/lib/listener/helpers.js +4 -1
- package/lib/listener/mocha.js +2 -1
- package/lib/listener/pageobjects.js +43 -0
- package/lib/listener/result.js +3 -2
- package/lib/locator.js +158 -16
- package/lib/mocha/cli.js +19 -1
- package/lib/mocha/factory.js +11 -1
- package/lib/mocha/inject.js +1 -1
- package/lib/mocha/scenarioConfig.js +2 -1
- package/lib/mocha/ui.js +5 -6
- package/lib/parser.js +2 -2
- package/lib/pause.js +38 -4
- package/lib/plugin/aiTrace.js +457 -0
- package/lib/plugin/analyze.js +9 -9
- package/lib/plugin/auth.js +5 -4
- package/lib/plugin/browser.js +77 -0
- package/lib/plugin/expose.js +159 -0
- package/lib/plugin/heal.js +47 -3
- package/lib/plugin/junitReporter.js +303 -0
- package/lib/plugin/pageInfo.js +54 -52
- package/lib/plugin/pause.js +131 -0
- package/lib/plugin/pauseOnFail.js +11 -33
- package/lib/plugin/retryFailedStep.js +43 -32
- package/lib/plugin/screencast.js +289 -0
- package/lib/plugin/screenshot.js +558 -0
- package/lib/plugin/screenshotOnFail.js +9 -170
- package/lib/plugin/stepTimeout.js +3 -2
- package/lib/recorder.js +1 -1
- package/lib/rerun.js +2 -1
- package/lib/result.js +2 -1
- package/lib/step/base.js +10 -9
- package/lib/step/comment.js +2 -2
- package/lib/step/config.js +15 -2
- package/lib/step/helper.js +4 -4
- package/lib/step/meta.js +3 -3
- package/lib/step/record.js +5 -5
- package/lib/store.js +72 -3
- package/lib/translation.js +2 -1
- package/lib/utils/loaderCheck.js +28 -0
- package/lib/utils/mask_data.js +2 -1
- package/lib/utils/pluginParser.js +151 -0
- package/lib/utils/trace.js +297 -0
- package/lib/utils/typescript.js +188 -23
- package/lib/utils.js +77 -3
- package/lib/workers.js +65 -40
- package/package.json +35 -30
- package/typings/index.d.ts +119 -8
- package/typings/promiseBasedTypes.d.ts +3158 -6065
- package/typings/types.d.ts +3453 -6494
- package/docs/webapi/amOnPage.mustache +0 -11
- package/docs/webapi/appendField.mustache +0 -11
- package/docs/webapi/attachFile.mustache +0 -12
- package/docs/webapi/blur.mustache +0 -18
- package/docs/webapi/checkOption.mustache +0 -13
- package/docs/webapi/clearCookie.mustache +0 -9
- package/docs/webapi/clearField.mustache +0 -9
- package/docs/webapi/click.mustache +0 -29
- package/docs/webapi/clickLink.mustache +0 -8
- package/docs/webapi/closeCurrentTab.mustache +0 -7
- package/docs/webapi/closeOtherTabs.mustache +0 -8
- package/docs/webapi/dontSee.mustache +0 -11
- package/docs/webapi/dontSeeCheckboxIsChecked.mustache +0 -10
- package/docs/webapi/dontSeeCookie.mustache +0 -8
- package/docs/webapi/dontSeeCurrentUrlEquals.mustache +0 -10
- package/docs/webapi/dontSeeElement.mustache +0 -8
- package/docs/webapi/dontSeeElementInDOM.mustache +0 -8
- package/docs/webapi/dontSeeInCurrentUrl.mustache +0 -4
- package/docs/webapi/dontSeeInField.mustache +0 -11
- package/docs/webapi/dontSeeInSource.mustache +0 -8
- package/docs/webapi/dontSeeInTitle.mustache +0 -8
- package/docs/webapi/dontSeeTraffic.mustache +0 -13
- package/docs/webapi/doubleClick.mustache +0 -13
- package/docs/webapi/downloadFile.mustache +0 -12
- package/docs/webapi/dragAndDrop.mustache +0 -9
- package/docs/webapi/dragSlider.mustache +0 -11
- package/docs/webapi/executeAsyncScript.mustache +0 -24
- package/docs/webapi/executeScript.mustache +0 -26
- package/docs/webapi/fillField.mustache +0 -16
- package/docs/webapi/flushNetworkTraffics.mustache +0 -5
- package/docs/webapi/focus.mustache +0 -13
- package/docs/webapi/forceClick.mustache +0 -28
- package/docs/webapi/forceRightClick.mustache +0 -18
- package/docs/webapi/grabAllWindowHandles.mustache +0 -7
- package/docs/webapi/grabAttributeFrom.mustache +0 -10
- package/docs/webapi/grabAttributeFromAll.mustache +0 -9
- package/docs/webapi/grabBrowserLogs.mustache +0 -9
- package/docs/webapi/grabCookie.mustache +0 -11
- package/docs/webapi/grabCssPropertyFrom.mustache +0 -11
- package/docs/webapi/grabCssPropertyFromAll.mustache +0 -10
- package/docs/webapi/grabCurrentUrl.mustache +0 -9
- package/docs/webapi/grabCurrentWindowHandle.mustache +0 -6
- package/docs/webapi/grabDataFromPerformanceTiming.mustache +0 -20
- package/docs/webapi/grabElementBoundingRect.mustache +0 -20
- package/docs/webapi/grabGeoLocation.mustache +0 -8
- package/docs/webapi/grabHTMLFrom.mustache +0 -10
- package/docs/webapi/grabHTMLFromAll.mustache +0 -9
- package/docs/webapi/grabNumberOfOpenTabs.mustache +0 -8
- package/docs/webapi/grabNumberOfVisibleElements.mustache +0 -9
- package/docs/webapi/grabPageScrollPosition.mustache +0 -8
- package/docs/webapi/grabPopupText.mustache +0 -5
- package/docs/webapi/grabRecordedNetworkTraffics.mustache +0 -10
- package/docs/webapi/grabSource.mustache +0 -8
- package/docs/webapi/grabTextFrom.mustache +0 -10
- package/docs/webapi/grabTextFromAll.mustache +0 -9
- package/docs/webapi/grabTitle.mustache +0 -8
- package/docs/webapi/grabValueFrom.mustache +0 -9
- package/docs/webapi/grabValueFromAll.mustache +0 -8
- package/docs/webapi/grabWebElement.mustache +0 -9
- package/docs/webapi/grabWebElements.mustache +0 -9
- package/docs/webapi/moveCursorTo.mustache +0 -12
- package/docs/webapi/openNewTab.mustache +0 -7
- package/docs/webapi/pressKey.mustache +0 -12
- package/docs/webapi/pressKeyDown.mustache +0 -12
- package/docs/webapi/pressKeyUp.mustache +0 -12
- package/docs/webapi/pressKeyWithKeyNormalization.mustache +0 -60
- package/docs/webapi/refreshPage.mustache +0 -6
- package/docs/webapi/resizeWindow.mustache +0 -6
- package/docs/webapi/rightClick.mustache +0 -14
- package/docs/webapi/saveElementScreenshot.mustache +0 -10
- package/docs/webapi/saveScreenshot.mustache +0 -12
- package/docs/webapi/say.mustache +0 -10
- package/docs/webapi/scrollIntoView.mustache +0 -11
- package/docs/webapi/scrollPageToBottom.mustache +0 -6
- package/docs/webapi/scrollPageToTop.mustache +0 -6
- package/docs/webapi/scrollTo.mustache +0 -12
- package/docs/webapi/see.mustache +0 -11
- package/docs/webapi/seeAttributesOnElements.mustache +0 -9
- package/docs/webapi/seeCheckboxIsChecked.mustache +0 -10
- package/docs/webapi/seeCookie.mustache +0 -8
- package/docs/webapi/seeCssPropertiesOnElements.mustache +0 -9
- package/docs/webapi/seeCurrentUrlEquals.mustache +0 -11
- package/docs/webapi/seeElement.mustache +0 -8
- package/docs/webapi/seeElementInDOM.mustache +0 -8
- package/docs/webapi/seeInCurrentUrl.mustache +0 -8
- package/docs/webapi/seeInField.mustache +0 -12
- package/docs/webapi/seeInPopup.mustache +0 -8
- package/docs/webapi/seeInSource.mustache +0 -7
- package/docs/webapi/seeInTitle.mustache +0 -8
- package/docs/webapi/seeNumberOfElements.mustache +0 -11
- package/docs/webapi/seeNumberOfVisibleElements.mustache +0 -10
- package/docs/webapi/seeTextEquals.mustache +0 -9
- package/docs/webapi/seeTitleEquals.mustache +0 -8
- package/docs/webapi/seeTraffic.mustache +0 -36
- package/docs/webapi/selectOption.mustache +0 -21
- package/docs/webapi/setCookie.mustache +0 -16
- package/docs/webapi/setGeoLocation.mustache +0 -12
- package/docs/webapi/startRecordingTraffic.mustache +0 -8
- package/docs/webapi/startRecordingWebSocketMessages.mustache +0 -8
- package/docs/webapi/stopRecordingTraffic.mustache +0 -5
- package/docs/webapi/stopRecordingWebSocketMessages.mustache +0 -7
- package/docs/webapi/switchTo.mustache +0 -9
- package/docs/webapi/switchToNextTab.mustache +0 -10
- package/docs/webapi/switchToPreviousTab.mustache +0 -10
- package/docs/webapi/type.mustache +0 -21
- package/docs/webapi/uncheckOption.mustache +0 -13
- package/docs/webapi/wait.mustache +0 -8
- package/docs/webapi/waitForClickable.mustache +0 -11
- package/docs/webapi/waitForCookie.mustache +0 -9
- package/docs/webapi/waitForDetached.mustache +0 -10
- package/docs/webapi/waitForDisabled.mustache +0 -6
- package/docs/webapi/waitForElement.mustache +0 -11
- package/docs/webapi/waitForEnabled.mustache +0 -6
- package/docs/webapi/waitForFunction.mustache +0 -17
- package/docs/webapi/waitForInvisible.mustache +0 -10
- package/docs/webapi/waitForNumberOfTabs.mustache +0 -9
- package/docs/webapi/waitForText.mustache +0 -13
- package/docs/webapi/waitForValue.mustache +0 -10
- package/docs/webapi/waitForVisible.mustache +0 -10
- package/docs/webapi/waitInUrl.mustache +0 -9
- package/docs/webapi/waitNumberOfVisibleElements.mustache +0 -10
- package/docs/webapi/waitToHide.mustache +0 -10
- package/docs/webapi/waitUrlEquals.mustache +0 -10
- package/lib/helper/AI.js +0 -214
- package/lib/helper/Mochawesome.js +0 -96
- package/lib/helper/extras/PlaywrightReactVueLocator.js +0 -52
- package/lib/helper/extras/React.js +0 -65
- package/lib/listener/enhancedGlobalRetry.js +0 -110
- package/lib/plugin/enhancedRetryFailedStep.js +0 -99
- package/lib/plugin/htmlReporter.js +0 -3648
- package/lib/plugin/stepByStepReport.js +0 -427
- package/lib/plugin/subtitles.js +0 -89
- 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.
|