codeceptjs 4.2.2 → 4.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +4 -4
  2. package/docs/ai.md +1 -1
  3. package/docs/alternative-browsers.md +4 -4
  4. package/docs/api.md +13 -13
  5. package/docs/assertions.md +6 -6
  6. package/docs/best.md +1 -1
  7. package/docs/bootstrap.md +1 -1
  8. package/docs/data.md +8 -8
  9. package/docs/element-selection.md +27 -4
  10. package/docs/helpers/ApiDataFactory.md +2 -2
  11. package/docs/helpers/Appium.md +56 -56
  12. package/docs/helpers/Decision.md +1 -1
  13. package/docs/helpers/Detox.md +1 -1
  14. package/docs/helpers/ExpectHelper.md +1 -1
  15. package/docs/helpers/FileSystem.md +1 -1
  16. package/docs/helpers/GraphQL.md +1 -1
  17. package/docs/helpers/GraphQLDataFactory.md +2 -2
  18. package/docs/helpers/JSONResponse.md +1 -1
  19. package/docs/helpers/Kitesurf.md +65 -65
  20. package/docs/helpers/Lightpanda.md +65 -65
  21. package/docs/helpers/MockRequest.md +1 -1
  22. package/docs/helpers/Moli.md +65 -65
  23. package/docs/helpers/Obscura.md +65 -65
  24. package/docs/helpers/Playwright.md +127 -127
  25. package/docs/helpers/Puppeteer.md +88 -88
  26. package/docs/helpers/REST.md +1 -1
  27. package/docs/helpers/WebDriver.md +87 -87
  28. package/docs/installation.md +1 -1
  29. package/docs/locators.md +5 -7
  30. package/docs/migration-4.md +7 -3
  31. package/docs/mobile.md +2 -2
  32. package/docs/parallel.md +1 -1
  33. package/docs/playwright.md +5 -5
  34. package/docs/plugins/aiTrace.md +1 -1
  35. package/docs/plugins/autoDelay.md +1 -1
  36. package/docs/plugins/customLocator.md +1 -1
  37. package/docs/plugins/customReporter.md +1 -1
  38. package/docs/plugins/junitReporter.md +2 -2
  39. package/docs/plugins/pageInfo.md +1 -1
  40. package/docs/plugins/pauseOnFail.md +1 -1
  41. package/docs/plugins/retryFailedStep.md +1 -1
  42. package/docs/plugins/screenshotOnFail.md +1 -1
  43. package/docs/plugins/stepTimeout.md +1 -1
  44. package/docs/plugins.md +10 -10
  45. package/docs/puppeteer.md +4 -4
  46. package/docs/retry.md +1 -1
  47. package/docs/timeouts.md +7 -7
  48. package/docs/webdriver.md +8 -8
  49. package/lib/actor.js +20 -2
  50. package/lib/aria.js +1 -0
  51. package/lib/codecept.js +1 -1
  52. package/lib/data/context.js +24 -0
  53. package/lib/element/WebElement.js +5 -5
  54. package/lib/helper/ApiDataFactory.js +1 -1
  55. package/lib/helper/Appium.js +2 -2
  56. package/lib/helper/GraphQLDataFactory.js +1 -1
  57. package/lib/helper/Playwright.js +22 -12
  58. package/lib/helper/Puppeteer.js +5 -11
  59. package/lib/mocha/asyncWrapper.js +14 -3
  60. package/lib/mocha/test.js +1 -0
  61. package/lib/plugin/auth.js +3 -0
  62. package/lib/plugin/junitReporter.js +21 -12
  63. package/lib/recorder.js +22 -3
  64. package/lib/step/base.js +8 -1
  65. package/lib/step/func.js +1 -1
  66. package/lib/step/helper.js +1 -1
  67. package/lib/step/record.js +22 -17
  68. package/lib/step/retry.js +13 -6
  69. package/lib/utils/typescript.js +86 -12
  70. package/lib/workers.js +15 -0
  71. package/package.json +2 -1
  72. package/typings/index.d.ts +12 -0
  73. package/typings/promiseBasedTypes.d.ts +696 -351
  74. package/typings/types.d.ts +485 -352
