testdriverai 5.2.2 → 5.3.0
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/.github/workflows/test-install.yml +1 -1
- package/README.md +5 -11
- package/agent.js +135 -99
- package/docs/30x30.mdx +84 -0
- package/docs/action/browser.mdx +129 -0
- package/docs/action/os.mdx +157 -0
- package/docs/action/output.mdx +98 -0
- package/docs/action/performance.mdx +71 -0
- package/docs/action/prerun.mdx +80 -0
- package/docs/action/secrets.mdx +103 -0
- package/docs/action/setup.mdx +115 -0
- package/docs/bugs/jira.mdx +208 -0
- package/docs/cli/overview.mdx +65 -0
- package/docs/commands/assert.mdx +31 -0
- package/docs/commands/exec.mdx +42 -0
- package/docs/commands/focus-application.mdx +29 -0
- package/docs/commands/hover-image.mdx +32 -0
- package/docs/commands/hover-text.mdx +37 -0
- package/docs/commands/if.mdx +43 -0
- package/docs/commands/match-image.mdx +41 -0
- package/docs/commands/press-keys.mdx +30 -0
- package/docs/commands/run.mdx +30 -0
- package/docs/commands/scroll-until-image.mdx +33 -0
- package/docs/commands/scroll-until-text.mdx +37 -0
- package/docs/commands/scroll.mdx +33 -0
- package/docs/commands/type.mdx +29 -0
- package/docs/commands/wait-for-image.mdx +31 -0
- package/docs/commands/wait-for-text.mdx +35 -0
- package/docs/commands/wait.mdx +30 -0
- package/docs/docs.json +226 -0
- package/docs/exporting/playwright.mdx +159 -0
- package/docs/features/auto-healing.mdx +124 -0
- package/docs/features/cross-platform.mdx +106 -0
- package/docs/features/generation.mdx +180 -0
- package/docs/features/github.mdx +161 -0
- package/docs/features/parallel-testing.mdx +130 -0
- package/docs/features/reusable-snippets.mdx +124 -0
- package/docs/features/selectorless.mdx +62 -0
- package/docs/features/visual-assertions.mdx +123 -0
- package/docs/getting-started/ci.mdx +196 -0
- package/docs/getting-started/generating.mdx +210 -0
- package/docs/getting-started/running.mdx +67 -0
- package/docs/getting-started/setup.mdx +133 -0
- package/docs/getting-started/writing.mdx +99 -0
- package/docs/guide/assertions.mdx +195 -0
- package/docs/guide/authentication.mdx +150 -0
- package/docs/guide/code.mdx +169 -0
- package/docs/guide/locating.mdx +136 -0
- package/docs/guide/setup-teardown.mdx +161 -0
- package/docs/guide/variables.mdx +218 -0
- package/docs/guide/waiting.mdx +199 -0
- package/docs/importing/csv.mdx +196 -0
- package/docs/importing/gherkin.mdx +142 -0
- package/docs/importing/jira.mdx +172 -0
- package/docs/importing/testrail.mdx +161 -0
- package/docs/integrations/electron.mdx +152 -0
- package/docs/integrations/netlify.mdx +98 -0
- package/docs/integrations/vercel.mdx +177 -0
- package/docs/interactive/assert.mdx +51 -0
- package/docs/interactive/generate.mdx +41 -0
- package/docs/interactive/run.mdx +36 -0
- package/docs/interactive/save.mdx +53 -0
- package/docs/interactive/undo.mdx +47 -0
- package/docs/issues.mdx +9 -0
- package/docs/overview/comparison.mdx +82 -0
- package/docs/overview/faq.mdx +122 -0
- package/docs/overview/quickstart.mdx +66 -0
- package/docs/overview/what-is-testdriver.mdx +73 -0
- package/docs/quickstart.mdx +66 -0
- package/docs/reference/commands/scroll.mdx +0 -0
- package/docs/reference/interactive/assert.mdx +0 -0
- package/docs/security/action.mdx +62 -0
- package/docs/security/agent.mdx +62 -0
- package/docs/security/dashboard.mdx +0 -0
- package/docs/security/platform.mdx +54 -0
- package/docs/tutorials/advanced-test.mdx +79 -0
- package/docs/tutorials/basic-test.mdx +41 -0
- package/electron/icon.png +0 -0
- package/electron/overlay.html +7 -3
- package/electron/overlay.js +75 -15
- package/electron/tray-buffered.png +0 -0
- package/electron/tray.png +0 -0
- package/index.js +75 -34
- package/lib/commander.js +22 -1
- package/lib/commands.js +87 -19
- package/lib/config.js +10 -1
- package/lib/focus-application.js +30 -23
- package/lib/generator.js +58 -7
- package/lib/init.js +48 -19
- package/lib/ipc.js +50 -0
- package/lib/logger.js +19 -6
- package/lib/overlay.js +82 -36
- package/lib/parser.js +9 -7
- package/lib/resources/prerun.yaml +17 -0
- package/lib/sandbox.js +2 -3
- package/lib/sdk.js +0 -2
- package/lib/session.js +3 -1
- package/lib/speak.js +0 -2
- package/lib/subimage/opencv.js +0 -4
- package/lib/system.js +56 -39
- package/lib/upload-secrets.js +65 -0
- package/lib/validation.js +175 -0
- package/package.json +2 -1
- package/postinstall.js +0 -24
- package/lib/websockets.js +0 -85
- package/test.md +0 -8
- package/test.yml +0 -18
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Authentication in TestDriver.ai"
|
|
3
|
+
sidebarTitle: "Authentication"
|
|
4
|
+
description: "Learn how to securely handle authentication workflows in TestDriver.ai using GitHub Actions."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
This guide explains how to handle **authentication workflows** in **TestDriver.ai** using GitHub Actions. It covers securely passing credentials (e.g., usernames and passwords) to the TestDriver.ai action and using them in both the `prerun` script and test files.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## How Authentication Works in TestDriver.ai
|
|
12
|
+
|
|
13
|
+
1. **Store Credentials Securely**:
|
|
14
|
+
- Use GitHub Secrets to store sensitive information like usernames, passwords, or API keys.
|
|
15
|
+
2. **Pass Credentials to the Workflow**:
|
|
16
|
+
- Supply credentials as environment variables or directly in the workflow.
|
|
17
|
+
3. **Use Credentials in Tests**:
|
|
18
|
+
- Dynamically reference credentials in the `prerun` script or test files to perform authentication steps.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Step 1: Store Credentials in GitHub Secrets
|
|
23
|
+
|
|
24
|
+
1. Navigate to your repository's **Settings** > **Secrets and variables** > **Actions**.
|
|
25
|
+
2. Add the following secrets:
|
|
26
|
+
- **`TD_USERNAME`**: The username for login.
|
|
27
|
+
- **`TD_PASSWORD`**: The password for login.
|
|
28
|
+
- **`TESTDRIVER_API_KEY`**: Your TestDriver.ai API key.
|
|
29
|
+
- **`WEBSITE_URL`**: The URL of the website to test.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Step 2: Pass Credentials to the Workflow
|
|
34
|
+
|
|
35
|
+
Secrets are passed to the GitHub Action using the `secrets` context. They can be supplied as:
|
|
36
|
+
- **Environment Variables**: Passed via the `env` block.
|
|
37
|
+
- **Inline in the `prerun` Script**: Used directly in the script.
|
|
38
|
+
|
|
39
|
+
### Example Workflow:
|
|
40
|
+
|
|
41
|
+
```yaml
|
|
42
|
+
name: TestDriver.ai / Authentication
|
|
43
|
+
|
|
44
|
+
on:
|
|
45
|
+
push:
|
|
46
|
+
branches:
|
|
47
|
+
- main
|
|
48
|
+
pull_request:
|
|
49
|
+
workflow_dispatch:
|
|
50
|
+
|
|
51
|
+
jobs:
|
|
52
|
+
test-authentication:
|
|
53
|
+
name: Test Authentication
|
|
54
|
+
runs-on: ubuntu-latest
|
|
55
|
+
steps:
|
|
56
|
+
- name: Check out repository
|
|
57
|
+
uses: actions/checkout@v2
|
|
58
|
+
|
|
59
|
+
- name: Run Authentication Test
|
|
60
|
+
uses: testdriverai/action@main
|
|
61
|
+
with:
|
|
62
|
+
key: ${{ secrets.TESTDRIVER_API_KEY }}
|
|
63
|
+
prompt: |
|
|
64
|
+
1. Open the login page
|
|
65
|
+
2. Enter the username: ${{ secrets.TD_USERNAME }}
|
|
66
|
+
3. Enter the password: ${{ secrets.TD_PASSWORD }}
|
|
67
|
+
4. Click the "Log In" button
|
|
68
|
+
5. Verify the dashboard is displayed
|
|
69
|
+
prerun: |
|
|
70
|
+
cd $env:TEMP
|
|
71
|
+
npm init -y
|
|
72
|
+
npm install dashcam-chrome
|
|
73
|
+
Start-Process "msedge" -ArgumentList "--start-maximized", "--load-extension=$(pwd)/node_modules/dashcam-chrome/build", "${{ secrets.WEBSITE_URL }}"
|
|
74
|
+
exit
|
|
75
|
+
env:
|
|
76
|
+
TD_USERNAME: ${{ secrets.TD_USERNAME }}
|
|
77
|
+
TD_PASSWORD: ${{ secrets.TD_PASSWORD }}
|
|
78
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
79
|
+
FORCE_COLOR: "3"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Step 3: Use Credentials in Test Files
|
|
88
|
+
|
|
89
|
+
Secrets can be referenced in the test file using placeholders (e.g., `${TD_USERNAME}` and `${TD_PASSWORD}`).
|
|
90
|
+
|
|
91
|
+
### Example Test File:
|
|
92
|
+
|
|
93
|
+
```yaml
|
|
94
|
+
version: 4.2.18
|
|
95
|
+
steps:
|
|
96
|
+
- prompt: Log in to the application
|
|
97
|
+
commands:
|
|
98
|
+
- command: hover-text
|
|
99
|
+
text: Email
|
|
100
|
+
description: Email input field
|
|
101
|
+
action: click
|
|
102
|
+
- command: type
|
|
103
|
+
text: ${TD_USERNAME}
|
|
104
|
+
- command: hover-text
|
|
105
|
+
text: Password
|
|
106
|
+
description: Password input field
|
|
107
|
+
action: click
|
|
108
|
+
- command: type
|
|
109
|
+
text: ${TD_PASSWORD}
|
|
110
|
+
- command: hover-text
|
|
111
|
+
text: Log In
|
|
112
|
+
description: Log In button
|
|
113
|
+
action: click
|
|
114
|
+
- command: assert
|
|
115
|
+
expect: The dashboard is displayed
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## How It Works Together
|
|
124
|
+
|
|
125
|
+
1. **Secrets in the Workflow**:
|
|
126
|
+
- Secrets like `TD_USERNAME` and `TD_PASSWORD` are passed as environment variables to the TestDriver.ai action.
|
|
127
|
+
|
|
128
|
+
2. **Secrets in the `prerun` Script**:
|
|
129
|
+
- The `WEBSITE_URL` secret is used to launch the browser with the correct URL.
|
|
130
|
+
|
|
131
|
+
3. **Secrets in the Test File**:
|
|
132
|
+
- The test file dynamically references the secrets to fill in login credentials during the test.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Benefits of Using Authentication in TestDriver.ai
|
|
137
|
+
|
|
138
|
+
1. **Secure Handling of Credentials**:
|
|
139
|
+
- Secrets are encrypted and not exposed in logs.
|
|
140
|
+
- Even if printed, they appear as `***`.
|
|
141
|
+
|
|
142
|
+
2. **Dynamic Testing**:
|
|
143
|
+
- Easily switch between different environments (e.g., staging, production) by updating the secrets.
|
|
144
|
+
|
|
145
|
+
3. **Reusability**:
|
|
146
|
+
- Use the same workflow and test files across multiple repositories or environments.
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
By securely passing credentials and using them in the `prerun` script and test files, you can automate authentication workflows in TestDriver.ai while ensuring sensitive information remains protected.
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Custom Code in TestDriver.ai"
|
|
3
|
+
sidebarTitle: "Custom Code"
|
|
4
|
+
description: "Learn how to integrate custom Node.js scripts into your TestDriver.ai workflows for dynamic testing."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
TestDriver.ai allows you to execute custom **Node.js** scripts within your test workflows using the `exec` command. This feature, introduced in version `5.1.0`, enables you to integrate custom logic, such as generating one-time passwords (OTPs), hitting APIs, or performing other dynamic operations, directly into your tests.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Key Features
|
|
12
|
+
|
|
13
|
+
1. **Run Node.js Scripts**:
|
|
14
|
+
- Execute custom JavaScript code within your test steps.
|
|
15
|
+
- Use NPM modules to extend functionality.
|
|
16
|
+
|
|
17
|
+
2. **Dynamic Outputs**:
|
|
18
|
+
- Store the result of your script in a variable for use in subsequent steps.
|
|
19
|
+
|
|
20
|
+
3. **NPM Support**:
|
|
21
|
+
- Install and use NPM packages in your scripts.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Example: One-Time Password (OTP) Validator
|
|
26
|
+
|
|
27
|
+
This example demonstrates how to generate a one-time password (OTP) using the `totp-generator` NPM package and use it in a test.
|
|
28
|
+
|
|
29
|
+
### Workflow File: `.github/workflows/testdriver-otp.yml`
|
|
30
|
+
|
|
31
|
+
```yaml
|
|
32
|
+
name: TestDriver.ai
|
|
33
|
+
|
|
34
|
+
on:
|
|
35
|
+
push:
|
|
36
|
+
branches: ["main"]
|
|
37
|
+
pull_request:
|
|
38
|
+
workflow_dispatch:
|
|
39
|
+
|
|
40
|
+
jobs:
|
|
41
|
+
test:
|
|
42
|
+
name: "TestDriver"
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
steps:
|
|
45
|
+
- uses: testdriverai/action@main
|
|
46
|
+
with:
|
|
47
|
+
version: "5.1.0"
|
|
48
|
+
key: ${{ secrets.TESTDRIVER_API_KEY }}
|
|
49
|
+
prompt: |
|
|
50
|
+
1. /run testdriver/testdriver.yaml
|
|
51
|
+
prerun: |
|
|
52
|
+
cd $env:TEMP
|
|
53
|
+
npm init -y
|
|
54
|
+
npm install totp-generator
|
|
55
|
+
exit
|
|
56
|
+
env:
|
|
57
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
58
|
+
FORCE_COLOR: "3"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
### Test File: `testdriver/testdriver.yaml`
|
|
67
|
+
|
|
68
|
+
```yaml
|
|
69
|
+
version: 5.1.0
|
|
70
|
+
session: 67e57d614dc25283aa0872a9
|
|
71
|
+
steps:
|
|
72
|
+
- prompt: Log in with the totp
|
|
73
|
+
commands:
|
|
74
|
+
- command: exec
|
|
75
|
+
output: totp
|
|
76
|
+
js: |
|
|
77
|
+
const { TOTP } = require("totp-generator");
|
|
78
|
+
let otp = TOTP.generate("JBSWY3DPEB3W64TMMQQQ").otp;
|
|
79
|
+
result = otp;
|
|
80
|
+
- command: exec
|
|
81
|
+
js: |
|
|
82
|
+
console.log("${OUTPUT.totp}");
|
|
83
|
+
- command: type
|
|
84
|
+
text: ${OUTPUT.totp}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## How It Works
|
|
93
|
+
|
|
94
|
+
### Parameters for `exec`
|
|
95
|
+
|
|
96
|
+
- **`js`**: The Node.js script to execute. The output must be assigned to the `result` variable.
|
|
97
|
+
- **`output`**: The name of the variable to store the result. This variable can be referenced in subsequent steps as `${OUTPUT.<var>}`.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
### Running the Demo Locally
|
|
102
|
+
|
|
103
|
+
1. Clone the repository.
|
|
104
|
+
2. Install dependencies:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
npm install
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
3. Run the test:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
testdriverai run testdriver/testdriver.yaml
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
### Example Output
|
|
121
|
+
|
|
122
|
+
- **Step 1**: Generates an OTP using the `totp-generator` package.
|
|
123
|
+
- **Step 2**: Logs the OTP to the console.
|
|
124
|
+
- **Step 3**: Types the OTP into the application.
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Pro Tips
|
|
129
|
+
|
|
130
|
+
1. **Avoid Overwriting `result`**:
|
|
131
|
+
- Always assign the output of your script to the `result` variable.
|
|
132
|
+
|
|
133
|
+
2. **Install Dependencies**:
|
|
134
|
+
- Ensure all required NPM packages are installed locally and in the `prerun` script when using GitHub Actions.
|
|
135
|
+
|
|
136
|
+
3. **Node.js Context**:
|
|
137
|
+
- The script runs in the same context as the calling process and uses Node.js's [VM module](https://nodejs.org/api/vm.html) internally.
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Gotchas
|
|
142
|
+
|
|
143
|
+
1. **Runner Support**:
|
|
144
|
+
- This feature is supported only on **hosted Windows runners**. Hosted Linux runners do not yet support `prerun`.
|
|
145
|
+
|
|
146
|
+
2. **NPM Initialization**:
|
|
147
|
+
- Ensure you initialize NPM (`npm init`) and install required packages before running the test.
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Using NPM Modules from Scratch
|
|
152
|
+
|
|
153
|
+
1. Initialize a new Node.js project:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
npm init
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
2. Install the required package:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
npm install totp-generator --save
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
By leveraging the `exec` command, you can extend TestDriver.ai's capabilities with custom Node.js scripts, enabling dynamic and powerful test workflows.
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Locating Elements in TestDriver.ai"
|
|
3
|
+
sidebarTitle: "Locating Elements"
|
|
4
|
+
description: "Learn how to effectively describe and locate elements using TestDriver.ai's visual understanding capabilities."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
TestDriver.ai uses **visual understanding** to locate elements on the screen. Unlike traditional testing frameworks that rely on selectors or element IDs, TestDriver.ai identifies elements based on their **visual appearance**. This guide explains how to describe elements effectively to ensure TestDriver.ai can locate them accurately.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Key Principles for Locating Elements
|
|
12
|
+
|
|
13
|
+
1. **Describe the Element Visually**:
|
|
14
|
+
- Focus on the **appearance** of the element, not its behavior or function.
|
|
15
|
+
- Mention unique visual traits such as **text**, **color**, **size**, **position**, or **icon**.
|
|
16
|
+
|
|
17
|
+
2. **Avoid Behavioral Descriptions**:
|
|
18
|
+
- Do not describe what the element does (e.g., "button that submits the form").
|
|
19
|
+
- Instead, describe how it looks (e.g., "blue button with the text 'Submit' in the bottom-right corner").
|
|
20
|
+
|
|
21
|
+
3. **Use Unique Identifiers**:
|
|
22
|
+
- If the element has visible text, include it in the description.
|
|
23
|
+
- For icons or images, describe their shape, color, or associated label.
|
|
24
|
+
|
|
25
|
+
4. **Leverage Visual Feedback**:
|
|
26
|
+
- TestDriver.ai will draw **yellow boxes** around detected elements during test execution.
|
|
27
|
+
- Use this feedback to verify that the correct element is being targeted.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Examples of Effective Descriptions
|
|
32
|
+
|
|
33
|
+
### 1. Buttons
|
|
34
|
+
- **Good**: "Blue button with the text 'Sign In' in the top-right corner."
|
|
35
|
+
- **Bad**: "Button that logs the user in."
|
|
36
|
+
|
|
37
|
+
### 2. Links
|
|
38
|
+
- **Good**: "Hyperlink with the text 'Learn More' in the footer."
|
|
39
|
+
- **Bad**: "Link that navigates to the About page."
|
|
40
|
+
|
|
41
|
+
### 3. Icons
|
|
42
|
+
- **Good**: "Magnifying glass icon next to the search bar."
|
|
43
|
+
- **Bad**: "Search icon that opens the search feature."
|
|
44
|
+
|
|
45
|
+
### 4. Input Fields
|
|
46
|
+
- **Good**: "White input box labeled 'Email Address' above the password field."
|
|
47
|
+
- **Bad**: "Field where the user enters their email."
|
|
48
|
+
|
|
49
|
+
### 5. Images
|
|
50
|
+
- **Good**: "Company logo in the top-left corner, a blue circle with white text."
|
|
51
|
+
- **Bad**: "Logo that redirects to the homepage."
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## How to Write TestDriver.ai Commands
|
|
56
|
+
|
|
57
|
+
### Example: Locating a Button
|
|
58
|
+
|
|
59
|
+
#### YAML Command:
|
|
60
|
+
|
|
61
|
+
```yaml
|
|
62
|
+
- command: hover-text
|
|
63
|
+
text: Sign In
|
|
64
|
+
description: Blue button with the text 'Sign In' in the top-right corner
|
|
65
|
+
action: click
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
### Example: Locating an Icon
|
|
74
|
+
|
|
75
|
+
#### YAML Command:
|
|
76
|
+
|
|
77
|
+
```yaml
|
|
78
|
+
- command: hover-image
|
|
79
|
+
description: Magnifying glass icon next to the search bar
|
|
80
|
+
action: click
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
### Example: Locating a Link
|
|
89
|
+
|
|
90
|
+
#### YAML Command:
|
|
91
|
+
|
|
92
|
+
```yaml
|
|
93
|
+
- command: hover-text
|
|
94
|
+
text: Learn More
|
|
95
|
+
description: Hyperlink with the text 'Learn More' in the footer
|
|
96
|
+
action: click
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Debugging Element Detection
|
|
105
|
+
|
|
106
|
+
1. **Run the Test**:
|
|
107
|
+
- Execute the test using TestDriver.ai.
|
|
108
|
+
- TestDriver.ai will draw **yellow boxes** around detected elements.
|
|
109
|
+
|
|
110
|
+
2. **Verify the Correct Element**:
|
|
111
|
+
- Ensure the yellow box highlights the intended element.
|
|
112
|
+
- If the wrong element is highlighted, refine your description.
|
|
113
|
+
|
|
114
|
+
3. **Adjust the Description**:
|
|
115
|
+
- Add more specific visual details (e.g., color, position, associated text).
|
|
116
|
+
- Avoid generic terms like "button" or "icon" without additional context.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Best Practices
|
|
121
|
+
|
|
122
|
+
1. **Be Specific**:
|
|
123
|
+
- Include as many unique visual traits as possible to differentiate the element from others.
|
|
124
|
+
|
|
125
|
+
2. **Test Incrementally**:
|
|
126
|
+
- Run tests after adding or modifying commands to verify element detection.
|
|
127
|
+
|
|
128
|
+
3. **Use Visual Feedback**:
|
|
129
|
+
- Leverage the yellow boxes drawn by TestDriver.ai to confirm the correct element is being targeted.
|
|
130
|
+
|
|
131
|
+
4. **Avoid Overloading Descriptions**:
|
|
132
|
+
- Keep descriptions concise but detailed enough to uniquely identify the element.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
By focusing on **visual descriptions** and leveraging TestDriver.ai's feedback, you can accurately locate elements and create robust, reliable tests.
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Setup & Teardown"
|
|
3
|
+
sidebarTitle: "Setup & Teardown"
|
|
4
|
+
description: "Learn how to effectively describe and locate elements using TestDriver.ai's visual understanding capabilities."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
When running tests with **TestDriver.ai** in GitHub Actions, it's important to handle **setup** and **teardown** tasks properly. Setup tasks should be performed **before** the TestDriver.ai action (e.g., creating a new user via an API), and teardown tasks should be performed **after** the TestDriver.ai action, ensuring cleanup happens regardless of the test results.
|
|
9
|
+
|
|
10
|
+
This guide explains how to structure your workflow to handle setup and teardown tasks effectively.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Workflow Overview
|
|
15
|
+
|
|
16
|
+
1. **Setup Tasks**:
|
|
17
|
+
- Use a dedicated action **before** the TestDriver.ai action to prepare the environment (e.g., create a test user via an API).
|
|
18
|
+
- Pass the created user credentials to the TestDriver.ai action using environment variables.
|
|
19
|
+
|
|
20
|
+
2. **Run Tests**:
|
|
21
|
+
- Execute the tests using TestDriver.ai, leveraging the setup data (e.g., the test user).
|
|
22
|
+
|
|
23
|
+
3. **Teardown Tasks**:
|
|
24
|
+
- Use a dedicated action **after** the TestDriver.ai action to clean up (e.g., delete the test user).
|
|
25
|
+
- Ensure the teardown step runs **no matter the result** of the TestDriver.ai action.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Example Workflow with Setup and Teardown
|
|
30
|
+
|
|
31
|
+
### Workflow File: `.github/workflows/testdriver-setup-teardown.yml`
|
|
32
|
+
|
|
33
|
+
```yaml
|
|
34
|
+
name: TestDriver.ai with Setup and Teardown
|
|
35
|
+
|
|
36
|
+
on:
|
|
37
|
+
push:
|
|
38
|
+
branches:
|
|
39
|
+
- main
|
|
40
|
+
pull_request:
|
|
41
|
+
workflow_dispatch:
|
|
42
|
+
|
|
43
|
+
jobs:
|
|
44
|
+
test:
|
|
45
|
+
name: "TestDriver with Setup and Teardown"
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
steps:
|
|
48
|
+
# Step 1: Check out the repository
|
|
49
|
+
- name: Check out repository
|
|
50
|
+
uses: actions/checkout@v2
|
|
51
|
+
|
|
52
|
+
# Step 2: Setup - Create a test user via API
|
|
53
|
+
- name: Setup Test User
|
|
54
|
+
id: setup-user
|
|
55
|
+
run: |
|
|
56
|
+
echo "Creating test user via API..."
|
|
57
|
+
RESPONSE=$(curl -X POST -H "Content-Type: application/json" -d '{"name": "Test User", "email": "test@example.com", "password": "password123"}' https://api.example.com/users)
|
|
58
|
+
echo "USER_ID=$(echo $RESPONSE | jq -r '.id')" >> $GITHUB_ENV
|
|
59
|
+
echo "USER_EMAIL=$(echo $RESPONSE | jq -r '.email')" >> $GITHUB_ENV
|
|
60
|
+
echo "USER_PASSWORD=password123" >> $GITHUB_ENV
|
|
61
|
+
env:
|
|
62
|
+
API_KEY: ${{ secrets.API_KEY }}
|
|
63
|
+
|
|
64
|
+
# Step 3: Run Tests with TestDriver.ai
|
|
65
|
+
- name: Run Tests with TestDriver.ai
|
|
66
|
+
uses: testdriverai/action@main
|
|
67
|
+
with:
|
|
68
|
+
key: ${{ secrets.TESTDRIVER_API_KEY }}
|
|
69
|
+
prompt: |
|
|
70
|
+
1. Log in with the test user
|
|
71
|
+
2. Perform actions on the dashboard
|
|
72
|
+
prerun: |
|
|
73
|
+
echo "Launching browser with test user credentials..."
|
|
74
|
+
echo "Email: $USER_EMAIL"
|
|
75
|
+
echo "Password: $USER_PASSWORD"
|
|
76
|
+
env:
|
|
77
|
+
USER_EMAIL: ${{ env.USER_EMAIL }}
|
|
78
|
+
USER_PASSWORD: ${{ env.USER_PASSWORD }}
|
|
79
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
80
|
+
FORCE_COLOR: "3"
|
|
81
|
+
|
|
82
|
+
# Step 4: Teardown - Delete the test user
|
|
83
|
+
- name: Teardown Test User
|
|
84
|
+
if: always()
|
|
85
|
+
run: |
|
|
86
|
+
echo "Deleting test user via API..."
|
|
87
|
+
curl -X DELETE -H "Authorization: Bearer ${{ secrets.API_KEY }}" https://api.example.com/users/$USER_ID
|
|
88
|
+
echo "Test user deleted."
|
|
89
|
+
env:
|
|
90
|
+
USER_ID: ${{ env.USER_ID }}
|
|
91
|
+
API_KEY: ${{ secrets.API_KEY }}```
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Workflow Steps Explained
|
|
97
|
+
|
|
98
|
+
### 1. **Setup Test User**
|
|
99
|
+
- **Purpose**: Create a test user via an API before running the tests.
|
|
100
|
+
- **How It Works**:
|
|
101
|
+
- The `Setup Test User` step sends a `POST` request to the API to create a new user.
|
|
102
|
+
- The user ID, email, and password are extracted from the API response and stored as environment variables (`USER_ID`, `USER_EMAIL`, `USER_PASSWORD`).
|
|
103
|
+
- **Example Output**:
|
|
104
|
+
- `USER_ID`: `12345`
|
|
105
|
+
- `USER_EMAIL`: `test@example.com`
|
|
106
|
+
- `USER_PASSWORD`: `password123`
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
### 2. **Run Tests with TestDriver.ai**
|
|
111
|
+
- **Purpose**: Execute tests using the TestDriver.ai action.
|
|
112
|
+
- **How It Works**:
|
|
113
|
+
- The `USER_EMAIL` and `USER_PASSWORD` environment variables are passed to the `prerun` script.
|
|
114
|
+
- The test prompts use these credentials to log in and perform actions.
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
### 3. **Teardown Test User**
|
|
119
|
+
- **Purpose**: Delete the test user via an API after the tests are complete.
|
|
120
|
+
- **How It Works**:
|
|
121
|
+
- The `Teardown Test User` step sends a `DELETE` request to the API to remove the test user.
|
|
122
|
+
- The `if: always()` condition ensures this step runs even if the TestDriver.ai action fails.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Best Practices for Setup and Teardown
|
|
127
|
+
|
|
128
|
+
1. **Use APIs for Setup and Teardown**:
|
|
129
|
+
- Use APIs to create and delete test data dynamically, ensuring a clean environment for each test run.
|
|
130
|
+
|
|
131
|
+
2. **Pass Data via Environment Variables**:
|
|
132
|
+
- Store setup data (e.g., user credentials) in environment variables and pass them to the TestDriver.ai action.
|
|
133
|
+
|
|
134
|
+
3. **Ensure Teardown Always Runs**:
|
|
135
|
+
- Use `if: always()` to ensure teardown tasks are executed regardless of the test results.
|
|
136
|
+
|
|
137
|
+
4. **Log Setup and Teardown Steps**:
|
|
138
|
+
- Add `echo` statements to log the progress of setup and teardown tasks for easier debugging.
|
|
139
|
+
|
|
140
|
+
5. **Test Locally**:
|
|
141
|
+
- Verify setup and teardown scripts locally before integrating them into the workflow.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Example Use Cases
|
|
146
|
+
|
|
147
|
+
### 1. **User Management**
|
|
148
|
+
- Create a test user during setup.
|
|
149
|
+
- Delete the test user during teardown.
|
|
150
|
+
|
|
151
|
+
### 2. **Database Operations**
|
|
152
|
+
- Insert test data into a database during setup.
|
|
153
|
+
- Remove the test data during teardown.
|
|
154
|
+
|
|
155
|
+
### 3. **Mock Services**
|
|
156
|
+
- Start a mock API server during setup.
|
|
157
|
+
- Stop the mock server during teardown.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
By structuring your workflow to handle **setup** before the TestDriver.ai action and **teardown** after it, you can ensure a clean and reliable test environment for every run. This approach also ensures that teardown tasks are executed regardless of the test results, maintaining a consistent state for subsequent runs.
|