Skip to content

Commit f572b8e

Browse files
author
DavertMik
committed
update docs
1 parent 6d8c234 commit f572b8e

8 files changed

Lines changed: 394 additions & 295 deletions

File tree

docs/ai.md

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ So, instead of asking "write me a test" it can ask "write a test for **this** pa
2222
CodeceptJS AI can do the following:
2323

2424
- 🏋️‍♀️ **assist writing tests** in `pause()` or interactive shell mode
25-
- 📃 **generate page objects** in `pause()` or interactive shell mode
2625
- 🚑 **self-heal failing tests** (can be used on CI)
27-
- 💬 send arbitrary prompts to AI provider from any tested page attaching its HTML contents
2826

2927
![](/img/fill_form.gif)
3028

@@ -385,125 +383,6 @@ Run tests with both AI and analyze enabled:
385383
npx codeceptjs run --ai
386384
```
387385
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-
const pageDoc = await I.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-
![](/img/ai_page_object.png)
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 for this 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:
483-
484-
```js
485-
I.askForPageObject('login', 'implement signIn(username, password) method')
486-
```
487-
488-
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-
507386
## Advanced Configuration
508387
509388
AI prompts and HTML compression can be configured inside `ai` section of `codecept.conf` file:

0 commit comments

Comments
 (0)