Skip to content

Commit d92f851

Browse files
Merge pull request #77 from dreamquality/feat-code-autogen-tools
added new tools for codegeneration while performing the rest tools
2 parents 9790e8f + d2ec6fd commit d92f851

File tree

18 files changed

+1134
-72
lines changed

18 files changed

+1134
-72
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,7 @@ dist
128128
.yarn/build-state.yml
129129
.yarn/install-state.gz
130130
.pnp.*
131+
132+
133+
.DS_Store
134+
.DS_Store?

docs/docs/.DS_Store

-6 KB
Binary file not shown.

docs/docs/local-setup/.DS_Store

-8 KB
Binary file not shown.

docs/docs/playwright-api/.DS_Store

-6 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
sidebar_position: 5
3+
---
4+
5+
import YouTubeVideoEmbed from '@site/src/components/HomepageFeatures/YouTubeVideoEmbed';
6+
7+
# 🎥 Recording Actions
8+
9+
Playwright MCP allows you to record your browser interactions and automatically generate test specifications. This feature helps you create automated tests without writing code manually.
10+
11+
## Getting Started
12+
13+
To start recording your actions and generate test files, you'll need to:
14+
15+
1. Start a recording session
16+
2. Perform your actions using MCP tools
17+
3. End the session to generate the test file
18+
19+
### Example
20+
21+
Here's a complete example of recording actions and generating a test spec:
22+
23+
1. First, start a new recording session by specifying:
24+
- Where to save the generated tests (`tests/generated` directory)
25+
- What to name your tests (using 'LoginTest' as a prefix)
26+
- Whether to include helpful comments in the generated code
27+
28+
2. Then perform the test actions:
29+
- Navigate to the Sauce Demo website (https://www.saucedemo.com)
30+
- Enter "standard_user" in the username field
31+
- Enter "secret_sauce" in the password field
32+
- Click the login button
33+
34+
3. Finally, end the recording session to generate your test file
35+
36+
The generated test file will look something like this:
37+
38+
```typescript
39+
import { test, expect } from '@playwright/test';
40+
41+
test('LoginTest_2024-03-23', async ({ page }) => {
42+
// Navigate to the login page
43+
await page.goto('https://www.saucedemo.com');
44+
45+
// Fill in username
46+
await page.fill('#user-name', 'standard_user');
47+
48+
// Fill in password
49+
await page.fill('#password', 'secret_sauce');
50+
51+
// Click login button
52+
await page.click('#login-button');
53+
54+
// Verify successful login
55+
await expect(page).toHaveURL(/.*inventory.html/);
56+
});
57+
```
58+
59+
## Configuration Options
60+
61+
When starting a recording session, you can configure several options:
62+
63+
- **outputPath**: Directory where the generated test files will be saved
64+
- **testNamePrefix**: Prefix for the generated test names
65+
- **includeComments**: Whether to include descriptive comments in the generated tests
66+
67+
For example, you might configure your session to:
68+
- Save tests in a 'tests/generated' folder
69+
- Name tests with a 'MyTest' prefix
70+
- Include helpful comments in the generated code
71+
72+
## Session Management
73+
74+
You can manage your recording sessions using these tools:
75+
76+
- **get_codegen_session**: Retrieve information about a recording session
77+
- **clear_codegen_session**: Clean up a recording session without generating a test
78+
79+
These tools help you check the status of your recording or clean up if you want to start over without generating a test file.
80+
81+
## Best Practices
82+
83+
1. **Organize Tests**: Use meaningful test name prefixes to organize your generated tests
84+
2. **Clean Up**: Always end or clear your sessions after recording
85+
3. **Verify Actions**: Include verification steps in your recordings
86+
4. **Maintain Context**: Keep related actions in the same recording session
87+
5. **Documentation**: Add comments during recording for better test maintainability
88+
89+
## Running Generated Tests
90+
91+
To run your generated tests, use the Playwright test runner:
92+
93+
```bash
94+
npx playwright test tests/generated/logintest_*.spec.ts
95+
```
96+
97+
:::tip
98+
You can modify the generated test files to add additional assertions, setup, or teardown code as needed.
99+
:::

docs/static/.DS_Store

-8 KB
Binary file not shown.

docs/static/img/.DS_Store

-6 KB
Binary file not shown.

package-lock.json

+50-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
"@playwright/browser-chromium": "1.51.1",
3232
"@playwright/browser-firefox": "1.51.1",
3333
"@playwright/browser-webkit": "1.51.1",
34-
"playwright": "1.51.1"
34+
"playwright": "1.51.1",
35+
"@playwright/test": "^1.42.1",
36+
"uuid": "^9.0.1"
3537
},
3638
"keywords": [
3739
"playwright",

0 commit comments

Comments
 (0)