You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Brings in the unified `on=` trigger framework (pluginParser.js),
new screenshot/browser/pause plugins, and 4.x docs.
Resolves aiTrace.js by combining the trace.js helpers (captureSnapshot,
pickActingHelper, traceDirFor, artifactLinks) with 4.x's parsePluginArgs/
resolveTrigger entrypoint.
Copy file name to clipboardExpand all lines: docs/ai.md
+8-130Lines changed: 8 additions & 130 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,9 +22,7 @@ So, instead of asking "write me a test" it can ask "write a test for **this** pa
22
22
CodeceptJS AI can do the following:
23
23
24
24
- 🏋️♀️ **assist writing tests** in `pause()` or interactive shell mode
25
-
- 📃 **generate page objects** in `pause()` or interactive shell mode
26
25
- 🚑 **self-heal failing tests** (can be used on CI)
27
-
- 💬 send arbitrary prompts to AI provider from any tested page attaching its HTML contents
28
26
29
27

30
28
@@ -60,7 +58,7 @@ import { openai } from '@ai-sdk/openai'
60
58
exportdefault {
61
59
// ... other config
62
60
ai: {
63
-
model:openai('gpt-4o-mini'),
61
+
model:openai('gpt-5'),
64
62
},
65
63
}
66
64
```
@@ -94,7 +92,7 @@ import { openai } from '@ai-sdk/openai'
94
92
95
93
exportdefault {
96
94
ai: {
97
-
model:openai('gpt-4o-mini'),
95
+
model:openai('gpt-5'),
98
96
// or use gpt-4o, gpt-3.5-turbo, etc.
99
97
},
100
98
}
@@ -121,8 +119,8 @@ import { anthropic } from '@ai-sdk/anthropic'
121
119
122
120
exportdefault {
123
121
ai: {
124
-
model:anthropic('claude-3-5-sonnet-20241022'),
125
-
// or use claude-3-opus-20240229, claude-3-haiku-20240307, etc.
122
+
model:anthropic('claude-sonnet-4-6'),
123
+
// or use claude-opus-4-7, claude-haiku-4-5, etc.
126
124
},
127
125
}
128
126
```
@@ -232,10 +230,9 @@ npx codeceptjs generate:heal
232
230
Heal recipes should be included into `codecept.conf.js` or `codecept.conf.ts` config file:
233
231
234
232
```js
233
+
import'./heal.js'
235
234
236
-
require('./heal')
237
-
238
-
exports.config= {
235
+
exportconstconfig= {
239
236
// ... your codeceptjs config
240
237
```
241
238
@@ -385,125 +382,6 @@ Run tests with both AI and analyze enabled:
385
382
npx codeceptjs run --ai
386
383
```
387
384
388
-
## Arbitrary Prompts
389
-
390
-
What if you want to take AI on the journey of test automation and ask it questions while browsing pages?
391
-
392
-
This is possible with the new `AI` helper. Enable it in your config file in `helpers` section:
393
-
394
-
```js
395
-
// inside codecept.conf
396
-
helpers: {
397
-
// Playwright, Puppeteer, or WebDrver helper should be enabled too
398
-
Playwright: {
399
-
},
400
-
401
-
AI: {}
402
-
}
403
-
```
404
-
405
-
AI helper will be automatically attached to Playwright, WebDriver, or another web helper you use. It includes the following methods:
406
-
407
-
- `askGptOnPage` - sends GPT prompt attaching the HTML of the page. Large pages will be split into chunks, according to `chunkSize` config. You will receive responses for all chunks.
408
-
- `askGptOnPageFragment` - sends GPT prompt attaching the HTML of the specific element. This method is recommended over `askGptOnPage` as you can reduce the amount of data to be processed.
409
-
- `askGptGeneralPrompt` - sends GPT prompt without HTML.
410
-
- `askForPageObject` - creates PageObject for you, explained in next section.
411
-
412
-
`askGpt` methods won't remove non-interactive elements, so it is recommended to manually control the size of the sent HTML.
413
-
414
-
Here are some good use cases for this helper:
415
-
416
-
- get page summaries
417
-
- inside pause mode navigate through your application and ask to document pages
418
-
- etc...
419
-
420
-
```js
421
-
// use it inside test or inside interactive pause
422
-
// pretend you are technical writer asking for documentation
423
-
constpageDoc=awaitI.askGptOnPageFragment('Act as technical writer, describe what is this page for', '#container')
424
-
```
425
-
426
-
As of now, those use cases do not apply to test automation but maybe you can apply them to your testing setup.
427
-
428
-
## Generate PageObjects
429
-
430
-
Last but not the least. AI helper can be used to quickly prototype PageObjects on pages browsed within interactive session.
431
-
432
-

433
-
434
-
Enable AI helper as explained in previous section and launch shell:
435
-
436
-
```
437
-
npx codeceptjs shell --ai
438
-
```
439
-
440
-
Also this is availble from `pause()` if AI helper is enabled,
441
-
442
-
Ensure that browser is started in window mode, then browse the web pages on your site.
443
-
On a page you want to create PageObject execute `askForPageObject()` command. The only required parameter is the name of a page:
444
-
445
-
```js
446
-
I.askForPageObject('login')
447
-
```
448
-
449
-
This command sends request to AI provider should create valid CodeceptJS PageObject.
450
-
Run it few times or switch AI provider if response is not satisfactory to you.
451
-
452
-
> You can change the style of PageObject and locator preferences by adjusting prompt in a config file
453
-
454
-
When completed successfully, page object is saved to **output** directory and loaded into the shell as `page` variable so locators and methods can be checked on the fly.
455
-
456
-
If page object has `signInButton` locator you can quickly check it by typing:
457
-
458
-
```js
459
-
I.click(page.signInButton)
460
-
```
461
-
462
-
If page object has `clickForgotPassword` method you can execute it as:
463
-
464
-
```js
465
-
=>page.clickForgotPassword()
466
-
```
467
-
468
-
Here is an example of a session:
469
-
470
-
```shell
471
-
Page object for login is saved to .../output/loginPage-1718579784751.js
472
-
Page object registered forthis session as `page` variable
473
-
Use `=>page.methodName()`in shell to run methods of page object
474
-
Use `click(page.locatorName)` to check locators of page object
475
-
476
-
I.=>page.clickSignUp()
477
-
I.click(page.signUpLink)
478
-
I.=>page.enterPassword('asdasd')
479
-
I.=>page.clickSignIn()
480
-
```
481
-
482
-
You can improve prompt by passing custom request as a second parameter:
To generate page object for the part of a page, pass in root locator as third parameter.
489
-
490
-
```js
491
-
I.askForPageObject('login', '', '#auth')
492
-
```
493
-
494
-
In this case, all generated locators, will use `#auth` as their root element.
495
-
496
-
Don't aim for perfect PageObjects but find a good enough one, which you can use for writing your tests.
497
-
All created page objects are considered temporary, that's why saved to `output` directory.
498
-
499
-
Rename created PageObject to remove timestamp and move it from `output` to `pages` folder and include it into codecept.conf file:
500
-
501
-
```js
502
-
include: {
503
-
loginPage:"./pages/loginPage.js",
504
-
// ...
505
-
```
506
-
507
385
## Advanced Configuration
508
386
509
387
AI prompts and HTML compression can be configured inside `ai` section of `codecept.conf` file:
@@ -612,8 +490,8 @@ It is recommended to try HTML processing on one of your web pages before launchi
612
490
To do that open the common page of your application and using DevTools copy the outerHTML of `<html>` element. Don't use `Page Source` for that, as it may not include dynamically added HTML elements. Save this HTML into a file and create a NodeJS script:
0 commit comments