@checksum-ai/runtime 1.1.14 → 1.1.16
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.
- package/README.md +175 -31
- package/checksumlib.js +958 -74
- package/cli.js +36 -168
- package/index.js +70 -70
- package/package.json +1 -1
- package/test-run-monitor.js +36 -8
package/README.md
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
# Checksum.ai
|
|
1
|
+
# Checksum.ai Runtime
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
### Quick Start
|
|
4
4
|
|
|
5
|
-
1.
|
|
6
|
-
2. Navigate to the directory where you want to
|
|
7
|
-
3.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
5. Update `login.ts` with your login function using Playwright. See the Login Function section below for guidance.
|
|
14
|
-
6. Run `npx checksumai test` to execute the example test and verify successful login.
|
|
15
|
-
7. If you haven't already, visit [app.checksum.ai](https://app.checksum.ai) to complete the configuration and generate a test. Then, wait for the pull request (PR) to be created and approve it.
|
|
5
|
+
1. Install the package using `npm install -D @checksum-ai/runtime` or `yarn add @checksum-ai/runtime -D`.
|
|
6
|
+
2. Navigate to the directory where you want to initialize the Checksum tests folder and run `npx checksumai init`.
|
|
7
|
+
3. In the newly created "checksum" folder
|
|
8
|
+
1. Edit `checksum.config.ts` and add the necessary configurations, including your apiKey, application baseURL, environment info, etc.
|
|
9
|
+
2. Update `login.ts` with your login function using Playwright. See the Login Function section below for guidance.
|
|
10
|
+
4. Run `npx playwright install --with-deps` to install Playwright dependencies.
|
|
11
|
+
5. Run `npx checksumai test` to execute the example test and verify successful login.
|
|
12
|
+
6. If you haven't already, visit [app.checksum.ai](https://app.checksum.ai) to complete the configuration and generate a test. Then, wait for the pull request (PR) to be created and approve it.
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
### Login Function
|
|
18
15
|
|
|
19
16
|
1. This function is executed at the start of each test.
|
|
20
17
|
2. We recommend using a consistent seeded user for every test. For example, before each test, call a webhook that creates a user, seeds it with data, and returns the username and password. This approach ensures test reliability and allows parallel test execution. Configure this webhook [in your project](https://app.checksum.ai/#/settings/wizard) for consistent test generation.
|
|
@@ -23,36 +20,183 @@
|
|
|
23
20
|
|
|
24
21
|
## Checksum AI Magic
|
|
25
22
|
|
|
26
|
-
The tests generated by Checksum are based on Playwright. When executed using the Checksum CLI with an API key, Checksum enhances Playwright's functionality, improving test reliability and automatically
|
|
23
|
+
The tests generated by Checksum are based on Playwright. When executed using the Checksum runtime CLI with an API key, Checksum enhances Playwright's functionality, improving test reliability and automatically maintains tests. Each enhancement is enabled/disabled using the `checksum.config.ts` file.
|
|
27
24
|
|
|
28
|
-
|
|
25
|
+
#### Smart Selectors
|
|
26
|
+
When generating tests, Checksum stores extensive metadata for each action (stored in the `checksum/test-data` folder). If a traditional selector fails, this metadata is used to locate the target element. For example, if a test identifies an element by its ID but the ID changes, Checksum utilizes other data points (e.g., element class, text, parents) to locate the element. Use the `checksumSelector("<id>")` method to link an action to its metadata. Do not alter the IDs.
|
|
29
27
|
|
|
30
|
-
Checksum runs your Playwright tests regularly, but we added a few extra features to make tests more reliable. All of the features can be turned on/off through `checksum.config.ts`
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
#### Checksum AI
|
|
30
|
+
If Smart Selectors also fail, Checksum's custom-trained model can regenerate the failed section of the test. In such cases, the model might add, remove, or alter actions to achieve the same objectives, without changing the assertions. The assumption is that as long as the assertions pass, the model has successfully fixed the test. Use the `checksumAI` method to wrap each step in order to achieve this behavior.
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
Example using both `checksumSelector` and `checksumAI`:
|
|
33
|
+
```js
|
|
34
|
+
await checksumAI("Save the form and continue", () =>
|
|
35
|
+
page
|
|
36
|
+
.checksumSelector("gIexv")
|
|
37
|
+
.getByRole("button", { name: "Save" })
|
|
38
|
+
.click()
|
|
39
|
+
);
|
|
40
|
+
```
|
|
37
41
|
|
|
38
42
|
You can modify the description as needed for our model. Additionally, you can include steps with only ChecksumAI descriptions, prompting our model to generate the Playwright code. For example, `await page.checksumAI("Click on 'New Task' button")` without the actual action will have our model generate the necessary Playwright code. You can even author entire tests in this manner.
|
|
39
43
|
|
|
40
|
-
### Run Modes
|
|
41
|
-
|
|
42
|
-
Checksum offers three run modes:
|
|
43
|
-
|
|
44
|
-
1. **Normal** - Tests are executed using the Autonomous Test Agent as defined in the config file.
|
|
45
|
-
2. **Heal** - If the Autonomous Test Agent corrects a test, a new test file with the fix is created. By default, this file is created locally, but you can also configure the Agent to open a PR to your GitHub repository by setting `autoHealPRs` to true.
|
|
46
|
-
3. **Refactor (Work in Progress)** - The Autonomous Test Agent runs the test and, for each action, regenerates a regular Playwright selector, a Smart Selector, and a Checksum AI description.
|
|
47
44
|
|
|
48
45
|
### Mock Data
|
|
49
46
|
|
|
50
|
-
When generating tests, Checksum records all
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
When generating tests, Checksum records all network responses, allowing tests to run in the same context. These recordings are stored as HAR files, stored in the `checksum/test-data/har` folder. Using this method is particularly useful for debugging newly generated tests, especially if your testing database/context differs from the one used for test generation. Note that if your network responses' format changes, the mocked data may not work as expected.
|
|
48
|
+
|
|
49
|
+
## Checksum Config
|
|
50
|
+
Alongside standard test run configurations found in `playwright.config.ts`, use the `checksum.config.ts` file to configure your test runs.
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
{
|
|
54
|
+
/**
|
|
55
|
+
* Checksum Run mode.
|
|
56
|
+
* Normal is currently the only supported mode.
|
|
57
|
+
*/
|
|
58
|
+
runMode: RunMode.Normal,
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Insert here your Checksum API key.
|
|
62
|
+
* You can find it in https://app.checksum.ai/#/settings/
|
|
63
|
+
*/
|
|
64
|
+
apiKey: "<API key>",
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Define your test run environments and test users within each environment.
|
|
68
|
+
* The environments must be aligned with those set here:
|
|
69
|
+
* https://app.checksum.ai/#/settings/
|
|
70
|
+
*/
|
|
71
|
+
environments: [{
|
|
72
|
+
name: 'staging';
|
|
73
|
+
users: [
|
|
74
|
+
{
|
|
75
|
+
role: "host",
|
|
76
|
+
username: "<host username>",
|
|
77
|
+
password: "<host password>",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
role: "guest",
|
|
81
|
+
username: "<guest username>",
|
|
82
|
+
password: "<guest password>",
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
baseURL: 'staging.mydomain.com';
|
|
86
|
+
loginURL: 'staging.mydomain.com/login';
|
|
87
|
+
default: true;
|
|
88
|
+
}]
|
|
89
|
+
|
|
90
|
+
options: {
|
|
91
|
+
/**
|
|
92
|
+
* Whether to use Checksum Smart Selector in order to
|
|
93
|
+
* recover from failing to locate an element for an action
|
|
94
|
+
*/
|
|
95
|
+
useChecksumSelectors: true,
|
|
96
|
+
/**
|
|
97
|
+
* Whether to use Checksum AI in order to
|
|
98
|
+
* recover from a failed action or assertion
|
|
99
|
+
*/
|
|
100
|
+
useChecksumAI: { actions: true, assertions: false },
|
|
101
|
+
/**
|
|
102
|
+
* Whether to use recorded network responses when running your tests
|
|
103
|
+
*/
|
|
104
|
+
useMockData: false,
|
|
105
|
+
/**
|
|
106
|
+
* Whether to upload the test reports to Checksum cloud
|
|
107
|
+
* allowing you to view them at https://app.checksum.ai/#/test-runs.
|
|
108
|
+
* Note: Only relevant if Playwright reporter config is set to HTML
|
|
109
|
+
* Note: Reports will be saved locally either way (according to Playwright configs)
|
|
110
|
+
* and can be viewed using the CLI command show-reports.
|
|
111
|
+
*/
|
|
112
|
+
hostReports: !!process.env.CI,
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Checksum Helpers API
|
|
118
|
+
Helpers are deconstructed from the result of the initial call to the imported @checksum-ai/runtime `init` method, as following:
|
|
119
|
+
```js
|
|
120
|
+
import { test as base } from "@playwright/test";
|
|
121
|
+
import { init, IChecksumPage } from "@checksum-ai/runtime";
|
|
122
|
+
const { test, expect, defineChecksumTest, login, checksumAI } = init(base);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
```js
|
|
126
|
+
function init(base: ChecksumTestType<PlaywrightTestArgs>): {
|
|
127
|
+
/**
|
|
128
|
+
* The Playwright test instance enhanced by Checksum
|
|
129
|
+
*/
|
|
130
|
+
test: ChecksumTestType<ChecksumPlaywrightTestArgs>;
|
|
131
|
+
/**
|
|
132
|
+
* The login method which calls the user defined login function
|
|
133
|
+
*/
|
|
134
|
+
login: ReturnType<typeof getLogin>;
|
|
135
|
+
/**
|
|
136
|
+
* The test title definition along with the test id
|
|
137
|
+
* used by Checksum to identify the test
|
|
138
|
+
*/
|
|
139
|
+
defineChecksumTest: (title: string, testId: string) => string;
|
|
140
|
+
/**
|
|
141
|
+
* The Playwright expect instance enhanced by Checksum
|
|
142
|
+
*/
|
|
143
|
+
expect: ChecksumExpect;
|
|
144
|
+
/**
|
|
145
|
+
* Wrapping each test action with this method allows
|
|
146
|
+
* Checksum to recover from failure using our test recover AI agent
|
|
147
|
+
*/
|
|
148
|
+
checksumAI: (description: string, testFunction: Function) => Promise<any>;
|
|
149
|
+
/**
|
|
150
|
+
* Return environment data as defined in the checksum configuration
|
|
151
|
+
* given the environment name and userRole, along with a login function
|
|
152
|
+
* for this environment and user combination
|
|
153
|
+
*/
|
|
154
|
+
getEnvironment: ({
|
|
155
|
+
name,
|
|
156
|
+
userRole,
|
|
157
|
+
}: {
|
|
158
|
+
name?: string;
|
|
159
|
+
userRole?: string;
|
|
160
|
+
}) => {
|
|
161
|
+
environment: ChecksumConfigEnvironment;
|
|
162
|
+
user: EnvironmentUser;
|
|
163
|
+
login: ReturnType<typeof getLogin>;
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
```
|
|
167
|
+
## Checksum Page API
|
|
168
|
+
|
|
169
|
+
```js
|
|
170
|
+
interface ChecksumPage extends Page {
|
|
171
|
+
/**
|
|
172
|
+
* Affiliates the test step with selection data calculated during test generation and used as part of the recovery mechanism in case Playwright fails to locate the element
|
|
173
|
+
*/
|
|
174
|
+
checksumSelector: (id: string) => ChecksumPage;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* For tests requiring file uploads, this method resolves to the configured assets folder storing all relevant files
|
|
178
|
+
*/
|
|
179
|
+
resolveAssetsFolder: (assets: string[]) => string[];
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* For multi-tab test flows, this method gets the ChecksumPage in order of appearance, when 0 is the initially opened tab.
|
|
183
|
+
*/
|
|
184
|
+
getPage(index: number): Promise<ChecksumPage>;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* When required to login mid-test, use reauthenticate with the user's role. Note: It is not possible to change environments during a single test run.
|
|
188
|
+
*/
|
|
189
|
+
reauthenticate: (role: string) => Promise<void>;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
## CLI Commands
|
|
53
196
|
|
|
54
197
|
1. `init` - Initialize the Checksum directory and configurations.
|
|
55
198
|
2. `test` - Run Checksum tests. Accepts all [Playwright command line flags](https://playwright.dev/docs/test-cli). To override `checksum.config.ts`, pass full or partial JSON as a string, e.g., `--checksum-config='{"baseURL": "https://example.com"}'`.
|
|
199
|
+
3. `show-report` - Locally shows the latest test run HTML report. Only applicable following completion of a test run configured to output an HTML report.
|
|
56
200
|
|
|
57
201
|
## Running with GitHub Actions
|
|
58
202
|
|