codeceptjs 3.5.12-beta.3 → 3.5.12-beta.5
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/docs/advanced.md +351 -0
- package/docs/ai.md +248 -0
- package/docs/api.md +323 -0
- package/docs/basics.md +979 -0
- package/docs/bdd.md +539 -0
- package/docs/best.md +237 -0
- package/docs/books.md +37 -0
- package/docs/bootstrap.md +135 -0
- package/docs/build/ApiDataFactory.js +410 -0
- package/docs/build/Appium.js +2027 -0
- package/docs/build/Expect.js +422 -0
- package/docs/build/FileSystem.js +228 -0
- package/docs/build/GraphQL.js +229 -0
- package/docs/build/GraphQLDataFactory.js +309 -0
- package/docs/build/JSONResponse.js +338 -0
- package/docs/build/Mochawesome.js +71 -0
- package/docs/build/Nightmare.js +2152 -0
- package/docs/build/OpenAI.js +126 -0
- package/docs/build/Playwright.js +5110 -0
- package/docs/build/Protractor.js +2706 -0
- package/docs/build/Puppeteer.js +3905 -0
- package/docs/build/REST.js +344 -0
- package/docs/build/TestCafe.js +2125 -0
- package/docs/build/WebDriver.js +4240 -0
- package/docs/changelog.md +2572 -0
- package/docs/commands.md +266 -0
- package/docs/community-helpers.md +58 -0
- package/docs/configuration.md +157 -0
- package/docs/continuous-integration.md +22 -0
- package/docs/custom-helpers.md +306 -0
- package/docs/data.md +379 -0
- package/docs/detox.md +235 -0
- package/docs/docker.md +136 -0
- package/docs/email.md +183 -0
- package/docs/examples.md +149 -0
- package/docs/helpers/ApiDataFactory.md +266 -0
- package/docs/helpers/Appium.md +1374 -0
- package/docs/helpers/Detox.md +586 -0
- package/docs/helpers/Expect.md +275 -0
- package/docs/helpers/FileSystem.md +152 -0
- package/docs/helpers/GraphQL.md +151 -0
- package/docs/helpers/GraphQLDataFactory.md +226 -0
- package/docs/helpers/JSONResponse.md +254 -0
- package/docs/helpers/Mochawesome.md +8 -0
- package/docs/helpers/MockRequest.md +377 -0
- package/docs/helpers/Nightmare.md +1305 -0
- package/docs/helpers/OpenAI.md +70 -0
- package/docs/helpers/Playwright.md +2759 -0
- package/docs/helpers/Polly.md +44 -0
- package/docs/helpers/Protractor.md +1769 -0
- package/docs/helpers/Puppeteer-firefox.md +86 -0
- package/docs/helpers/Puppeteer.md +2317 -0
- package/docs/helpers/REST.md +218 -0
- package/docs/helpers/TestCafe.md +1321 -0
- package/docs/helpers/WebDriver.md +2547 -0
- package/docs/hooks.md +340 -0
- package/docs/index.md +111 -0
- package/docs/installation.md +75 -0
- package/docs/internal-api.md +266 -0
- package/docs/locators.md +339 -0
- package/docs/mobile-react-native-locators.md +67 -0
- package/docs/mobile.md +338 -0
- package/docs/pageobjects.md +291 -0
- package/docs/parallel.md +400 -0
- package/docs/playwright.md +632 -0
- package/docs/plugins.md +1259 -0
- package/docs/puppeteer.md +316 -0
- package/docs/quickstart.md +162 -0
- package/docs/react.md +70 -0
- package/docs/reports.md +392 -0
- package/docs/secrets.md +36 -0
- package/docs/shadow.md +68 -0
- package/docs/shared/keys.mustache +31 -0
- package/docs/shared/react.mustache +1 -0
- package/docs/testcafe.md +174 -0
- package/docs/translation.md +247 -0
- package/docs/tutorial.md +271 -0
- package/docs/typescript.md +180 -0
- package/docs/ui.md +59 -0
- package/docs/videos.md +28 -0
- package/docs/visual.md +202 -0
- package/docs/vue.md +143 -0
- package/docs/webapi/amOnPage.mustache +11 -0
- package/docs/webapi/appendField.mustache +11 -0
- package/docs/webapi/attachFile.mustache +12 -0
- package/docs/webapi/blur.mustache +18 -0
- package/docs/webapi/checkOption.mustache +13 -0
- package/docs/webapi/clearCookie.mustache +9 -0
- package/docs/webapi/clearField.mustache +9 -0
- package/docs/webapi/click.mustache +25 -0
- package/docs/webapi/clickLink.mustache +8 -0
- package/docs/webapi/closeCurrentTab.mustache +7 -0
- package/docs/webapi/closeOtherTabs.mustache +8 -0
- package/docs/webapi/dontSee.mustache +11 -0
- package/docs/webapi/dontSeeCheckboxIsChecked.mustache +10 -0
- package/docs/webapi/dontSeeCookie.mustache +8 -0
- package/docs/webapi/dontSeeCurrentUrlEquals.mustache +10 -0
- package/docs/webapi/dontSeeElement.mustache +8 -0
- package/docs/webapi/dontSeeElementInDOM.mustache +8 -0
- package/docs/webapi/dontSeeInCurrentUrl.mustache +4 -0
- package/docs/webapi/dontSeeInField.mustache +11 -0
- package/docs/webapi/dontSeeInSource.mustache +8 -0
- package/docs/webapi/dontSeeInTitle.mustache +8 -0
- package/docs/webapi/doubleClick.mustache +13 -0
- package/docs/webapi/downloadFile.mustache +12 -0
- package/docs/webapi/dragAndDrop.mustache +9 -0
- package/docs/webapi/dragSlider.mustache +11 -0
- package/docs/webapi/executeAsyncScript.mustache +24 -0
- package/docs/webapi/executeScript.mustache +26 -0
- package/docs/webapi/fillField.mustache +16 -0
- package/docs/webapi/focus.mustache +13 -0
- package/docs/webapi/forceClick.mustache +28 -0
- package/docs/webapi/forceRightClick.mustache +18 -0
- package/docs/webapi/grabAllWindowHandles.mustache +7 -0
- package/docs/webapi/grabAttributeFrom.mustache +10 -0
- package/docs/webapi/grabAttributeFromAll.mustache +9 -0
- package/docs/webapi/grabBrowserLogs.mustache +9 -0
- package/docs/webapi/grabCookie.mustache +11 -0
- package/docs/webapi/grabCssPropertyFrom.mustache +11 -0
- package/docs/webapi/grabCssPropertyFromAll.mustache +10 -0
- package/docs/webapi/grabCurrentUrl.mustache +9 -0
- package/docs/webapi/grabCurrentWindowHandle.mustache +6 -0
- package/docs/webapi/grabDataFromPerformanceTiming.mustache +20 -0
- package/docs/webapi/grabElementBoundingRect.mustache +20 -0
- package/docs/webapi/grabGeoLocation.mustache +8 -0
- package/docs/webapi/grabHTMLFrom.mustache +10 -0
- package/docs/webapi/grabHTMLFromAll.mustache +9 -0
- package/docs/webapi/grabNumberOfOpenTabs.mustache +8 -0
- package/docs/webapi/grabNumberOfVisibleElements.mustache +9 -0
- package/docs/webapi/grabPageScrollPosition.mustache +8 -0
- package/docs/webapi/grabPopupText.mustache +5 -0
- package/docs/webapi/grabSource.mustache +8 -0
- package/docs/webapi/grabTextFrom.mustache +10 -0
- package/docs/webapi/grabTextFromAll.mustache +9 -0
- package/docs/webapi/grabTitle.mustache +8 -0
- package/docs/webapi/grabValueFrom.mustache +9 -0
- package/docs/webapi/grabValueFromAll.mustache +8 -0
- package/docs/webapi/grabWebElement.mustache +9 -0
- package/docs/webapi/grabWebElements.mustache +9 -0
- package/docs/webapi/moveCursorTo.mustache +12 -0
- package/docs/webapi/openNewTab.mustache +7 -0
- package/docs/webapi/pressKey.mustache +12 -0
- package/docs/webapi/pressKeyDown.mustache +12 -0
- package/docs/webapi/pressKeyUp.mustache +12 -0
- package/docs/webapi/pressKeyWithKeyNormalization.mustache +60 -0
- package/docs/webapi/refreshPage.mustache +6 -0
- package/docs/webapi/resizeWindow.mustache +6 -0
- package/docs/webapi/rightClick.mustache +14 -0
- package/docs/webapi/saveElementScreenshot.mustache +10 -0
- package/docs/webapi/saveScreenshot.mustache +12 -0
- package/docs/webapi/say.mustache +10 -0
- package/docs/webapi/scrollIntoView.mustache +11 -0
- package/docs/webapi/scrollPageToBottom.mustache +6 -0
- package/docs/webapi/scrollPageToTop.mustache +6 -0
- package/docs/webapi/scrollTo.mustache +12 -0
- package/docs/webapi/see.mustache +11 -0
- package/docs/webapi/seeAttributesOnElements.mustache +9 -0
- package/docs/webapi/seeCheckboxIsChecked.mustache +10 -0
- package/docs/webapi/seeCookie.mustache +8 -0
- package/docs/webapi/seeCssPropertiesOnElements.mustache +9 -0
- package/docs/webapi/seeCurrentUrlEquals.mustache +11 -0
- package/docs/webapi/seeElement.mustache +8 -0
- package/docs/webapi/seeElementInDOM.mustache +8 -0
- package/docs/webapi/seeInCurrentUrl.mustache +8 -0
- package/docs/webapi/seeInField.mustache +12 -0
- package/docs/webapi/seeInPopup.mustache +8 -0
- package/docs/webapi/seeInSource.mustache +7 -0
- package/docs/webapi/seeInTitle.mustache +8 -0
- package/docs/webapi/seeNumberOfElements.mustache +11 -0
- package/docs/webapi/seeNumberOfVisibleElements.mustache +10 -0
- package/docs/webapi/seeTextEquals.mustache +9 -0
- package/docs/webapi/seeTitleEquals.mustache +8 -0
- package/docs/webapi/selectOption.mustache +21 -0
- package/docs/webapi/setCookie.mustache +16 -0
- package/docs/webapi/setGeoLocation.mustache +12 -0
- package/docs/webapi/switchTo.mustache +9 -0
- package/docs/webapi/switchToNextTab.mustache +10 -0
- package/docs/webapi/switchToPreviousTab.mustache +10 -0
- package/docs/webapi/type.mustache +21 -0
- package/docs/webapi/uncheckOption.mustache +13 -0
- package/docs/webapi/wait.mustache +8 -0
- package/docs/webapi/waitForClickable.mustache +11 -0
- package/docs/webapi/waitForDetached.mustache +10 -0
- package/docs/webapi/waitForElement.mustache +11 -0
- package/docs/webapi/waitForEnabled.mustache +6 -0
- package/docs/webapi/waitForFunction.mustache +17 -0
- package/docs/webapi/waitForInvisible.mustache +10 -0
- package/docs/webapi/waitForNumberOfTabs.mustache +9 -0
- package/docs/webapi/waitForText.mustache +13 -0
- package/docs/webapi/waitForValue.mustache +10 -0
- package/docs/webapi/waitForVisible.mustache +10 -0
- package/docs/webapi/waitInUrl.mustache +9 -0
- package/docs/webapi/waitNumberOfVisibleElements.mustache +10 -0
- package/docs/webapi/waitToHide.mustache +10 -0
- package/docs/webapi/waitUrlEquals.mustache +10 -0
- package/docs/webdriver.md +701 -0
- package/docs/wiki/Books-&-Posts.md +27 -0
- package/docs/wiki/Community-Helpers-&-Plugins.md +53 -0
- package/docs/wiki/Converting-Playwright-to-Istanbul-Coverage.md +61 -0
- package/docs/wiki/Examples.md +145 -0
- package/docs/wiki/Google-Summer-of-Code-(GSoC)-2020.md +68 -0
- package/docs/wiki/Home.md +16 -0
- package/docs/wiki/Migration-to-Appium-v2---CodeceptJS.md +83 -0
- package/docs/wiki/Release-Process.md +24 -0
- package/docs/wiki/Roadmap.md +23 -0
- package/docs/wiki/Tests.md +1393 -0
- package/docs/wiki/Upgrading-to-CodeceptJS-3.md +153 -0
- package/docs/wiki/Videos.md +19 -0
- package/package.json +2 -1
package/docs/hooks.md
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
---
|
|
2
|
+
permalink: /hooks
|
|
3
|
+
title: Extending CodeceptJS
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Extending
|
|
7
|
+
|
|
8
|
+
CodeceptJS provides API to run custom code before and after the test and inject custom listeners into the event system.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## Plugins
|
|
12
|
+
|
|
13
|
+
Plugins allow to use CodeceptJS internal API to extend functionality. Use internal event dispatcher, container, output, promise recorder, to create your own reporters, test listeners, etc.
|
|
14
|
+
|
|
15
|
+
CodeceptJS includes [built-in plugins](/plugins/) which extend basic functionality and can be turned on and off on purpose. Taking them as [examples](https://github.com/codeceptjs/CodeceptJS/tree/master/lib/plugin) you can develop your custom plugins.
|
|
16
|
+
|
|
17
|
+
A plugin is a basic JS module returning a function. Plugins can have individual configs which are passed into this function:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
const defaultConfig = {
|
|
21
|
+
someDefaultOption: true
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = function(config) {
|
|
25
|
+
config = Object.assign(defaultConfig, config);
|
|
26
|
+
// do stuff
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Plugin can register event listeners or hook into promise chain with recorder. See [API reference](https://github.com/codeceptjs/CodeceptJS/tree/master/lib/helper).
|
|
31
|
+
|
|
32
|
+
To enable your custom plugin in config add it to `plugins` section. Specify path to node module using `require`.
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
"plugins": {
|
|
36
|
+
"myPlugin": {
|
|
37
|
+
"require": "./path/to/my/module",
|
|
38
|
+
"enabled": true
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
* `require` - specifies relative path to a plugin file. Path is relative to config file.
|
|
44
|
+
* `enabled` - to enable this plugin.
|
|
45
|
+
|
|
46
|
+
If a plugin is disabled (`enabled` is not set or false) this plugin can be enabled from command line:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
npx codeceptjs run --plugin myPlugin
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Several plugins can be enabled as well:
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
npx codeceptjs run --plugin myPlugin,allure
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Example: Execute code for a specific group of tests
|
|
59
|
+
|
|
60
|
+
If you need to execute some code before a group of tests, you can [mark these tests with a same tag](/advanced/#tags). Then to listen for tests where this tag is included (see [test object api](#test-object)).
|
|
61
|
+
|
|
62
|
+
Let's say we need to populate database for a group of tests.
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
// populate database for slow tests
|
|
66
|
+
const event = require('codeceptjs').event;
|
|
67
|
+
|
|
68
|
+
module.exports = function() {
|
|
69
|
+
|
|
70
|
+
event.dispatcher.on(event.test.before, function (test) {
|
|
71
|
+
|
|
72
|
+
if (test.tags.indexOf('@populate') >= 0) {
|
|
73
|
+
recorder.add('populate database', async () => {
|
|
74
|
+
// populate database for this test
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Example: Check URL before running a test
|
|
82
|
+
|
|
83
|
+
If you want to share bootstrap script or run multiple bootstraps, it's a good idea to wrap that script into a plugin.
|
|
84
|
+
Plugin can also execute JS before tests but you need to use internal APIs to synchronize promises.
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
const { recorder } = require('codeceptjs');
|
|
88
|
+
|
|
89
|
+
module.exports = function(options) {
|
|
90
|
+
|
|
91
|
+
event.dispatcher.on(event.all.before, function () {
|
|
92
|
+
recorder.startUnlessRunning(); // start recording promises
|
|
93
|
+
recorder.add('do some async stuff', async () => {
|
|
94
|
+
// your code
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## API
|
|
101
|
+
|
|
102
|
+
**Use local CodeceptJS installation to get access to `codeceptjs` module**
|
|
103
|
+
|
|
104
|
+
CodeceptJS provides an API which can be loaded via `require('codeceptjs')` when CodeceptJS is installed locally.
|
|
105
|
+
These internal objects are available:
|
|
106
|
+
|
|
107
|
+
* [`codecept`](https://github.com/codeceptjs/CodeceptJS/blob/master/lib/codecept.js): test runner class
|
|
108
|
+
* [`config`](https://github.com/codeceptjs/CodeceptJS/blob/master/lib/config.js): current codecept config
|
|
109
|
+
* [`event`](https://github.com/codeceptjs/CodeceptJS/blob/master/lib/event.js): event listener
|
|
110
|
+
* [`recorder`](https://github.com/codeceptjs/CodeceptJS/blob/master/lib/recorder.js): global promise chain
|
|
111
|
+
* [`output`](https://github.com/codeceptjs/CodeceptJS/blob/master/lib/output.js): internal printer
|
|
112
|
+
* [`container`](https://github.com/codeceptjs/CodeceptJS/blob/master/lib/container.js): dependency injection container for tests, includes current helpers and support objects
|
|
113
|
+
* [`helper`](https://github.com/codeceptjs/CodeceptJS/blob/master/lib/helper.js): basic helper class
|
|
114
|
+
* [`actor`](https://github.com/codeceptjs/CodeceptJS/blob/master/lib/actor.js): basic actor (I) class
|
|
115
|
+
|
|
116
|
+
[API reference](https://github.com/codeceptjs/CodeceptJS/tree/master/docs/api) is available on GitHub.
|
|
117
|
+
Also please check the source code of corresponding modules.
|
|
118
|
+
|
|
119
|
+
### Event Listeners
|
|
120
|
+
|
|
121
|
+
CodeceptJS provides a module with [event dispatcher and set of predefined events](https://github.com/codeceptjs/CodeceptJS/blob/master/lib/event.js).
|
|
122
|
+
|
|
123
|
+
It can be required from codeceptjs package if it is installed locally.
|
|
124
|
+
|
|
125
|
+
```js
|
|
126
|
+
const event = require('codeceptjs').event;
|
|
127
|
+
|
|
128
|
+
module.exports = function() {
|
|
129
|
+
|
|
130
|
+
event.dispatcher.on(event.test.before, function (test) {
|
|
131
|
+
|
|
132
|
+
console.log('--- I am before test --');
|
|
133
|
+
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Available events:
|
|
139
|
+
|
|
140
|
+
* `event.test.before(test)` - *async* when `Before` hooks from helpers and from test is executed
|
|
141
|
+
* `event.test.after(test)` - *async* after each test
|
|
142
|
+
* `event.test.started(test)` - *sync* at the very beginning of a test. Passes a current test object.
|
|
143
|
+
* `event.test.passed(test)` - *sync* when test passed
|
|
144
|
+
* `event.test.failed(test, error)` - *sync* when test failed
|
|
145
|
+
* `event.test.finished(test)` - *sync* when test finished
|
|
146
|
+
* `event.suite.before(suite)` - *async* before a suite
|
|
147
|
+
* `event.suite.after(suite)` - *async* after a suite
|
|
148
|
+
* `event.step.before(step)` - *async* when the step is scheduled for execution
|
|
149
|
+
* `event.step.after(step)` - *async* after a step
|
|
150
|
+
* `event.step.started(step)` - *sync* when step starts.
|
|
151
|
+
* `event.step.passed(step)` - *sync* when step passed.
|
|
152
|
+
* `event.step.failed(step, err)` - *sync* when step failed.
|
|
153
|
+
* `event.step.finished(step)` - *sync* when step finishes.
|
|
154
|
+
* `event.step.comment(step)` - *sync* fired for comments like `I.say`.
|
|
155
|
+
* `event.bddStep.before(bddStep)` - *async* when the gherkin step is scheduled for execution
|
|
156
|
+
* `event.bddStep.after(bddStep)` - *async* after a gherkin step
|
|
157
|
+
* `event.all.before` - before running tests
|
|
158
|
+
* `event.all.after` - after running tests
|
|
159
|
+
* `event.all.result` - when results are printed
|
|
160
|
+
|
|
161
|
+
* *sync* - means that event is fired in the moment of action happens.
|
|
162
|
+
* *async* - means that event is fired when an actions is scheduled. Use `recorder` to schedule your actions.
|
|
163
|
+
|
|
164
|
+
For further reference look for [currently available listeners](https://github.com/codeceptjs/CodeceptJS/tree/master/lib/listener) using event system.
|
|
165
|
+
|
|
166
|
+
#### Test Object
|
|
167
|
+
|
|
168
|
+
Test events provide a test object with following fields:
|
|
169
|
+
|
|
170
|
+
* `title` title of a test
|
|
171
|
+
* `body` test function as a string
|
|
172
|
+
* `opts` additional test options like retries, and others
|
|
173
|
+
* `pending` true if test is scheduled for execution and false if a test has finished
|
|
174
|
+
* `tags` array of tags for this test
|
|
175
|
+
* `file` path to a file with a test.
|
|
176
|
+
* `steps` array of executed steps (available only in `test.passed`, `test.failed`, `test.finished` event)
|
|
177
|
+
* `skipInfo` additional test options when test skipped
|
|
178
|
+
* * `message` string with reason for skip
|
|
179
|
+
* * `description` string with test body
|
|
180
|
+
and others
|
|
181
|
+
|
|
182
|
+
#### Step Object
|
|
183
|
+
|
|
184
|
+
Step events provide step objects with following fields:
|
|
185
|
+
|
|
186
|
+
* `name` name of a step, like 'see', 'click', and others
|
|
187
|
+
* `actor` current actor, in most cases it `I`
|
|
188
|
+
* `helper` current helper instance used to execute this step
|
|
189
|
+
* `helperMethod` corresponding helper method, in most cases is the same as `name`
|
|
190
|
+
* `status` status of a step (passed or failed)
|
|
191
|
+
* `prefix` if a step is executed inside `within` block contain within text, like: 'Within .js-signup-form'.
|
|
192
|
+
* `args` passed arguments
|
|
193
|
+
|
|
194
|
+
### Recorder
|
|
195
|
+
|
|
196
|
+
To inject asynchronous functions in a test or before/after a test you can subscribe to corresponding event and register a function inside a recorder object. [Recorder](https://github.com/codeceptjs/CodeceptJS/blob/master/lib/recorder.js) represents a global promises chain.
|
|
197
|
+
|
|
198
|
+
Provide a function description as a first parameter, function should return a promise:
|
|
199
|
+
|
|
200
|
+
```js
|
|
201
|
+
const event = require('codeceptjs').event;
|
|
202
|
+
const recorder = require('codeceptjs').recorder;
|
|
203
|
+
module.exports = function() {
|
|
204
|
+
|
|
205
|
+
event.dispatcher.on(event.test.before, function (test) {
|
|
206
|
+
|
|
207
|
+
const request = require('request');
|
|
208
|
+
|
|
209
|
+
recorder.add('create fixture data via API', function() {
|
|
210
|
+
return new Promise((doneFn, errFn) => {
|
|
211
|
+
request({
|
|
212
|
+
baseUrl: 'http://api.site.com/',
|
|
213
|
+
method: 'POST',
|
|
214
|
+
url: '/users',
|
|
215
|
+
json: { name: 'john', email: 'john@john.com' }
|
|
216
|
+
}), (err, httpResponse, body) => {
|
|
217
|
+
if (err) return errFn(err);
|
|
218
|
+
doneFn();
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Whenever you execute tests with `--verbose` option you will see registered events and promises executed by a recorder.
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
### Output
|
|
231
|
+
|
|
232
|
+
Output module provides 4 verbosity levels. Depending on the mode you can have different information printed using corresponding functions.
|
|
233
|
+
|
|
234
|
+
* `default`: prints basic information using `output.print`
|
|
235
|
+
* `steps`: toggled by `--steps` option, prints step execution
|
|
236
|
+
* `debug`: toggled by `--debug` option, prints steps, and debug information with `output.debug`
|
|
237
|
+
* `verbose`: toggled by `--verbose` prints debug information and internal logs with `output.log`
|
|
238
|
+
|
|
239
|
+
It is recommended to avoid `console.log` and use output.* methods for printing.
|
|
240
|
+
|
|
241
|
+
```js
|
|
242
|
+
const output = require('codeceptjs').output;
|
|
243
|
+
|
|
244
|
+
output.print('This is basic information');
|
|
245
|
+
output.debug('This is debug information');
|
|
246
|
+
output.log('This is verbose logging information');
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Container
|
|
250
|
+
|
|
251
|
+
CodeceptJS has a dependency injection container with Helpers and Support objects.
|
|
252
|
+
They can be retrieved from the container:
|
|
253
|
+
|
|
254
|
+
```js
|
|
255
|
+
let container = require('codeceptjs').container;
|
|
256
|
+
|
|
257
|
+
// get object with all helpers
|
|
258
|
+
let helpers = container.helpers();
|
|
259
|
+
|
|
260
|
+
// get helper by name
|
|
261
|
+
let WebDriver = container.helpers('WebDriver');
|
|
262
|
+
|
|
263
|
+
// get support objects
|
|
264
|
+
let support = container.support();
|
|
265
|
+
|
|
266
|
+
// get support object by name
|
|
267
|
+
let UserPage = container.support('UserPage');
|
|
268
|
+
|
|
269
|
+
// get all registered plugins
|
|
270
|
+
let plugins = container.plugins();
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
New objects can also be added to container in runtime:
|
|
274
|
+
|
|
275
|
+
```js
|
|
276
|
+
let container = require('codeceptjs').container;
|
|
277
|
+
|
|
278
|
+
container.append({
|
|
279
|
+
helpers: { // add helper
|
|
280
|
+
MyHelper: new MyHelper({ config1: 'val1' });
|
|
281
|
+
},
|
|
282
|
+
support: { // add page object
|
|
283
|
+
UserPage: require('./pages/user');
|
|
284
|
+
}
|
|
285
|
+
})
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
Container also contains current Mocha instance:
|
|
289
|
+
|
|
290
|
+
```js
|
|
291
|
+
let mocha = container.mocha();
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Config
|
|
295
|
+
|
|
296
|
+
CodeceptJS config can be accessed from `require('codeceptjs').config.get()`:
|
|
297
|
+
|
|
298
|
+
```js
|
|
299
|
+
|
|
300
|
+
let config = require('codeceptjs').config.get();
|
|
301
|
+
|
|
302
|
+
if (config.myKey == 'value') {
|
|
303
|
+
// run hook
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
## Custom Runner
|
|
309
|
+
|
|
310
|
+
> 📺 [Watch this](https://www.youtube.com/watch?v=3eZtVL0Ad0A) material on YouTube
|
|
311
|
+
|
|
312
|
+
CodeceptJS can be imported and used in custom runners.
|
|
313
|
+
To initialize Codecept you need to create Config and Container objects.
|
|
314
|
+
|
|
315
|
+
```js
|
|
316
|
+
const { codecept: Codecept } = require('codeceptjs');
|
|
317
|
+
|
|
318
|
+
const config = { helpers: { WebDriver: { browser: 'chrome', url: 'http://localhost' } } };
|
|
319
|
+
const opts = { steps: true };
|
|
320
|
+
|
|
321
|
+
const codecept = new Codecept(config, options);
|
|
322
|
+
codecept.init(testRoot);
|
|
323
|
+
|
|
324
|
+
// run tests
|
|
325
|
+
try {
|
|
326
|
+
await codecept.bootstrap();
|
|
327
|
+
codecept.loadTests('*_test.js');
|
|
328
|
+
await codecept.run(test);
|
|
329
|
+
} catch (err) {
|
|
330
|
+
printError(err);
|
|
331
|
+
process.exitCode = 1;
|
|
332
|
+
} finally {
|
|
333
|
+
await codecept.teardown();
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
In this way Codecept runner class can be extended.
|
|
340
|
+
|
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, TestCafe
|
|
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
|
+
const { faker } = require('@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.retry(2).click('Create'); // 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,75 @@
|
|
|
1
|
+
---
|
|
2
|
+
permalink: /installation
|
|
3
|
+
title: Installation
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Installation
|
|
7
|
+
|
|
8
|
+
## QuickStart Via Installer
|
|
9
|
+
|
|
10
|
+
Creating a new project via [`create-codeceptjs` installer](https://github.com/codeceptjs/create-codeceptjs) is the simplest way to start
|
|
11
|
+
|
|
12
|
+
Install CodeceptJS + Playwright into current directory
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
npx create-codeceptjs .
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Install CodeceptJS + Puppeteer into current directory
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
npx create-codeceptjs . --puppeteer
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Install CodeceptJS + webdriverio into current directory
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
npx create-codeceptjs . --webdriverio
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Install CodeceptJS + webdriverio into `e2e-tests` directory:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
npx create-codeceptjs e2e-tests --webdriverio
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
If you plan to use CodeceptJS for **API testing** only proceed to standard installation
|
|
37
|
+
|
|
38
|
+
## Standard Installation
|
|
39
|
+
|
|
40
|
+
Open a directory where you want to install CodeceptJS tests.
|
|
41
|
+
If it is an empty directory - create a new NPM package with
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
npm init -y
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Install CodeceptJS with NPM:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
npx codeceptjs init
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
After choosing default helper (Playwright, Puppeteer, WebDriver, etc) a corresponding package should be installed automatically.
|
|
54
|
+
|
|
55
|
+
> If you face issues installing additional packages while running `npx codeceptjs init` command, install required packages manually using npm
|
|
56
|
+
|
|
57
|
+
Unless you are using WebDriver - CodeceptJS is ready to go!
|
|
58
|
+
For WebDriver installation Selenium Server is required 👇
|
|
59
|
+
|
|
60
|
+
## WebDriver
|
|
61
|
+
|
|
62
|
+
WebDriver based helpers like WebDriver will require [Selenium Server](https://codecept.io/helpers/WebDriver/#selenium-installation) installed. They will also require ChromeDriver or GeckoDriver to run corresponding browsers.
|
|
63
|
+
|
|
64
|
+
We recommend to install them manually or use NPM packages:
|
|
65
|
+
|
|
66
|
+
[Selenium Standalone](https://www.npmjs.com/package/selenium-standalone) to install and run Selenium, ChromeDriver, Firefox Driver with one package.
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
Alternatively, you can execute headless Selenium in [Docker](https://github.com/SeleniumHQ/docker-selenium) for headless browser testing.
|
|
70
|
+
|
|
71
|
+
Launch Selenium with Chrome browser inside a Docker container:
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
docker run --net=host selenium/standalone-chrome
|
|
75
|
+
```
|