Skip to content

Commit

Permalink
DOC: Autogenerate and update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jan 4, 2025
1 parent f669be0 commit ff1bd58
Show file tree
Hide file tree
Showing 16 changed files with 3,440 additions and 3,113 deletions.
30 changes: 16 additions & 14 deletions docs/helpers/AI.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ Use it only in development mode. It is recommended to run it only inside pause()

This helper should be configured in codecept.conf.{js|ts}

- `chunkSize`: - The maximum number of characters to send to the AI API at once. We split HTML fragments by 8000 chars to not exceed token limit. Increase this value if you use GPT-4.
* `chunkSize`: - The maximum number of characters to send to the AI API at once. We split HTML fragments by 8000 chars to not exceed token limit. Increase this value if you use GPT-4.

### Parameters

- `config`  
* `config`  

### askForPageObject

Expand All @@ -37,22 +37,22 @@ Prompt can be customized in a global config file.

```js
// create page object for whole page
I.askForPageObject('home')
I.askForPageObject('home');

// create page object with extra prompt
I.askForPageObject('home', 'implement signIn(username, password) method')
I.askForPageObject('home', 'implement signIn(username, password) method');

// create page object for a specific element
I.askForPageObject('home', null, '.detail')
I.askForPageObject('home', null, '.detail');
```

Asks for a page object based on the provided page name, locator, and extra prompt.

#### Parameters

- `pageName` **[string][1]** The name of the page to retrieve the object for.
- `extraPrompt` **([string][1] | null)** An optional extra prompt for additional context or information.
- `locator` **([string][1] | null)** An optional locator to find a specific element on the page.
* `pageName` **[string][1]** The name of the page to retrieve the object for.
* `extraPrompt` **([string][1] | null)** An optional extra prompt for additional context or information.
* `locator` **([string][1] | null)** An optional locator to find a specific element on the page.

Returns **[Promise][2]<[Object][3]>** A promise that resolves to the requested page object.

Expand All @@ -62,7 +62,7 @@ Send a general request to AI and return response.

#### Parameters

- `prompt` **[string][1]**&#x20;
* `prompt` **[string][1]**&#x20;

Returns **[Promise][2]<[string][1]>** A Promise that resolves to the generated response from the GPT model.

Expand All @@ -71,12 +71,12 @@ Returns **[Promise][2]<[string][1]>** A Promise that resolves to the generated r
Asks the AI GPT language model a question based on the provided prompt within the context of the current page's HTML.

```js
I.askGptOnPage('what does this page do?')
I.askGptOnPage('what does this page do?');
```

#### Parameters

- `prompt` **[string][1]** The question or prompt to ask the GPT model.
* `prompt` **[string][1]** The question or prompt to ask the GPT model.

Returns **[Promise][2]<[string][1]>** A Promise that resolves to the generated responses from the GPT model, joined by newlines.

Expand All @@ -85,16 +85,18 @@ Returns **[Promise][2]<[string][1]>** A Promise that resolves to the generated r
Asks the AI a question based on the provided prompt within the context of a specific HTML fragment on the current page.

```js
I.askGptOnPageFragment('describe features of this screen', '.screen')
I.askGptOnPageFragment('describe features of this screen', '.screen');
```

#### Parameters

- `prompt` **[string][1]** The question or prompt to ask the GPT-3.5 model.
- `locator` **[string][1]** The locator or selector used to identify the HTML fragment on the page.
* `prompt` **[string][1]** The question or prompt to ask the GPT-3.5 model.
* `locator` **[string][1]** The locator or selector used to identify the HTML fragment on the page.

Returns **[Promise][2]<[string][1]>** A Promise that resolves to the generated response from the GPT model.

