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
Copy file name to clipboardExpand all lines: docs/ai.md
-121Lines changed: 0 additions & 121 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
@@ -385,125 +383,6 @@ Run tests with both AI and analyze enabled:
385
383
npx codeceptjs run --ai
386
384
```
387
385
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:
0 commit comments