codeceptjs 3.5.12-beta.2 → 3.5.12-beta.3
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/lib/locator.js +7 -12
- package/package.json +3 -5
- package/docs/advanced.md +0 -351
- package/docs/ai.md +0 -248
- package/docs/api.md +0 -323
- package/docs/basics.md +0 -979
- package/docs/bdd.md +0 -539
- package/docs/best.md +0 -237
- package/docs/books.md +0 -37
- package/docs/bootstrap.md +0 -135
- package/docs/build/ApiDataFactory.js +0 -410
- package/docs/build/Appium.js +0 -2027
- package/docs/build/Expect.js +0 -422
- package/docs/build/FileSystem.js +0 -228
- package/docs/build/GraphQL.js +0 -229
- package/docs/build/GraphQLDataFactory.js +0 -309
- package/docs/build/JSONResponse.js +0 -338
- package/docs/build/Mochawesome.js +0 -71
- package/docs/build/Nightmare.js +0 -2152
- package/docs/build/OpenAI.js +0 -126
- package/docs/build/Playwright.js +0 -5110
- package/docs/build/Protractor.js +0 -2706
- package/docs/build/Puppeteer.js +0 -3905
- package/docs/build/REST.js +0 -344
- package/docs/build/TestCafe.js +0 -2125
- package/docs/build/WebDriver.js +0 -4240
- package/docs/changelog.md +0 -2572
- package/docs/commands.md +0 -266
- package/docs/community-helpers.md +0 -58
- package/docs/configuration.md +0 -157
- package/docs/continuous-integration.md +0 -22
- package/docs/custom-helpers.md +0 -306
- package/docs/data.md +0 -379
- package/docs/detox.md +0 -235
- package/docs/docker.md +0 -136
- package/docs/email.md +0 -183
- package/docs/examples.md +0 -149
- package/docs/helpers/ApiDataFactory.md +0 -266
- package/docs/helpers/Appium.md +0 -1374
- package/docs/helpers/Detox.md +0 -586
- package/docs/helpers/Expect.md +0 -275
- package/docs/helpers/FileSystem.md +0 -152
- package/docs/helpers/GraphQL.md +0 -151
- package/docs/helpers/GraphQLDataFactory.md +0 -226
- package/docs/helpers/JSONResponse.md +0 -254
- package/docs/helpers/Mochawesome.md +0 -8
- package/docs/helpers/MockRequest.md +0 -377
- package/docs/helpers/Nightmare.md +0 -1305
- package/docs/helpers/OpenAI.md +0 -70
- package/docs/helpers/Playwright.md +0 -2759
- package/docs/helpers/Polly.md +0 -44
- package/docs/helpers/Protractor.md +0 -1769
- package/docs/helpers/Puppeteer-firefox.md +0 -86
- package/docs/helpers/Puppeteer.md +0 -2317
- package/docs/helpers/REST.md +0 -218
- package/docs/helpers/TestCafe.md +0 -1321
- package/docs/helpers/WebDriver.md +0 -2547
- package/docs/hooks.md +0 -340
- package/docs/index.md +0 -111
- package/docs/installation.md +0 -75
- package/docs/internal-api.md +0 -266
- package/docs/locators.md +0 -339
- package/docs/mobile-react-native-locators.md +0 -67
- package/docs/mobile.md +0 -338
- package/docs/pageobjects.md +0 -291
- package/docs/parallel.md +0 -400
- package/docs/playwright.md +0 -632
- package/docs/plugins.md +0 -1259
- package/docs/puppeteer.md +0 -316
- package/docs/quickstart.md +0 -162
- package/docs/react.md +0 -70
- package/docs/reports.md +0 -392
- package/docs/secrets.md +0 -36
- package/docs/shadow.md +0 -68
- package/docs/shared/keys.mustache +0 -31
- package/docs/shared/react.mustache +0 -1
- package/docs/testcafe.md +0 -174
- package/docs/translation.md +0 -247
- package/docs/tutorial.md +0 -271
- package/docs/typescript.md +0 -180
- package/docs/ui.md +0 -59
- package/docs/videos.md +0 -28
- package/docs/visual.md +0 -202
- package/docs/vue.md +0 -143
- 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 -25
- 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/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/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/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/selectOption.mustache +0 -21
- package/docs/webapi/setCookie.mustache +0 -16
- package/docs/webapi/setGeoLocation.mustache +0 -12
- 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/waitForDetached.mustache +0 -10
- 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/docs/webdriver.md +0 -701
- package/docs/wiki/Books-&-Posts.md +0 -27
- package/docs/wiki/Community-Helpers-&-Plugins.md +0 -53
- package/docs/wiki/Converting-Playwright-to-Istanbul-Coverage.md +0 -61
- package/docs/wiki/Examples.md +0 -145
- package/docs/wiki/Google-Summer-of-Code-(GSoC)-2020.md +0 -68
- package/docs/wiki/Home.md +0 -16
- package/docs/wiki/Migration-to-Appium-v2---CodeceptJS.md +0 -83
- package/docs/wiki/Release-Process.md +0 -24
- package/docs/wiki/Roadmap.md +0 -23
- package/docs/wiki/Tests.md +0 -1393
- package/docs/wiki/Upgrading-to-CodeceptJS-3.md +0 -153
- package/docs/wiki/Videos.md +0 -19
- package/lib/css2xpath/js/css_to_xpath.js +0 -20
- package/lib/css2xpath/js/expression.js +0 -23
- package/lib/css2xpath/js/renderer.js +0 -239
package/docs/plugins.md
DELETED
|
@@ -1,1259 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
permalink: plugins
|
|
3
|
-
sidebarDepth:
|
|
4
|
-
sidebar: auto
|
|
5
|
-
title: Plugins
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
9
|
-
|
|
10
|
-
## autoDelay
|
|
11
|
-
|
|
12
|
-
Sometimes it takes some time for a page to respond to user's actions.
|
|
13
|
-
Depending on app's performance this can be either slow or fast.
|
|
14
|
-
|
|
15
|
-
For instance, if you click a button and nothing happens - probably JS event is not attached to this button yet
|
|
16
|
-
Also, if you fill field and input validation doesn't accept your input - maybe because you typed value too fast.
|
|
17
|
-
|
|
18
|
-
This plugin allows to slow down tests execution when a test running too fast.
|
|
19
|
-
It puts a tiny delay for before and after action commands.
|
|
20
|
-
|
|
21
|
-
Commands affected (by default):
|
|
22
|
-
|
|
23
|
-
- `click`
|
|
24
|
-
- `fillField`
|
|
25
|
-
- `checkOption`
|
|
26
|
-
- `pressKey`
|
|
27
|
-
- `doubleClick`
|
|
28
|
-
- `rightClick`
|
|
29
|
-
|
|
30
|
-
#### Configuration
|
|
31
|
-
|
|
32
|
-
```js
|
|
33
|
-
plugins: {
|
|
34
|
-
autoDelay: {
|
|
35
|
-
enabled: true
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
Possible config options:
|
|
41
|
-
|
|
42
|
-
- `methods`: list of affected commands. Can be overridden
|
|
43
|
-
- `delayBefore`: put a delay before a command. 100ms by default
|
|
44
|
-
- `delayAfter`: put a delay after a command. 200ms by default
|
|
45
|
-
|
|
46
|
-
### Parameters
|
|
47
|
-
|
|
48
|
-
- `config`
|
|
49
|
-
|
|
50
|
-
## autoLogin
|
|
51
|
-
|
|
52
|
-
Logs user in for the first test and reuses session for next tests.
|
|
53
|
-
Works by saving cookies into memory or file.
|
|
54
|
-
If a session expires automatically logs in again.
|
|
55
|
-
|
|
56
|
-
> For better development experience cookies can be saved into file, so a session can be reused while writing tests.
|
|
57
|
-
|
|
58
|
-
#### Usage
|
|
59
|
-
|
|
60
|
-
1. Enable this plugin and configure as described below
|
|
61
|
-
2. Define user session names (example: `user`, `editor`, `admin`, etc).
|
|
62
|
-
3. Define how users are logged in and how to check that user is logged in
|
|
63
|
-
4. Use `login` object inside your tests to log in:
|
|
64
|
-
|
|
65
|
-
```js
|
|
66
|
-
// inside a test file
|
|
67
|
-
// use login to inject auto-login function
|
|
68
|
-
Feature('Login');
|
|
69
|
-
|
|
70
|
-
Before(({ login }) => {
|
|
71
|
-
login('user'); // login using user session
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
// Alternatively log in for one scenario.
|
|
75
|
-
Scenario('log me in', ( { I, login } ) => {
|
|
76
|
-
login('admin');
|
|
77
|
-
I.see('I am logged in');
|
|
78
|
-
});
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
#### Configuration
|
|
82
|
-
|
|
83
|
-
- `saveToFile` (default: false) - save cookies to file. Allows to reuse session between execution.
|
|
84
|
-
- `inject` (default: `login`) - name of the login function to use
|
|
85
|
-
- `users` - an array containing different session names and functions to:
|
|
86
|
-
- `login` - sign in into the system
|
|
87
|
-
- `check` - check that user is logged in
|
|
88
|
-
- `fetch` - to get current cookies (by default `I.grabCookie()`)
|
|
89
|
-
- `restore` - to set cookies (by default `I.amOnPage('/'); I.setCookie(cookie)`)
|
|
90
|
-
|
|
91
|
-
#### How It Works
|
|
92
|
-
|
|
93
|
-
1. `restore` method is executed. It should open a page and set credentials.
|
|
94
|
-
2. `check` method is executed. It should reload a page (so cookies are applied) and check that this page belongs to logged-in user. When you pass the second args `session`, you could perform the validation using passed session.
|
|
95
|
-
3. If `restore` and `check` were not successful, `login` is executed
|
|
96
|
-
4. `login` should fill in login form
|
|
97
|
-
5. After successful login, `fetch` is executed to save cookies into memory or file.
|
|
98
|
-
|
|
99
|
-
#### Example: Simple login
|
|
100
|
-
|
|
101
|
-
```js
|
|
102
|
-
autoLogin: {
|
|
103
|
-
enabled: true,
|
|
104
|
-
saveToFile: true,
|
|
105
|
-
inject: 'login',
|
|
106
|
-
users: {
|
|
107
|
-
admin: {
|
|
108
|
-
// loginAdmin function is defined in `steps_file.js`
|
|
109
|
-
login: (I) => I.loginAdmin(),
|
|
110
|
-
// if we see `Admin` on page, we assume we are logged in
|
|
111
|
-
check: (I) => {
|
|
112
|
-
I.amOnPage('/');
|
|
113
|
-
I.see('Admin');
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
#### Example: Multiple users
|
|
121
|
-
|
|
122
|
-
```js
|
|
123
|
-
autoLogin: {
|
|
124
|
-
enabled: true,
|
|
125
|
-
saveToFile: true,
|
|
126
|
-
inject: 'loginAs', // use `loginAs` instead of login
|
|
127
|
-
users: {
|
|
128
|
-
user: {
|
|
129
|
-
login: (I) => {
|
|
130
|
-
I.amOnPage('/login');
|
|
131
|
-
I.fillField('email', 'user@site.com');
|
|
132
|
-
I.fillField('password', '123456');
|
|
133
|
-
I.click('Login');
|
|
134
|
-
},
|
|
135
|
-
check: (I) => {
|
|
136
|
-
I.amOnPage('/');
|
|
137
|
-
I.see('User', '.navbar');
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
admin: {
|
|
141
|
-
login: (I) => {
|
|
142
|
-
I.amOnPage('/login');
|
|
143
|
-
I.fillField('email', 'admin@site.com');
|
|
144
|
-
I.fillField('password', '123456');
|
|
145
|
-
I.click('Login');
|
|
146
|
-
},
|
|
147
|
-
check: (I) => {
|
|
148
|
-
I.amOnPage('/');
|
|
149
|
-
I.see('Admin', '.navbar');
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
#### Example: Keep cookies between tests
|
|
157
|
-
|
|
158
|
-
If you decide to keep cookies between tests you don't need to save/retrieve cookies between tests.
|
|
159
|
-
But you need to login once work until session expires.
|
|
160
|
-
For this case, disable `fetch` and `restore` methods.
|
|
161
|
-
|
|
162
|
-
```js
|
|
163
|
-
helpers: {
|
|
164
|
-
WebDriver: {
|
|
165
|
-
// config goes here
|
|
166
|
-
keepCookies: true; // keep cookies for all tests
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
plugins: {
|
|
170
|
-
autoLogin: {
|
|
171
|
-
users: {
|
|
172
|
-
admin: {
|
|
173
|
-
login: (I) => {
|
|
174
|
-
I.amOnPage('/login');
|
|
175
|
-
I.fillField('email', 'admin@site.com');
|
|
176
|
-
I.fillField('password', '123456');
|
|
177
|
-
I.click('Login');
|
|
178
|
-
},
|
|
179
|
-
check: (I) => {
|
|
180
|
-
I.amOnPage('/dashboard');
|
|
181
|
-
I.see('Admin', '.navbar');
|
|
182
|
-
},
|
|
183
|
-
fetch: () => {}, // empty function
|
|
184
|
-
restore: () => {}, // empty funciton
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
#### Example: Getting sessions from local storage
|
|
192
|
-
|
|
193
|
-
If your session is stored in local storage instead of cookies you still can obtain sessions.
|
|
194
|
-
|
|
195
|
-
```js
|
|
196
|
-
plugins: {
|
|
197
|
-
autoLogin: {
|
|
198
|
-
admin: {
|
|
199
|
-
login: (I) => I.loginAsAdmin(),
|
|
200
|
-
check: (I) => I.see('Admin', '.navbar'),
|
|
201
|
-
fetch: (I) => {
|
|
202
|
-
return I.executeScript(() => localStorage.getItem('session_id'));
|
|
203
|
-
},
|
|
204
|
-
restore: (I, session) => {
|
|
205
|
-
I.amOnPage('/');
|
|
206
|
-
I.executeScript((session) => localStorage.setItem('session_id', session), session);
|
|
207
|
-
},
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
#### Tips: Using async function in the autoLogin
|
|
214
|
-
|
|
215
|
-
If you use async functions in the autoLogin plugin, login function should be used with `await` keyword.
|
|
216
|
-
|
|
217
|
-
```js
|
|
218
|
-
autoLogin: {
|
|
219
|
-
enabled: true,
|
|
220
|
-
saveToFile: true,
|
|
221
|
-
inject: 'login',
|
|
222
|
-
users: {
|
|
223
|
-
admin: {
|
|
224
|
-
login: async (I) => { // If you use async function in the autoLogin plugin
|
|
225
|
-
const phrase = await I.grabTextFrom('#phrase')
|
|
226
|
-
I.fillField('username', 'admin'),
|
|
227
|
-
I.fillField('password', 'password')
|
|
228
|
-
I.fillField('phrase', phrase)
|
|
229
|
-
},
|
|
230
|
-
check: (I) => {
|
|
231
|
-
I.amOnPage('/');
|
|
232
|
-
I.see('Admin');
|
|
233
|
-
},
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
```js
|
|
240
|
-
Scenario('login', async ( {I, login} ) => {
|
|
241
|
-
await login('admin') // you should use `await`
|
|
242
|
-
})
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
#### Tips: Using session to validate user
|
|
246
|
-
|
|
247
|
-
Instead of asserting on page elements for the current user in `check`, you can use the `session` you saved in `fetch`
|
|
248
|
-
|
|
249
|
-
```js
|
|
250
|
-
autoLogin: {
|
|
251
|
-
enabled: true,
|
|
252
|
-
saveToFile: true,
|
|
253
|
-
inject: 'login',
|
|
254
|
-
users: {
|
|
255
|
-
admin: {
|
|
256
|
-
login: async (I) => { // If you use async function in the autoLogin plugin
|
|
257
|
-
const phrase = await I.grabTextFrom('#phrase')
|
|
258
|
-
I.fillField('username', 'admin'),
|
|
259
|
-
I.fillField('password', 'password')
|
|
260
|
-
I.fillField('phrase', phrase)
|
|
261
|
-
},
|
|
262
|
-
check: (I, session) => {
|
|
263
|
-
// Throwing an error in `check` will make CodeceptJS perform the login step for the user
|
|
264
|
-
if (session.profile.email !== the.email.you.expect@some-mail.com) {
|
|
265
|
-
throw new Error ('Wrong user signed in');
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
```js
|
|
274
|
-
Scenario('login', async ( {I, login} ) => {
|
|
275
|
-
await login('admin') // you should use `await`
|
|
276
|
-
})
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
### Parameters
|
|
280
|
-
|
|
281
|
-
- `config`
|
|
282
|
-
|
|
283
|
-
## commentStep
|
|
284
|
-
|
|
285
|
-
Add descriptive nested steps for your tests:
|
|
286
|
-
|
|
287
|
-
```js
|
|
288
|
-
Scenario('project update test', async (I) => {
|
|
289
|
-
__`Given`;
|
|
290
|
-
const projectId = await I.have('project');
|
|
291
|
-
|
|
292
|
-
__`When`;
|
|
293
|
-
projectPage.update(projectId, { title: 'new title' });
|
|
294
|
-
|
|
295
|
-
__`Then`;
|
|
296
|
-
projectPage.open(projectId);
|
|
297
|
-
I.see('new title', 'h1');
|
|
298
|
-
})
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
Steps prefixed with `__` will be printed as nested steps in `--steps` output:
|
|
302
|
-
|
|
303
|
-
Given
|
|
304
|
-
I have "project"
|
|
305
|
-
When
|
|
306
|
-
projectPage update
|
|
307
|
-
Then
|
|
308
|
-
projectPage open
|
|
309
|
-
I see "new title", "h1"
|
|
310
|
-
|
|
311
|
-
Also those steps will be exported to allure reports.
|
|
312
|
-
|
|
313
|
-
This plugin can be used
|
|
314
|
-
|
|
315
|
-
### Config
|
|
316
|
-
|
|
317
|
-
- `enabled` - (default: false) enable a plugin
|
|
318
|
-
- `registerGlobal` - (default: false) register `__` template literal function globally. You can override function global name by providing a name as a value.
|
|
319
|
-
|
|
320
|
-
### Examples
|
|
321
|
-
|
|
322
|
-
Registering `__` globally:
|
|
323
|
-
|
|
324
|
-
```js
|
|
325
|
-
plugins: {
|
|
326
|
-
commentStep: {
|
|
327
|
-
enabled: true,
|
|
328
|
-
registerGlobal: true
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
Registering `Step` globally:
|
|
334
|
-
|
|
335
|
-
```js
|
|
336
|
-
plugins: {
|
|
337
|
-
commentStep: {
|
|
338
|
-
enabled: true,
|
|
339
|
-
registerGlobal: 'Step'
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
Using only local function names:
|
|
345
|
-
|
|
346
|
-
```js
|
|
347
|
-
plugins: {
|
|
348
|
-
commentStep: {
|
|
349
|
-
enabled: true
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
Then inside a test import a comment function from a plugin.
|
|
355
|
-
For instance, you can prepare Given/When/Then functions to use them inside tests:
|
|
356
|
-
|
|
357
|
-
```js
|
|
358
|
-
// inside a test
|
|
359
|
-
const step = codeceptjs.container.plugins('commentStep');
|
|
360
|
-
|
|
361
|
-
const Given = () => step`Given`;
|
|
362
|
-
const When = () => step`When`;
|
|
363
|
-
const Then = () => step`Then`;
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
Scenario('project update test', async (I) => {
|
|
367
|
-
Given();
|
|
368
|
-
const projectId = await I.have('project');
|
|
369
|
-
|
|
370
|
-
When();
|
|
371
|
-
projectPage.update(projectId, { title: 'new title' });
|
|
372
|
-
|
|
373
|
-
Then();
|
|
374
|
-
projectPage.open(projectId);
|
|
375
|
-
I.see('new title', 'h1');
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
```
|
|
379
|
-
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
### Parameters
|
|
383
|
-
|
|
384
|
-
- `config`
|
|
385
|
-
|
|
386
|
-
## coverage
|
|
387
|
-
|
|
388
|
-
Dumps code coverage from Playwright/Puppeteer after every test.
|
|
389
|
-
|
|
390
|
-
#### Configuration
|
|
391
|
-
|
|
392
|
-
```js
|
|
393
|
-
plugins: {
|
|
394
|
-
coverage: {
|
|
395
|
-
enabled: true
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
Possible config options:
|
|
401
|
-
|
|
402
|
-
- `coverageDir`: directory to dump coverage files
|
|
403
|
-
- `uniqueFileName`: generate a unique filename by adding uuid
|
|
404
|
-
|
|
405
|
-
### Parameters
|
|
406
|
-
|
|
407
|
-
- `config`
|
|
408
|
-
|
|
409
|
-
## customLocator
|
|
410
|
-
|
|
411
|
-
Creates a [custom locator][1] by using special attributes in HTML.
|
|
412
|
-
|
|
413
|
-
If you have a convention to use `data-test-id` or `data-qa` attributes to mark active elements for e2e tests,
|
|
414
|
-
you can enable this plugin to simplify matching elements with these attributes:
|
|
415
|
-
|
|
416
|
-
```js
|
|
417
|
-
// replace this:
|
|
418
|
-
I.click({ css: '[data-test-id=register_button]');
|
|
419
|
-
// with this:
|
|
420
|
-
I.click('$register_button');
|
|
421
|
-
```
|
|
422
|
-
|
|
423
|
-
This plugin will create a valid XPath locator for you.
|
|
424
|
-
|
|
425
|
-
#### Configuration
|
|
426
|
-
|
|
427
|
-
- `enabled` (default: `false`) should a locator be enabled
|
|
428
|
-
- `prefix` (default: `$`) sets a prefix for a custom locator.
|
|
429
|
-
- `attribute` (default: `data-test-id`) to set an attribute to be matched.
|
|
430
|
-
- `strategy` (default: `xpath`) actual locator strategy to use in query (`css` or `xpath`).
|
|
431
|
-
- `showActual` (default: false) show in the output actually produced XPath or CSS locator. By default shows custom locator value.
|
|
432
|
-
|
|
433
|
-
#### Examples:
|
|
434
|
-
|
|
435
|
-
Using `data-test` attribute with `$` prefix:
|
|
436
|
-
|
|
437
|
-
```js
|
|
438
|
-
// in codecept.conf.js
|
|
439
|
-
plugins: {
|
|
440
|
-
customLocator: {
|
|
441
|
-
enabled: true,
|
|
442
|
-
attribute: 'data-test'
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
```
|
|
446
|
-
|
|
447
|
-
In a test:
|
|
448
|
-
|
|
449
|
-
```js
|
|
450
|
-
I.seeElement('$user'); // matches => [data-test=user]
|
|
451
|
-
I.click('$sign-up'); // matches => [data-test=sign-up]
|
|
452
|
-
```
|
|
453
|
-
|
|
454
|
-
Using `data-qa` attribute with `=` prefix:
|
|
455
|
-
|
|
456
|
-
```js
|
|
457
|
-
// in codecept.conf.js
|
|
458
|
-
plugins: {
|
|
459
|
-
customLocator: {
|
|
460
|
-
enabled: true,
|
|
461
|
-
prefix: '=',
|
|
462
|
-
attribute: 'data-qa'
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
```
|
|
466
|
-
|
|
467
|
-
In a test:
|
|
468
|
-
|
|
469
|
-
```js
|
|
470
|
-
I.seeElement('=user'); // matches => [data-qa=user]
|
|
471
|
-
I.click('=sign-up'); // matches => [data-qa=sign-up]
|
|
472
|
-
```
|
|
473
|
-
|
|
474
|
-
Using `data-qa` OR `data-test` attribute with `=` prefix:
|
|
475
|
-
|
|
476
|
-
```js
|
|
477
|
-
// in codecept.conf.js
|
|
478
|
-
plugins: {
|
|
479
|
-
customLocator: {
|
|
480
|
-
enabled: true,
|
|
481
|
-
prefix: '=',
|
|
482
|
-
attribute: ['data-qa', 'data-test'],
|
|
483
|
-
strategy: 'xpath'
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
```
|
|
487
|
-
|
|
488
|
-
In a test:
|
|
489
|
-
|
|
490
|
-
```js
|
|
491
|
-
I.seeElement('=user'); // matches => //*[@data-qa=user or @data-test=user]
|
|
492
|
-
I.click('=sign-up'); // matches => //*[data-qa=sign-up or @data-test=sign-up]
|
|
493
|
-
```
|
|
494
|
-
|
|
495
|
-
```js
|
|
496
|
-
// in codecept.conf.js
|
|
497
|
-
plugins: {
|
|
498
|
-
customLocator: {
|
|
499
|
-
enabled: true,
|
|
500
|
-
prefix: '=',
|
|
501
|
-
attribute: ['data-qa', 'data-test'],
|
|
502
|
-
strategy: 'css'
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
```
|
|
506
|
-
|
|
507
|
-
In a test:
|
|
508
|
-
|
|
509
|
-
```js
|
|
510
|
-
I.seeElement('=user'); // matches => [data-qa=user],[data-test=user]
|
|
511
|
-
I.click('=sign-up'); // matches => [data-qa=sign-up],[data-test=sign-up]
|
|
512
|
-
```
|
|
513
|
-
|
|
514
|
-
### Parameters
|
|
515
|
-
|
|
516
|
-
- `config`
|
|
517
|
-
|
|
518
|
-
## debugErrors
|
|
519
|
-
|
|
520
|
-
Prints errors found in HTML code after each failed test.
|
|
521
|
-
|
|
522
|
-
It scans HTML and searches for elements with error classes.
|
|
523
|
-
If an element found prints a text from it to console and adds as artifact to the test.
|
|
524
|
-
|
|
525
|
-
Enable this plugin in config:
|
|
526
|
-
|
|
527
|
-
```js
|
|
528
|
-
plugins: {
|
|
529
|
-
debugErrors: {
|
|
530
|
-
enabled: true,
|
|
531
|
-
}
|
|
532
|
-
```
|
|
533
|
-
|
|
534
|
-
Additional config options:
|
|
535
|
-
|
|
536
|
-
- `errorClasses` - list of classes to search for errors (default: `['error', 'warning', 'alert', 'danger']`)
|
|
537
|
-
|
|
538
|
-
### Parameters
|
|
539
|
-
|
|
540
|
-
- `config` (optional, default `{}`)
|
|
541
|
-
|
|
542
|
-
## eachElement
|
|
543
|
-
|
|
544
|
-
Provides `eachElement` global function to iterate over found elements to perform actions on them.
|
|
545
|
-
|
|
546
|
-
`eachElement` takes following args:
|
|
547
|
-
|
|
548
|
-
- `purpose` - the goal of an action. A comment text that will be displayed in output.
|
|
549
|
-
- `locator` - a CSS/XPath locator to match elements
|
|
550
|
-
- `fn(element, index)` - **asynchronous** function which will be executed for each matched element.
|
|
551
|
-
|
|
552
|
-
Example of usage:
|
|
553
|
-
|
|
554
|
-
```js
|
|
555
|
-
// this example works with Playwright and Puppeteer helper
|
|
556
|
-
await eachElement('click all checkboxes', 'form input[type=checkbox]', async (el) => {
|
|
557
|
-
await el.click();
|
|
558
|
-
});
|
|
559
|
-
```
|
|
560
|
-
|
|
561
|
-
Click odd elements:
|
|
562
|
-
|
|
563
|
-
```js
|
|
564
|
-
// this example works with Playwright and Puppeteer helper
|
|
565
|
-
await eachElement('click odd buttons', '.button-select', async (el, index) => {
|
|
566
|
-
if (index % 2) await el.click();
|
|
567
|
-
});
|
|
568
|
-
```
|
|
569
|
-
|
|
570
|
-
Check all elements for visibility:
|
|
571
|
-
|
|
572
|
-
```js
|
|
573
|
-
// this example works with Playwright and Puppeteer helper
|
|
574
|
-
const assert = require('assert');
|
|
575
|
-
await eachElement('check all items are visible', '.item', async (el) => {
|
|
576
|
-
assert(await el.isVisible());
|
|
577
|
-
});
|
|
578
|
-
```
|
|
579
|
-
|
|
580
|
-
This method works with WebDriver, Playwright, Puppeteer, Appium helpers.
|
|
581
|
-
|
|
582
|
-
Function parameter `el` represents a matched element.
|
|
583
|
-
Depending on a helper API of `el` can be different. Refer to API of corresponding browser testing engine for a complete API list:
|
|
584
|
-
|
|
585
|
-
- [Playwright ElementHandle][2]
|
|
586
|
-
- [Puppeteer][3]
|
|
587
|
-
- [webdriverio element][4]
|
|
588
|
-
|
|
589
|
-
#### Configuration
|
|
590
|
-
|
|
591
|
-
- `registerGlobal` - to register `eachElement` function globally, true by default
|
|
592
|
-
|
|
593
|
-
If `registerGlobal` is false you can use eachElement from the plugin:
|
|
594
|
-
|
|
595
|
-
```js
|
|
596
|
-
const eachElement = codeceptjs.container.plugins('eachElement');
|
|
597
|
-
```
|
|
598
|
-
|
|
599
|
-
### Parameters
|
|
600
|
-
|
|
601
|
-
- `purpose` **[string][5]**
|
|
602
|
-
- `locator` **CodeceptJS.LocatorOrString**
|
|
603
|
-
- `fn` **[Function][6]**
|
|
604
|
-
|
|
605
|
-
Returns **([Promise][7]<any> | [undefined][8])**
|
|
606
|
-
|
|
607
|
-
## fakerTransform
|
|
608
|
-
|
|
609
|
-
Use the `@faker-js/faker` package to generate fake data inside examples on your gherkin tests
|
|
610
|
-
|
|
611
|
-
#### Usage
|
|
612
|
-
|
|
613
|
-
To start please install `@faker-js/faker` package
|
|
614
|
-
|
|
615
|
-
npm install -D @faker-js/faker
|
|
616
|
-
|
|
617
|
-
yarn add -D @faker-js/faker
|
|
618
|
-
|
|
619
|
-
Add this plugin to config file:
|
|
620
|
-
|
|
621
|
-
```js
|
|
622
|
-
plugins: {
|
|
623
|
-
fakerTransform: {
|
|
624
|
-
enabled: true
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
```
|
|
628
|
-
|
|
629
|
-
Add the faker API using a mustache string format inside examples tables in your gherkin scenario outline
|
|
630
|
-
|
|
631
|
-
```feature
|
|
632
|
-
Scenario Outline: ...
|
|
633
|
-
Given ...
|
|
634
|
-
When ...
|
|
635
|
-
Then ...
|
|
636
|
-
Examples:
|
|
637
|
-
| productName | customer | email | anythingMore |
|
|
638
|
-
| {{commerce.product}} | Dr. {{name.findName}} | {{internet.email}} | staticData |
|
|
639
|
-
```
|
|
640
|
-
|
|
641
|
-
### Parameters
|
|
642
|
-
|
|
643
|
-
- `config`
|
|
644
|
-
|
|
645
|
-
## heal
|
|
646
|
-
|
|
647
|
-
Self-healing tests with OpenAI.
|
|
648
|
-
|
|
649
|
-
This plugin is experimental and requires OpenAI API key.
|
|
650
|
-
|
|
651
|
-
To use it you need to set OPENAI_API_KEY env variable and enable plugin inside the config.
|
|
652
|
-
|
|
653
|
-
```js
|
|
654
|
-
plugins: {
|
|
655
|
-
heal: {
|
|
656
|
-
enabled: true,
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
```
|
|
660
|
-
|
|
661
|
-
More config options are available:
|
|
662
|
-
|
|
663
|
-
- `healLimit` - how many steps can be healed in a single test (default: 2)
|
|
664
|
-
- `healSteps` - which steps can be healed (default: all steps that interact with UI, see list below)
|
|
665
|
-
|
|
666
|
-
Steps to heal:
|
|
667
|
-
|
|
668
|
-
- `click`
|
|
669
|
-
- `fillField`
|
|
670
|
-
- `appendField`
|
|
671
|
-
- `selectOption`
|
|
672
|
-
- `attachFile`
|
|
673
|
-
- `checkOption`
|
|
674
|
-
- `uncheckOption`
|
|
675
|
-
- `doubleClick`
|
|
676
|
-
|
|
677
|
-
### Parameters
|
|
678
|
-
|
|
679
|
-
- `config` (optional, default `{}`)
|
|
680
|
-
|
|
681
|
-
## pauseOnFail
|
|
682
|
-
|
|
683
|
-
Automatically launches [interactive pause][9] when a test fails.
|
|
684
|
-
|
|
685
|
-
Useful for debugging flaky tests on local environment.
|
|
686
|
-
Add this plugin to config file:
|
|
687
|
-
|
|
688
|
-
```js
|
|
689
|
-
plugins: {
|
|
690
|
-
pauseOnFail: {},
|
|
691
|
-
}
|
|
692
|
-
```
|
|
693
|
-
|
|
694
|
-
Unlike other plugins, `pauseOnFail` is not recommended to be enabled by default.
|
|
695
|
-
Enable it manually on each run via `-p` option:
|
|
696
|
-
|
|
697
|
-
npx codeceptjs run -p pauseOnFail
|
|
698
|
-
|
|
699
|
-
## retryFailedStep
|
|
700
|
-
|
|
701
|
-
Retries each failed step in a test.
|
|
702
|
-
|
|
703
|
-
Add this plugin to config file:
|
|
704
|
-
|
|
705
|
-
```js
|
|
706
|
-
plugins: {
|
|
707
|
-
retryFailedStep: {
|
|
708
|
-
enabled: true
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
```
|
|
712
|
-
|
|
713
|
-
Run tests with plugin enabled:
|
|
714
|
-
|
|
715
|
-
npx codeceptjs run --plugins retryFailedStep
|
|
716
|
-
|
|
717
|
-
#### Configuration:
|
|
718
|
-
|
|
719
|
-
- `retries` - number of retries (by default 3),
|
|
720
|
-
- `when` - function, when to perform a retry (accepts error as parameter)
|
|
721
|
-
- `factor` - The exponential factor to use. Default is 1.5.
|
|
722
|
-
- `minTimeout` - The number of milliseconds before starting the first retry. Default is 1000.
|
|
723
|
-
- `maxTimeout` - The maximum number of milliseconds between two retries. Default is Infinity.
|
|
724
|
-
- `randomize` - Randomizes the timeouts by multiplying with a factor from 1 to 2. Default is false.
|
|
725
|
-
- `defaultIgnoredSteps` - an array of steps to be ignored for retry. Includes:
|
|
726
|
-
- `amOnPage`
|
|
727
|
-
- `wait*`
|
|
728
|
-
- `send*`
|
|
729
|
-
- `execute*`
|
|
730
|
-
- `run*`
|
|
731
|
-
- `have*`
|
|
732
|
-
- `ignoredSteps` - an array for custom steps to ignore on retry. Use it to append custom steps to ignored list.
|
|
733
|
-
You can use step names or step prefixes ending with `*`. As such, `wait*` will match all steps starting with `wait`.
|
|
734
|
-
To append your own steps to ignore list - copy and paste a default steps list. Regexp values are accepted as well.
|
|
735
|
-
|
|
736
|
-
#### Example
|
|
737
|
-
|
|
738
|
-
```js
|
|
739
|
-
plugins: {
|
|
740
|
-
retryFailedStep: {
|
|
741
|
-
enabled: true,
|
|
742
|
-
ignoredSteps: [
|
|
743
|
-
'scroll*', // ignore all scroll steps
|
|
744
|
-
/Cookie/, // ignore all steps with a Cookie in it (by regexp)
|
|
745
|
-
]
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
```
|
|
749
|
-
|
|
750
|
-
#### Disable Per Test
|
|
751
|
-
|
|
752
|
-
This plugin can be disabled per test. In this case you will need to stet `I.retry()` to all flaky steps:
|
|
753
|
-
|
|
754
|
-
Use scenario configuration to disable plugin for a test
|
|
755
|
-
|
|
756
|
-
```js
|
|
757
|
-
Scenario('scenario tite', () => {
|
|
758
|
-
// test goes here
|
|
759
|
-
}).config(test => test.disableRetryFailedStep = true)
|
|
760
|
-
```
|
|
761
|
-
|
|
762
|
-
### Parameters
|
|
763
|
-
|
|
764
|
-
- `config`
|
|
765
|
-
|
|
766
|
-
## retryTo
|
|
767
|
-
|
|
768
|
-
Adds global `retryTo` which retries steps a few times before failing.
|
|
769
|
-
|
|
770
|
-
Enable this plugin in `codecept.conf.js` (enabled by default for new setups):
|
|
771
|
-
|
|
772
|
-
```js
|
|
773
|
-
plugins: {
|
|
774
|
-
retryTo: {
|
|
775
|
-
enabled: true
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
```
|
|
779
|
-
|
|
780
|
-
Use it in your tests:
|
|
781
|
-
|
|
782
|
-
```js
|
|
783
|
-
// retry these steps 5 times before failing
|
|
784
|
-
await retryTo((tryNum) => {
|
|
785
|
-
I.switchTo('#editor frame');
|
|
786
|
-
I.click('Open');
|
|
787
|
-
I.see('Opened')
|
|
788
|
-
}, 5);
|
|
789
|
-
```
|
|
790
|
-
|
|
791
|
-
Set polling interval as 3rd argument (200ms by default):
|
|
792
|
-
|
|
793
|
-
```js
|
|
794
|
-
// retry these steps 5 times before failing
|
|
795
|
-
await retryTo((tryNum) => {
|
|
796
|
-
I.switchTo('#editor frame');
|
|
797
|
-
I.click('Open');
|
|
798
|
-
I.see('Opened')
|
|
799
|
-
}, 5, 100);
|
|
800
|
-
```
|
|
801
|
-
|
|
802
|
-
Default polling interval can be changed in a config:
|
|
803
|
-
|
|
804
|
-
```js
|
|
805
|
-
plugins: {
|
|
806
|
-
retryTo: {
|
|
807
|
-
enabled: true,
|
|
808
|
-
pollInterval: 500,
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
```
|
|
812
|
-
|
|
813
|
-
Disables retryFailedStep plugin for steps inside a block;
|
|
814
|
-
|
|
815
|
-
Use this plugin if:
|
|
816
|
-
|
|
817
|
-
- you need repeat a set of actions in flaky tests
|
|
818
|
-
- iframe was not rendered and you need to retry switching to it
|
|
819
|
-
|
|
820
|
-
#### Configuration
|
|
821
|
-
|
|
822
|
-
- `pollInterval` - default interval between retries in ms. 200 by default.
|
|
823
|
-
- `registerGlobal` - to register `retryTo` function globally, true by default
|
|
824
|
-
|
|
825
|
-
If `registerGlobal` is false you can use retryTo from the plugin:
|
|
826
|
-
|
|
827
|
-
```js
|
|
828
|
-
const retryTo = codeceptjs.container.plugins('retryTo');
|
|
829
|
-
```
|
|
830
|
-
|
|
831
|
-
### Parameters
|
|
832
|
-
|
|
833
|
-
- `config`
|
|
834
|
-
|
|
835
|
-
## screenshotOnFail
|
|
836
|
-
|
|
837
|
-
Creates screenshot on failure. Screenshot is saved into `output` directory.
|
|
838
|
-
|
|
839
|
-
Initially this functionality was part of corresponding helper but has been moved into plugin since 1.4
|
|
840
|
-
|
|
841
|
-
This plugin is **enabled by default**.
|
|
842
|
-
|
|
843
|
-
#### Configuration
|
|
844
|
-
|
|
845
|
-
Configuration can either be taken from a corresponding helper (deprecated) or a from plugin config (recommended).
|
|
846
|
-
|
|
847
|
-
```js
|
|
848
|
-
plugins: {
|
|
849
|
-
screenshotOnFail: {
|
|
850
|
-
enabled: true
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
```
|
|
854
|
-
|
|
855
|
-
Possible config options:
|
|
856
|
-
|
|
857
|
-
- `uniqueScreenshotNames`: use unique names for screenshot. Default: false.
|
|
858
|
-
- `fullPageScreenshots`: make full page screenshots. Default: false.
|
|
859
|
-
|
|
860
|
-
### Parameters
|
|
861
|
-
|
|
862
|
-
- `config`
|
|
863
|
-
|
|
864
|
-
## selenoid
|
|
865
|
-
|
|
866
|
-
[Selenoid][10] plugin automatically starts browsers and video recording.
|
|
867
|
-
Works with WebDriver helper.
|
|
868
|
-
|
|
869
|
-
### Prerequisite
|
|
870
|
-
|
|
871
|
-
This plugin **requires Docker** to be installed.
|
|
872
|
-
|
|
873
|
-
> If you have issues starting Selenoid with this plugin consider using the official [Configuration Manager][11] tool from Selenoid
|
|
874
|
-
|
|
875
|
-
### Usage
|
|
876
|
-
|
|
877
|
-
Selenoid plugin can be started in two ways:
|
|
878
|
-
|
|
879
|
-
1. **Automatic** - this plugin will create and manage selenoid container for you.
|
|
880
|
-
2. **Manual** - you create the conatainer and configure it with a plugin (recommended).
|
|
881
|
-
|
|
882
|
-
#### Automatic
|
|
883
|
-
|
|
884
|
-
If you are new to Selenoid and you want plug and play setup use automatic mode.
|
|
885
|
-
|
|
886
|
-
Add plugin configuration in `codecept.conf.js`:
|
|
887
|
-
|
|
888
|
-
```js
|
|
889
|
-
plugins: {
|
|
890
|
-
selenoid: {
|
|
891
|
-
enabled: true,
|
|
892
|
-
deletePassed: true,
|
|
893
|
-
autoCreate: true,
|
|
894
|
-
autoStart: true,
|
|
895
|
-
sessionTimeout: '30m',
|
|
896
|
-
enableVideo: true,
|
|
897
|
-
enableLog: true,
|
|
898
|
-
},
|
|
899
|
-
}
|
|
900
|
-
```
|
|
901
|
-
|
|
902
|
-
When `autoCreate` is enabled it will pull the [latest Selenoid from DockerHub][12] and start Selenoid automatically.
|
|
903
|
-
It will also create `browsers.json` file required by Selenoid.
|
|
904
|
-
|
|
905
|
-
In automatic mode the latest version of browser will be used for tests. It is recommended to specify exact version of each browser inside `browsers.json` file.
|
|
906
|
-
|
|
907
|
-
> **If you are using Windows machine or if `autoCreate` does not work properly, create container manually**
|
|
908
|
-
|
|
909
|
-
#### Manual
|
|
910
|
-
|
|
911
|
-
While this plugin can create containers for you for better control it is recommended to create and launch containers manually.
|
|
912
|
-
This is especially useful for Continous Integration server as you can configure scaling for Selenoid containers.
|
|
913
|
-
|
|
914
|
-
> Use [Selenoid Configuration Manager][11] to create and start containers semi-automatically.
|
|
915
|
-
|
|
916
|
-
1. Create `browsers.json` file in the same directory `codecept.conf.js` is located
|
|
917
|
-
[Refer to Selenoid documentation][13] to know more about browsers.json.
|
|
918
|
-
|
|
919
|
-
_Sample browsers.json_
|
|
920
|
-
|
|
921
|
-
```js
|
|
922
|
-
{
|
|
923
|
-
"chrome": {
|
|
924
|
-
"default": "latest",
|
|
925
|
-
"versions": {
|
|
926
|
-
"latest": {
|
|
927
|
-
"image": "selenoid/chrome:latest",
|
|
928
|
-
"port": "4444",
|
|
929
|
-
"path": "/"
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
```
|
|
935
|
-
|
|
936
|
-
> It is recommended to use specific versions of browsers in `browsers.json` instead of latest. This will prevent tests fail when browsers will be updated.
|
|
937
|
-
|
|
938
|
-
**⚠ At first launch selenoid plugin takes extra time to download all Docker images before tests starts**.
|
|
939
|
-
|
|
940
|
-
2. Create Selenoid container
|
|
941
|
-
|
|
942
|
-
Run the following command to create a container. To know more [refer here][14]
|
|
943
|
-
|
|
944
|
-
```bash
|
|
945
|
-
docker create \
|
|
946
|
-
--name selenoid \
|
|
947
|
-
-p 4444:4444 \
|
|
948
|
-
-v /var/run/docker.sock:/var/run/docker.sock \
|
|
949
|
-
-v `pwd`/:/etc/selenoid/:ro \
|
|
950
|
-
-v `pwd`/output/video/:/opt/selenoid/video/ \
|
|
951
|
-
-e OVERRIDE_VIDEO_OUTPUT_DIR=`pwd`/output/video/ \
|
|
952
|
-
aerokube/selenoid:latest-release
|
|
953
|
-
```
|
|
954
|
-
|
|
955
|
-
### Video Recording
|
|
956
|
-
|
|
957
|
-
This plugin allows to record and save video per each executed tests.
|
|
958
|
-
|
|
959
|
-
When `enableVideo` is `true` this plugin saves video in `output/videos` directory with each test by name
|
|
960
|
-
To save space videos for all succesful tests are deleted. This can be changed by `deletePassed` option.
|
|
961
|
-
|
|
962
|
-
When `allure` plugin is enabled a video is attached to report automatically.
|
|
963
|
-
|
|
964
|
-
### Options:
|
|
965
|
-
|
|
966
|
-
| Param | Description |
|
|
967
|
-
| ---------------- | ------------------------------------------------------------------------------ |
|
|
968
|
-
| name | Name of the container (default : selenoid) |
|
|
969
|
-
| port | Port of selenium server (default : 4444) |
|
|
970
|
-
| autoCreate | Will automatically create container (Linux only) (default : true) |
|
|
971
|
-
| autoStart | If disabled start the container manually before running tests (default : true) |
|
|
972
|
-
| enableVideo | Enable video recording and use `video` folder of output (default: false) |
|
|
973
|
-
| enableLog | Enable log recording and use `logs` folder of output (default: false) |
|
|
974
|
-
| deletePassed | Delete video and logs of passed tests (default : true) |
|
|
975
|
-
| additionalParams | example: `additionalParams: '--env TEST=test'` [Refer here][15] to know more |
|
|
976
|
-
|
|
977
|
-
### Parameters
|
|
978
|
-
|
|
979
|
-
- `config`
|
|
980
|
-
|
|
981
|
-
## stepByStepReport
|
|
982
|
-
|
|
983
|
-
![step-by-step-report][16]
|
|
984
|
-
|
|
985
|
-
Generates step by step report for a test.
|
|
986
|
-
After each step in a test a screenshot is created. After test executed screenshots are combined into slideshow.
|
|
987
|
-
By default, reports are generated only for failed tests.
|
|
988
|
-
|
|
989
|
-
Run tests with plugin enabled:
|
|
990
|
-
|
|
991
|
-
npx codeceptjs run --plugins stepByStepReport
|
|
992
|
-
|
|
993
|
-
#### Configuration
|
|
994
|
-
|
|
995
|
-
```js
|
|
996
|
-
"plugins": {
|
|
997
|
-
"stepByStepReport": {
|
|
998
|
-
"enabled": true
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
```
|
|
1002
|
-
|
|
1003
|
-
Possible config options:
|
|
1004
|
-
|
|
1005
|
-
- `deleteSuccessful`: do not save screenshots for successfully executed tests. Default: true.
|
|
1006
|
-
- `animateSlides`: should animation for slides to be used. Default: true.
|
|
1007
|
-
- `ignoreSteps`: steps to ignore in report. Array of RegExps is expected. Recommended to skip `grab*` and `wait*` steps.
|
|
1008
|
-
- `fullPageScreenshots`: should full page screenshots be used. Default: false.
|
|
1009
|
-
- `output`: a directory where reports should be stored. Default: `output`.
|
|
1010
|
-
- `screenshotsForAllureReport`: If Allure plugin is enabled this plugin attaches each saved screenshot to allure report. Default: false.
|
|
1011
|
-
- \`disableScreenshotOnFail : Disables the capturing of screeshots after the failed step. Default: true.
|
|
1012
|
-
|
|
1013
|
-
### Parameters
|
|
1014
|
-
|
|
1015
|
-
- `config` **any**
|
|
1016
|
-
|
|
1017
|
-
## stepTimeout
|
|
1018
|
-
|
|
1019
|
-
Set timeout for test steps globally.
|
|
1020
|
-
|
|
1021
|
-
Add this plugin to config file:
|
|
1022
|
-
|
|
1023
|
-
```js
|
|
1024
|
-
plugins: {
|
|
1025
|
-
stepTimeout: {
|
|
1026
|
-
enabled: true
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
```
|
|
1030
|
-
|
|
1031
|
-
Run tests with plugin enabled:
|
|
1032
|
-
|
|
1033
|
-
npx codeceptjs run --plugins stepTimeout
|
|
1034
|
-
|
|
1035
|
-
#### Configuration:
|
|
1036
|
-
|
|
1037
|
-
- `timeout` - global step timeout, default 150 seconds
|
|
1038
|
-
- `overrideStepLimits` - whether to use timeouts set in plugin config to override step timeouts set in code with I.limitTime(x).action(...), default false
|
|
1039
|
-
- `noTimeoutSteps` - an array of steps with no timeout. Default:
|
|
1040
|
-
|
|
1041
|
-
- `amOnPage`
|
|
1042
|
-
- `wait*`
|
|
1043
|
-
|
|
1044
|
-
you could set your own noTimeoutSteps which would replace the default one.
|
|
1045
|
-
|
|
1046
|
-
- `customTimeoutSteps` - an array of step actions with custom timeout. Use it to override or extend noTimeoutSteps.
|
|
1047
|
-
You can use step names or step prefixes ending with `*`. As such, `wait*` will match all steps starting with `wait`.
|
|
1048
|
-
|
|
1049
|
-
#### Example
|
|
1050
|
-
|
|
1051
|
-
```js
|
|
1052
|
-
plugins: {
|
|
1053
|
-
stepTimeout: {
|
|
1054
|
-
enabled: true,
|
|
1055
|
-
overrideStepLimits: true,
|
|
1056
|
-
noTimeoutSteps: [
|
|
1057
|
-
'scroll*', // ignore all scroll steps
|
|
1058
|
-
/Cookie/, // ignore all steps with a Cookie in it (by regexp)
|
|
1059
|
-
],
|
|
1060
|
-
customTimeoutSteps: [
|
|
1061
|
-
['myFlakyStep*', 1],
|
|
1062
|
-
['scrollWhichRequiresTimeout', 5],
|
|
1063
|
-
]
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
```
|
|
1067
|
-
|
|
1068
|
-
### Parameters
|
|
1069
|
-
|
|
1070
|
-
- `config`
|
|
1071
|
-
|
|
1072
|
-
## subtitles
|
|
1073
|
-
|
|
1074
|
-
Automatically captures steps as subtitle, and saves it as an artifact when a video is found for a failed test
|
|
1075
|
-
|
|
1076
|
-
#### Configuration
|
|
1077
|
-
|
|
1078
|
-
```js
|
|
1079
|
-
plugins: {
|
|
1080
|
-
subtitles: {
|
|
1081
|
-
enabled: true
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
```
|
|
1085
|
-
|
|
1086
|
-
## tryTo
|
|
1087
|
-
|
|
1088
|
-
Adds global `tryTo` function in which all failed steps won't fail a test but will return true/false.
|
|
1089
|
-
|
|
1090
|
-
Enable this plugin in `codecept.conf.js` (enabled by default for new setups):
|
|
1091
|
-
|
|
1092
|
-
```js
|
|
1093
|
-
plugins: {
|
|
1094
|
-
tryTo: {
|
|
1095
|
-
enabled: true
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
```
|
|
1099
|
-
|
|
1100
|
-
Use it in your tests:
|
|
1101
|
-
|
|
1102
|
-
```js
|
|
1103
|
-
const result = await tryTo(() => I.see('Welcome'));
|
|
1104
|
-
|
|
1105
|
-
// if text "Welcome" is on page, result => true
|
|
1106
|
-
// if text "Welcome" is not on page, result => false
|
|
1107
|
-
```
|
|
1108
|
-
|
|
1109
|
-
Disables retryFailedStep plugin for steps inside a block;
|
|
1110
|
-
|
|
1111
|
-
Use this plugin if:
|
|
1112
|
-
|
|
1113
|
-
- you need to perform multiple assertions inside a test
|
|
1114
|
-
- there is A/B testing on a website you test
|
|
1115
|
-
- there is "Accept Cookie" banner which may surprisingly appear on a page.
|
|
1116
|
-
|
|
1117
|
-
#### Usage
|
|
1118
|
-
|
|
1119
|
-
#### Multiple Conditional Assertions
|
|
1120
|
-
|
|
1121
|
-
````js
|
|
1122
|
-
Add assert requires first:
|
|
1123
|
-
```js
|
|
1124
|
-
const assert = require('assert');
|
|
1125
|
-
````
|
|
1126
|
-
|
|
1127
|
-
Then use the assertion:
|
|
1128
|
-
const result1 = await tryTo(() => I.see('Hello, user'));
|
|
1129
|
-
const result2 = await tryTo(() => I.seeElement('.welcome'));
|
|
1130
|
-
assert.ok(result1 && result2, 'Assertions were not succesful');
|
|
1131
|
-
|
|
1132
|
-
##### Optional click
|
|
1133
|
-
|
|
1134
|
-
```js
|
|
1135
|
-
I.amOnPage('/');
|
|
1136
|
-
tryTo(() => I.click('Agree', '.cookies'));
|
|
1137
|
-
|
|
1138
|
-
#### Configuration
|
|
1139
|
-
|
|
1140
|
-
- `registerGlobal` - to register `tryTo` function globally, true by default
|
|
1141
|
-
|
|
1142
|
-
If `registerGlobal` is false you can use tryTo from the plugin:
|
|
1143
|
-
|
|
1144
|
-
```js
|
|
1145
|
-
const tryTo = codeceptjs.container.plugins('tryTo');
|
|
1146
|
-
```
|
|
1147
|
-
|
|
1148
|
-
### Parameters
|
|
1149
|
-
|
|
1150
|
-
- `config`
|
|
1151
|
-
|
|
1152
|
-
## wdio
|
|
1153
|
-
|
|
1154
|
-
Webdriverio services runner.
|
|
1155
|
-
|
|
1156
|
-
This plugin allows to run webdriverio services like:
|
|
1157
|
-
|
|
1158
|
-
- selenium-standalone
|
|
1159
|
-
- sauce
|
|
1160
|
-
- testingbot
|
|
1161
|
-
- browserstack
|
|
1162
|
-
- appium
|
|
1163
|
-
|
|
1164
|
-
A complete list of all available services can be found on [webdriverio website][17].
|
|
1165
|
-
|
|
1166
|
-
#### Setup
|
|
1167
|
-
|
|
1168
|
-
1. Install a webdriverio service
|
|
1169
|
-
2. Enable `wdio` plugin in config
|
|
1170
|
-
3. Add service name to `services` array inside wdio plugin config.
|
|
1171
|
-
|
|
1172
|
-
See examples below:
|
|
1173
|
-
|
|
1174
|
-
#### Selenium Standalone Service
|
|
1175
|
-
|
|
1176
|
-
Install `@wdio/selenium-standalone-service` package, as [described here][18].
|
|
1177
|
-
It is important to make sure it is compatible with current webdriverio version.
|
|
1178
|
-
|
|
1179
|
-
Enable `wdio` plugin in plugins list and add `selenium-standalone` service:
|
|
1180
|
-
|
|
1181
|
-
```js
|
|
1182
|
-
plugins: {
|
|
1183
|
-
wdio: {
|
|
1184
|
-
enabled: true,
|
|
1185
|
-
services: ['selenium-standalone']
|
|
1186
|
-
// additional config for service can be passed here
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
```
|
|
1190
|
-
|
|
1191
|
-
#### Sauce Service
|
|
1192
|
-
|
|
1193
|
-
Install `@wdio/sauce-service` package, as [described here][19].
|
|
1194
|
-
It is important to make sure it is compatible with current webdriverio version.
|
|
1195
|
-
|
|
1196
|
-
Enable `wdio` plugin in plugins list and add `sauce` service:
|
|
1197
|
-
|
|
1198
|
-
```js
|
|
1199
|
-
plugins: {
|
|
1200
|
-
wdio: {
|
|
1201
|
-
enabled: true,
|
|
1202
|
-
services: ['sauce'],
|
|
1203
|
-
user: ... ,// saucelabs username
|
|
1204
|
-
key: ... // saucelabs api key
|
|
1205
|
-
// additional config, from sauce service
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
```
|
|
1209
|
-
|
|
1210
|
-
* * *
|
|
1211
|
-
|
|
1212
|
-
In the same manner additional services from webdriverio can be installed, enabled, and configured.
|
|
1213
|
-
|
|
1214
|
-
#### Configuration
|
|
1215
|
-
|
|
1216
|
-
- `services` - list of enabled services
|
|
1217
|
-
- ... - additional configuration passed into services.
|
|
1218
|
-
|
|
1219
|
-
### Parameters
|
|
1220
|
-
|
|
1221
|
-
- `config`
|
|
1222
|
-
|
|
1223
|
-
[1]: https://codecept.io/locators#custom-locators
|
|
1224
|
-
|
|
1225
|
-
[2]: https://playwright.dev/docs/api/class-elementhandle
|
|
1226
|
-
|
|
1227
|
-
[3]: https://pptr.dev/#?product=Puppeteer&show=api-class-elementhandle
|
|
1228
|
-
|
|
1229
|
-
[4]: https://webdriver.io/docs/api
|
|
1230
|
-
|
|
1231
|
-
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
1232
|
-
|
|
1233
|
-
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
|
|
1234
|
-
|
|
1235
|
-
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
|
1236
|
-
|
|
1237
|
-
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined
|
|
1238
|
-
|
|
1239
|
-
[9]: /basics/#pause
|
|
1240
|
-
|
|
1241
|
-
[10]: https://aerokube.com/selenoid/
|
|
1242
|
-
|
|
1243
|
-
[11]: https://aerokube.com/cm/latest/
|
|
1244
|
-
|
|
1245
|
-
[12]: https://hub.docker.com/u/selenoid
|
|
1246
|
-
|
|
1247
|
-
[13]: https://aerokube.com/selenoid/latest/#_prepare_configuration
|
|
1248
|
-
|
|
1249
|
-
[14]: https://aerokube.com/selenoid/latest/#_option_2_start_selenoid_container
|
|
1250
|
-
|
|
1251
|
-
[15]: https://docs.docker.com/engine/reference/commandline/create/
|
|
1252
|
-
|
|
1253
|
-
[16]: https://codecept.io/img/codeceptjs-slideshow.gif
|
|
1254
|
-
|
|
1255
|
-
[17]: https://webdriver.io
|
|
1256
|
-
|
|
1257
|
-
[18]: https://webdriver.io/docs/selenium-standalone-service.html
|
|
1258
|
-
|
|
1259
|
-
[19]: https://webdriver.io/docs/sauce-service.html
|