[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise

[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
104 changes: 54 additions & 50 deletions docs/helpers/ApiDataFactory.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Most of web application have API, and it can be used to create and delete test r
By combining REST API with Factories you can easily create records for tests:

```js
I.have('user', { login: 'davert', email: '[email protected]' })
let id = await I.have('post', { title: 'My first post' })
I.haveMultiple('comment', 3, { post_id: id })
I.have('user', { login: 'davert', email: '[email protected]' });
let id = await I.have('post', { title: 'My first post'});
I.haveMultiple('comment', 3, {post_id: id});
```

To make this work you need
Expand All @@ -53,14 +53,14 @@ See the example for Posts factories:
```js
// tests/factories/posts.js

const { Factory } = require('rosie')
const { faker } = require('@faker-js/faker')
const { Factory } = require('rosie');
const { faker } = require('@faker-js/faker');

module.exports = new Factory()
// no need to set id, it will be set by REST API
.attr('author', () => faker.person.findName())
.attr('title', () => faker.lorem.sentence())
.attr('body', () => faker.lorem.paragraph())
// no need to set id, it will be set by REST API
.attr('author', () => faker.person.findName())
.attr('title', () => faker.lorem.sentence())
.attr('body', () => faker.lorem.paragraph());
```

For more options see [rosie documentation][1].
Expand All @@ -71,12 +71,12 @@ Then configure ApiDataHelper to match factories and REST API:

ApiDataFactory has following config options:

- `endpoint`: base URL for the API to send requests to.
- `cleanup` (default: true): should inserted records be deleted up after tests
- `factories`: list of defined factories
- `returnId` (default: false): return id instead of a complete response when creating items.
- `headers`: list of headers
- `REST`: configuration for REST requests
* `endpoint`: base URL for the API to send requests to.
* `cleanup` (default: true): should inserted records be deleted up after tests
* `factories`: list of defined factories
* `returnId` (default: false): return id instead of a complete response when creating items.
* `headers`: list of headers
* `REST`: configuration for REST requests

See the example:

Expand Down Expand Up @@ -121,19 +121,19 @@ For instance, to set timeout you should add:

By default to create a record ApiDataFactory will use endpoint and plural factory name:

- create: `POST {endpoint}/{resource} data`
- delete: `DELETE {endpoint}/{resource}/id`
* create: `POST {endpoint}/{resource} data`
* delete: `DELETE {endpoint}/{resource}/id`

Example (`endpoint`: `http://app.com/api`):

- create: POST request to `http://app.com/api/users`
- delete: DELETE request to `http://app.com/api/users/1`
* create: POST request to `http://app.com/api/users`
* delete: DELETE request to `http://app.com/api/users/1`

This behavior can be configured with following options:

- `uri`: set different resource uri. Example: `uri: account` => `http://app.com/api/account`.
- `create`: override create options. Expected format: `{ method: uri }`. Example: `{ "post": "/users/create" }`
- `delete`: override delete options. Expected format: `{ method: uri }`. Example: `{ "post": "/users/delete/{id}" }`
* `uri`: set different resource uri. Example: `uri: account` => `http://app.com/api/account`.
* `create`: override create options. Expected format: `{ method: uri }`. Example: `{ "post": "/users/create" }`
* `delete`: override delete options. Expected format: `{ method: uri }`. Example: `{ "post": "/users/delete/{id}" }`

Requests can also be overridden with a function which returns [axois request config][4].

Expand All @@ -146,31 +146,31 @@ delete: (id) => ({ method: 'delete', url: '/posts', data: { id } })
Requests can be updated on the fly by using `onRequest` function. For instance, you can pass in current session from a cookie.

```js
onRequest: async request => {
// using global codeceptjs instance
let cookie = await codeceptjs.container.helpers('WebDriver').grabCookie('session')
request.headers = { Cookie: `session=${cookie.value}` }
}
onRequest: async (request) => {
// using global codeceptjs instance
let cookie = await codeceptjs.container.helpers('WebDriver').grabCookie('session');
request.headers = { Cookie: `session=${cookie.value}` };
}
```

### Responses

By default `I.have()` returns a promise with a created data:

```js
let client = await I.have('client')
let client = await I.have('client');
```

Ids of created records are collected and used in the end of a test for the cleanup.
If you need to receive `id` instead of full response enable `returnId` in a helper config:

```js
// returnId: false
let clientId = await I.have('client')
let clientId = await I.have('client');
// clientId == 1

// returnId: true
let clientId = await I.have('client')
let clientId = await I.have('client');
// client == { name: 'John', email: '[email protected]' }
```

Expand All @@ -190,47 +190,47 @@ By default `id` property of response is taken. This behavior can be changed by s

### Parameters

- `config` &#x20;
* `config` &#x20;

### \_requestCreate
### _requestCreate

Executes request to create a record in API.
Can be replaced from a in custom helper.

#### Parameters

- `factory` **any**&#x20;
- `data` **any**&#x20;
* `factory` **any**&#x20;
* `data` **any**&#x20;

### \_requestDelete
### _requestDelete

Executes request to delete a record in API
Can be replaced from a custom helper.

#### Parameters

- `factory` **any**&#x20;
- `id` **any**&#x20;
* `factory` **any**&#x20;
* `id` **any**&#x20;

### have

Generates a new record using factory and saves API request to store it.

```js
// create a user
I.have('user')
I.have('user');
// create user with defined email
// and receive it when inside async function
const user = await I.have('user', { email: '[email protected]' })
const user = await I.have('user', { email: '[email protected]'});
// create a user with options that will not be included in the final request
I.have('user', {}, { age: 33, height: 55 })
I.have('user', { }, { age: 33, height: 55 })
```

#### Parameters

- `factory` **any** factory to use
- `params` **any?** predefined parameters
- `options` **any?** options for programmatically generate the attributes
* `factory` **any** factory to use
* `params` **any?** predefined parameters
* `options` **any?** options for programmatically generate the attributes

Returns **[Promise][5]<any>**&#x20;

Expand All @@ -240,24 +240,28 @@ Generates bunch of records and saves multiple API requests to store them.

```js
// create 3 posts
I.haveMultiple('post', 3)
I.haveMultiple('post', 3);

// create 3 posts by one author
I.haveMultiple('post', 3, { author: 'davert' })
I.haveMultiple('post', 3, { author: 'davert' });

// create 3 posts by one author with options
I.haveMultiple('post', 3, { author: 'davert' }, { publish_date: '01.01.1997' })
I.haveMultiple('post', 3, { author: 'davert' }, { publish_date: '01.01.1997' });
```

#### Parameters

- `factory` **any**&#x20;
- `times` **any**&#x20;
- `params` **any?**&#x20;
- `options` **any?**&#x20;
* `factory` **any**&#x20;
* `times` **any**&#x20;
* `params` **any?**&#x20;
* `options` **any?**&#x20;

[1]: https://github.com/rosiejs/rosie

[2]: https://www.npmjs.com/package/faker

[3]: http://codecept.io/helpers/REST/

[4]: https://github.com/axios/axios#request-config

[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
Loading

0 comments on commit ff1bd58

Please sign in to comment.