package/README.md CHANGED
@@ -45,9 +45,9 @@ CodeceptJS uses **Helper** modules to provide actions to `I` object. Currently,
45
45
  - [**Playwright**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/Playwright.md) - is a Node library to automate the Chromium, WebKit and Firefox browsers with a single API.
46
46
  - [**Puppeteer**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/Puppeteer.md) - uses Google Chrome's Puppeteer for fast headless testing.
47
47
  - [**WebDriver**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/WebDriver.md) - uses [webdriverio](http://webdriver.io/) to run tests via WebDriver or Devtools protocol.
48
- - [**Obscura**](https://codecept.io/helpers/Obscura) - drives the lightweight Obscura browser through Chrome DevTools Protocol. See [Alternative Browser Engines](https://codecept.io/alternative-browsers).
49
- - [**Lightpanda**](https://codecept.io/helpers/Lightpanda) - drives the Lightpanda headless browser through Chrome DevTools Protocol. See [Alternative Browser Engines](https://codecept.io/alternative-browsers).
50
- - [**Moli**](https://codecept.io/helpers/Moli) - drives the Moli headless browser through Chrome DevTools Protocol. See [Alternative Browser Engines](https://codecept.io/alternative-browsers).
48
+ - [**Obscura**](https://codecept.io/helpers/obscura) - drives the lightweight Obscura browser through Chrome DevTools Protocol. See [Alternative Browser Engines](https://codecept.io/alternative-browsers).
49
+ - [**Lightpanda**](https://codecept.io/helpers/lightpanda) - drives the Lightpanda headless browser through Chrome DevTools Protocol. See [Alternative Browser Engines](https://codecept.io/alternative-browsers).
50
+ - [**Moli**](https://codecept.io/helpers/moli) - drives the Moli headless browser through Chrome DevTools Protocol. See [Alternative Browser Engines](https://codecept.io/alternative-browsers).
51
51
  - [**Appium**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/Appium.md) - for **mobile testing** with Appium
52
52
  - [**Detox**](https://github.com/codeceptjs/CodeceptJS/blob/master/docs/helpers/Detox.md) - This is a wrapper on top of Detox library, aimed to unify testing experience for CodeceptJS framework. Detox provides a grey box testing for mobile applications, playing especially well for React Native apps.
53
53
 
@@ -208,7 +208,7 @@ Feature('CodeceptJS Demonstration')
208
208
  Scenario('test page title', async ({ I }) => {
209
209
  I.amOnPage('http://simple-form-bootstrap.plataformatec.com.br/documentation')
210
210
  const title = await I.grabTitle()
211
- I.expectEqual(title, 'Example application with SimpleForm and Twitter Bootstrap') // Avaiable with Expect helper. -> https://codecept.io/helpers/Expect/
211
+ I.expectEqual(title, 'Example application with SimpleForm and Twitter Bootstrap') // Avaiable with Expect helper. -> https://codecept.io/helpers/expect/
212
212
  })
213
213
  ```
214
214
 
package/docs/ai.md CHANGED
@@ -341,7 +341,7 @@ npx codeceptjs run --ai
341
341
 
342
342
  ## Decision Assertions
343
343
 
344
- Some checks are hard to express with locators: "checkout form has all required fields", "success message is shown". The [Decision helper](/helpers/Decision) asserts them in plain language:
344
+ Some checks are hard to express with locators: "checkout form has all required fields", "success message is shown". The [Decision helper](/helpers/decision) asserts them in plain language:
345
345
 
346
346
  ```js
347
347
  I.decide([
@@ -82,7 +82,7 @@ Obscura: {
82
82
  }
83
83
  ```
84
84
 
85
- All options: [Obscura helper reference](/helpers/Obscura).
85
+ All options: [Obscura helper reference](/helpers/obscura).
86
86
 
87
87
  ## Lightpanda
88
88
 
@@ -141,7 +141,7 @@ Lightpanda: {
141
141
  }
142
142
  ```
143
143
 
144
- All options: [Lightpanda helper reference](/helpers/Lightpanda).
144
+ All options: [Lightpanda helper reference](/helpers/lightpanda).
145
145
 
146
146
  ## Moli
147
147
 
@@ -196,7 +196,7 @@ Moli: {
196
196
  }
197
197
  ```
198
198
 
199
- All options: [Moli helper reference](/helpers/Moli).
199
+ All options: [Moli helper reference](/helpers/moli).
200
200
 
201
201
  ## Kitesurf
202
202
 
@@ -237,4 +237,4 @@ Every worker opens its own cloud session:
237
237
  npx codeceptjs run-workers 16
238
238
  ```
239
239
 
240
- All options: [Kitesurf helper reference](/helpers/Kitesurf).
240
+ All options: [Kitesurf helper reference](/helpers/kitesurf).
package/docs/api.md CHANGED
@@ -82,9 +82,9 @@ Ensure that inside `codecept.conf.js` in helpers section `REST` or `GraphQL` hel
82
82
  Originally, REST and GraphQL helpers were not designed for API testing.
83
83
  They were used to perform API requests for browser tests. As so, they lack assertion methods to API responses.
84
84
 
85
- [`JSONResponse`](/helpers/JSONResponse/) helper adds response assertions.
85
+ [`JSONResponse`](/helpers/json-response/) helper adds response assertions.
86
86
 
87
- > 💡 In CodeceptJS assertions start with `see` prefix. Learn more about assertions by [opening reference for JSONResponse](/helpers/JSONResponse/) helper.
87
+ > 💡 In CodeceptJS assertions start with `see` prefix. Learn more about assertions by [opening reference for JSONResponse](/helpers/json-response/) helper.
88
88
 
89
89
  Generate TypeScript definitions to get auto-completions for JSONResponse:
90
90
 
@@ -98,7 +98,7 @@ After helpers were configured and typings were generated, you can start writing
98
98
 
99
99
  ## Requests
100
100
 
101
- [REST](/helpers/REST/) or [GraphQL](/helpers/GraphQL/) helpers implement methods for making API requests.
101
+ [REST](/helpers/rest/) or [GraphQL](/helpers/graph-ql/) helpers implement methods for making API requests.
102
102
  Both helpers send requests via HTTP protocol from CodeceptJS process.
103
103
  For most cases, you will need to have authentication. It can be passed via headers, which can be added to helper's configuration in `codecept.conf.js`.
104
104
 
@@ -143,15 +143,15 @@ export const config = {
143
143
 
144
144
  REST helper can send GET/POST/PATCH/etc requests to REST API endpoint:
145
145
 
146
- * [`I.sendGetRequest()`](/helpers/REST#sendGetRequest)
147
- * [`I.sendPostRequest()`](/helpers/REST#sendPostRequest)
148
- * [`I.sendPutRequest()`](/helpers/REST#sendPutRequest)
149
- * [`I.sendPatchRequest()`](/helpers/REST#sendPatchRequest)
150
- * [`I.sendDeleteRequest()`](/helpers/REST#sendDeleteRequest)
151
- * [`I.sendDeleteRequestWithPayload()`](/helpers/REST#sendDeleteRequestWithPayload)
146
+ * [`I.sendGetRequest()`](/helpers/rest#sendgetrequest)
147
+ * [`I.sendPostRequest()`](/helpers/rest#sendpostrequest)
148
+ * [`I.sendPutRequest()`](/helpers/rest#sendputrequest)
149
+ * [`I.sendPatchRequest()`](/helpers/rest#sendpatchrequest)
150
+ * [`I.sendDeleteRequest()`](/helpers/rest#senddeleterequest)
151
+ * [`I.sendDeleteRequestWithPayload()`](/helpers/rest#senddeleterequestwithpayload)
152
152
  * ...
153
153
 
154
- Authentication headers can be set in [helper's config](https://codecept.io/helpers/REST/#configuration) or per test with headers or special methods like `I.amBearerAuthenticated`.
154
+ Authentication headers can be set in [helper's config](https://codecept.io/helpers/rest/#configuration) or per test with headers or special methods like `I.amBearerAuthenticated`.
155
155
 
156
156
  Example:
157
157
 
@@ -209,8 +209,8 @@ Scenario('get user by query', ({ I }) => {
209
209
 
210
210
  GraphQL helper has two methods available:
211
211
 
212
- * [`I.sendQuery()`](/helpers/GraphQL#sendQuery)
213
- * [`I.sendMutation()`](/helpers/GraphQL#sendMutation)
212
+ * [`I.sendQuery()`](/helpers/graph-ql#sendquery)
213
+ * [`I.sendMutation()`](/helpers/graph-ql#sendmutation)
214
214
 
215
215
  ## Assertions
216
216
 
@@ -257,7 +257,7 @@ I.seeResponseCodeIsServerError();
257
257
 
258
258
  ### Structure
259
259
 
260
- The most basic thing to check in response is existence of keys in JSON object. Use [`I.seeResponseContainsKeys()`](/helpers/JSONResponse#seeResponseContainsKeys) method for it:
260
+ The most basic thing to check in response is existence of keys in JSON object. Use [`I.seeResponseContainsKeys()`](/helpers/json-response#seeresponsecontainskeys) method for it:
261
261
 
262
262
  ```js
263
263
  // response is { "name": "joe", "email": "joe@joe.com" }
@@ -10,7 +10,7 @@ CodeceptJS ships with **browser assertions built into the `I` object** — `I.se
10
10
  When the built-ins are not enough — sort order, business math, JSON shapes, domain rules — you have three ways to assert, in order of preference:
11
11
 
12
12
  1. **Reusable custom assertions** in a helper: `I.seeTableIsOrdered('Price', 'desc')`
13
- 2. **Quick assertions with [ExpectHelper](/helpers/ExpectHelper)** on grabbed data: `I.expectDeepEqualExcluding(order, expected, ['id'])`
13
+ 2. **Quick assertions with [ExpectHelper](/helpers/expect-helper)** on grabbed data: `I.expectDeepEqualExcluding(order, expected, ['id'])`
14
14
  3. **Bring your own library** — `chai`, `jest`, or Node's `assert`
15
15
 
16
16
  This page also covers [element assertions via WebElement](/WebElement), [soft assertions](#soft-assertions) for running many checks in one scenario, and [masking secrets](#masking-secrets) in assertion logs.
@@ -84,7 +84,7 @@ Four options, from least setup to most:
84
84
 
85
85
  ### Quick Assertions with Expect Helper
86
86
 
87
- [`ExpectHelper`](/helpers/ExpectHelper) exposes chai's assertions as methods on the `I` object. Use it for one-off checks on data you have already grabbed — no helper class, no boilerplate.
87
+ [`ExpectHelper`](/helpers/expect-helper) exposes chai's assertions as methods on the `I` object. Use it for one-off checks on data you have already grabbed — no helper class, no boilerplate.
88
88
 
89
89
  **Install separately:**
90
90
 
@@ -145,7 +145,7 @@ Common methods:
145
145
  | `expectHasProperty` / `expectEmpty` | Object shape |
146
146
  | `expectJsonSchema` / `expectJsonSchemaUsingAJV` | Full schema validation |
147
147
 
148
- ExpectHelper calls appear in the step log next to browser steps, so failures read in order with the rest of the scenario. See the [full reference](/helpers/ExpectHelper).
148
+ ExpectHelper calls appear in the step log next to browser steps, so failures read in order with the rest of the scenario. See the [full reference](/helpers/expect-helper).
149
149
 
150
150
  ### Built-in Assertion Library
151
151
 
@@ -399,7 +399,7 @@ expected soft assertions '[expected web application to include "You must accept
399
399
 
400
400
  ## Decision Assertions
401
401
 
402
- Some checks are hard to express with locators: "checkout form has all required fields", "success message is shown", "sidebar is shown". The [Decision helper](/helpers/Decision) asserts such statements in plain language with a decision model.
402
+ Some checks are hard to express with locators: "checkout form has all required fields", "success message is shown", "sidebar is shown". The [Decision helper](/helpers/decision) asserts such statements in plain language with a decision model.
403
403
 
404
404
  A [decision model](https://openrouter.ai/models?output_modalities=decisions), like [Jev](https://openrouter.ai/typesafe/jev-1.13), does not generate text. It reads the page and returns the probability that a statement is true. This makes it a good fit for assertions:
405
405
 
@@ -466,7 +466,7 @@ helpers: {
466
466
  }
467
467
  ```
468
468
 
469
- A failed decision is not retried by the [retryFailedStep](/plugins/retryFailedStep) plugin: asking again would cost another request and return the same answer. Only connection errors and timeouts are retried.
469
+ A failed decision is not retried by the [retryFailedStep](/plugins/retry-failed-step) plugin: asking again would cost another request and return the same answer. Only connection errors and timeouts are retried.
470
470
 
471
471
  Use decision assertions for what a page means, and built-in assertions for exact values. `I.see('Total: $42.00')` is still the right check for a price.
472
472
 
@@ -479,7 +479,7 @@ Use decision assertions for what a page means, and built-in assertions for exact
479
479
  | A form field's current value | `I.seeInField` / `I.seeCheckboxIsChecked` |
480
480
  | URL or page title | `I.seeInCurrentUrl` / `I.seeInTitle` |
481
481
  | A count of matching elements | `I.seeNumberOfElements` |
482
- | Business logic / JSON shape on grabbed data | [ExpectHelper](/helpers/ExpectHelper) — `expectEqual`, `expectDeepEqualExcluding`, `expectJsonSchema` |
482
+ | Business logic / JSON shape on grabbed data | [ExpectHelper](/helpers/expect-helper) — `expectEqual`, `expectDeepEqualExcluding`, `expectJsonSchema` |
483
483
  | A lightweight, dependency-free assertion in a scenario | `equals`, `includes`, `empty`, `truth` from `codeceptjs/assertions` |
484
484
  | Per-element state in a loop | `grabWebElements` + [WebElement API](/WebElement) |
485
485
  | A matcher the above do not cover | `grab*` + `chai` / `jest` / `node:assert` |
package/docs/best.md CHANGED
@@ -38,7 +38,7 @@ To write simpler and effective tests we encourage to use short cuts.
38
38
  Make test be focused on one feature and try to simplify everything that is not related directly to test.
39
39
 
40
40
  * If data is required for a test, try to create that data via API. See how to do it in [Data Management](/data) chapter.
41
- * If user login is required, use [autoLogin plugin](/plugins#autoLogin) instead of putting login steps inside a test.
41
+ * If user login is required, use [auth plugin](/plugins#auth) instead of putting login steps inside a test.
42
42
  * Break a long test into few. Long test can be fragile and complicated to follow and update.
43
43
  * Use [custom steps and page objects](/pageobjects) to hide steps which are not relevant to current test.
44
44
 
package/docs/bootstrap.md CHANGED
@@ -55,7 +55,7 @@ First, `bootstrapAll` is called. Then two `bootstrap` runs in each of workers. T
55
55
 
56
56
  The `bootstrapAll` and `teardownAll` hooks are preferred to use for setting up common logic of tested project: to start the application server or database or to start webdriver's grid.
57
57
 
58
- The `bootstrap` and `teardown` hooks are used for setting up each testing browser: to create unique [cloud testing server](/helpers/WebDriver#cloud-providers) connection or to create specific browser-related test data in database (like users with names with browsername in it).
58
+ The `bootstrap` and `teardown` hooks are used for setting up each testing browser: to create unique [cloud testing server](/helpers/web-driver#cloud-providers) connection or to create specific browser-related test data in database (like users with names with browsername in it).
59
59
 
60
60
  ### Example: BootstrapAll & TeardownAll Inside Config
61
61
 
package/docs/data.md CHANGED
@@ -109,7 +109,7 @@ Data Objects can use any helper methods available via `I`, including `sendGetReq
109
109
 
110
110
  ## REST
111
111
 
112
- [REST helper](https://codecept.io/helpers/REST/) allows sending raw HTTP requests to application.
112
+ [REST helper](https://codecept.io/helpers/rest/) allows sending raw HTTP requests to application.
113
113
  This is a tool to make shortcuts and create your data pragmatically via API. However, it doesn't provide tools for testing APIs, so it should be paired with Playwright or WebDriver helper for browser testing.
114
114
 
115
115
  Enable REST helper in the config. It is recommended to set `endpoint`, a base URL for all API requests. If you need some authorization you can optionally set default headers too.
@@ -175,11 +175,11 @@ This can also be used to emulate Ajax requests:
175
175
  I.sendPostRequest('/update-status', {}, { http_x_requested_with: 'xmlhttprequest' })
176
176
  ```
177
177
 
178
- > See complete reference on [REST](https://codecept.io/helpers/REST) helper
178
+ > See complete reference on [REST](https://codecept.io/helpers/rest) helper
179
179
 
180
180
  ## GraphQL
181
181
 
182
- [GraphQL helper](https://codecept.io/helpers/GraphQL/) allows sending GraphQL queries and mutations to application, over Http.
182
+ [GraphQL helper](https://codecept.io/helpers/graph-ql/) allows sending GraphQL queries and mutations to application, over Http.
183
183
 
184
184
  This tool allows you to create shortcuts and manage your data pragmatically via a GraphQL endpoint. However, it does not include tools for testing the endpoint, so it should be used in conjunction with WebDriver helpers for browser testing.
185
185
 
@@ -243,14 +243,14 @@ After(({ I }) => {
243
243
  })
244
244
  ```
245
245
 
246
- > See complete reference on [GraphQL](https://codecept.io/helpers/GraphQL) helper
246
+ > See complete reference on [GraphQL](https://codecept.io/helpers/graph-ql) helper
247
247
 
248
248
  ## Data Generation with Factories
249
249
 
250
250
  This concept is extended by:
251
251
 
252
- - [ApiDataFactory](https://codecept.io/helpers/ApiDataFactory/) helper, and,
253
- - [GraphQLDataFactory](https://codecept.io/helpers/GraphQLDataFactory/) helper.
252
+ - [ApiDataFactory](https://codecept.io/helpers/api-data-factory/) helper, and,
253
+ - [GraphQLDataFactory](https://codecept.io/helpers/graph-ql-data-factory/) helper.
254
254
 
255
255
  These helpers build data according to defined rules and use REST API or GraphQL mutations to store them and automatically clean them up after a test.
256
256
 
@@ -320,7 +320,7 @@ At the end of a test ApiDataFactory will clean up created record for you. This i
320
320
  ids from crated records and running `DELETE /api/users/{id}` requests at the end of a test.
321
321
  This rules can be customized in helper configuration.
322
322
 
323
- > See complete reference on [ApiDataFactory](https://codecept.io/helpers/ApiDataFactory) helper
323
+ > See complete reference on [ApiDataFactory](https://codecept.io/helpers/api-data-factory) helper
324
324
 
325
325
  ### GraphQL Data Factory
326
326
 
@@ -383,7 +383,7 @@ data from crated records, creating deletion mutation objects by passing the data
383
383
  This behavior is according the `revert` function be customized in helper configuration.
384
384
  The revert function returns an object, that contains the query for deletion, and the variables object to go along with it.
385
385
 
386
- > See complete reference on [GraphQLDataFactory](https://codecept.io/helpers/GraphQLDataFactory) helper
386
+ > See complete reference on [GraphQLDataFactory](https://codecept.io/helpers/graph-ql-data-factory) helper
387
387
 
388
388
  ## Requests Using Browser Session
389
389
 
@@ -11,7 +11,28 @@ But what happens when it's not?
11
11
 
12
12
  ## Picking a Specific Element
13
13
 
14
- Say you have a list of items and you want to click the second one. You could write a more specific CSS selector, but sometimes the simplest approach is to tell CodeceptJS which element you want by position:
14
+ Say you have a list of items and you want to click the second one. You could write a more specific CSS selector, but sometimes the simplest approach is to tell CodeceptJS which element you want by position. Chain `first()`, `last()` or `at()` to the action:
15
+
16
+ ```js
17
+ I.click('a').first()
18
+
19
+ // click the last link
20
+ I.click('a').last()
21
+
22
+ // click the 2nd link
23
+ I.click('a').at(2)
24
+
25
+ // fill the second-to-last matching input
26
+ I.fillField('.email-input', 'test@example.com').at(-2)
27
+ ```
28
+
29
+ Chain the selection directly to the action, in the same expression. `await I.click('a').last()` works too. Calling it after the step has run throws an error.
30
+
31
+ These methods exist on helper actions only. They are not available on custom steps and page object methods.
32
+
33
+ They differ from `locate('a').first()`, which builds a position into the locator. A chained selection picks from whatever the action matched, including fuzzy matches like `I.click('Submit').last()`.
34
+
35
+ The same selection is available as a step option:
15
36
 
16
37
  ```js
17
38
  import step from 'codeceptjs/steps'
@@ -108,10 +129,12 @@ It works the other way too. If your helper has `strict: true` globally but you n
108
129
  I.click('a', step.opts({ exact: false }))
109
130
  ```
110
131
 
111
- And when you know there are multiple matches and want a specific one, `elementIndex` also overrides the strict check — no error is thrown because you've explicitly chosen which element to use:
132
+ And when you know there are multiple matches and want a specific one, `first()`, `last()`, `at()` and `elementIndex` override the strict check — no error is thrown because you've explicitly chosen which element to use:
112
133
 
113
134
  ```js
114
- // strict: true in config, but this works without error
135
+ // strict: true in config, but these work without error
136
+ I.click('a').first()
137
+ I.click('a').at(2)
115
138
  I.click('a', step.opts({ elementIndex: 2 }))
116
139
  ```
117
140
 
@@ -120,6 +143,6 @@ I.click('a', step.opts({ elementIndex: 2 }))
120
143
  | Situation | Approach |
121
144
  |-----------|----------|
122
145
  | You want to catch ambiguous locators early | Enable `strict: true` in helper config |
123
- | You need a specific element from a known list | Use `step.opts({ elementIndex: N })` |
146
+ | You need a specific element from a known list | Chain `.first()`, `.last()` or `.at(N)` to the action |
124
147
  | You want to iterate over all matching elements | Use [`eachElement`](/els) from the `els` module |
125
148
  | You need full control over element inspection | Use [`grabWebElements`](/WebElement) to get all matches |
@@ -1,5 +1,5 @@
1
1
  ---
2
- permalink: /helpers/ApiDataFactory
2
+ permalink: /helpers/api-data-factory
3
3
  editLink: false
4
4
  sidebar: auto
5
5
  title: ApiDataFactory
@@ -260,7 +260,7 @@ Can be replaced from a custom helper.
260
260
 
261
261
  [2]: https://www.npmjs.com/package/faker
262
262
 
263
- [3]: http://codecept.io/helpers/REST/
263
+ [3]: http://codecept.io/helpers/rest/
264
264
 
265
265
  [4]: https://github.com/axios/axios#request-config
266
266