Skip to content

Commit 82bc7af

Browse files
committed
Update README.md to include comprehensive documentation for LambdaTest Playwright SDK, covering prerequisites, installation, configuration, usage examples, advanced options, error handling, support, and licensing.
1 parent b11db08 commit 82bc7af

File tree

1 file changed

+207
-1
lines changed

1 file changed

+207
-1
lines changed

README.md

Lines changed: 207 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,207 @@
1-
# lambdatest-js-sdk
1+
# LambdaTest Playwright SDK
2+
3+
The LambdaTest Playwright SDK enables you to integrate LambdaTest's Smart UI testing capabilities with your Playwright test suites. This SDK allows you to capture visual snapshots of your web applications for visual regression testing.
4+
5+
## Prerequisites
6+
7+
- Node.js (v12 or higher)
8+
- Playwright (v1 or higher)
9+
- LambdaTest account with Smart UI access
10+
11+
## Installation
12+
13+
1. Install the LambdaTest Playwright SDK using npm:
14+
15+
```bash
16+
npm install @lambdatest/playwright-driver
17+
```
18+
19+
Or using yarn:
20+
21+
```bash
22+
yarn add @lambdatest/playwright-driver
23+
```
24+
25+
## Configuration
26+
27+
1. Set up your LambdaTest credentials as environment variables:
28+
29+
```bash
30+
export LT_USERNAME="your_username"
31+
export LT_ACCESS_KEY="your_access_key"
32+
```
33+
34+
2. Start the Smart UI server:
35+
36+
```bash
37+
npx smartui start
38+
```
39+
40+
## Usage
41+
42+
Here's how to use the SDK in your Playwright tests:
43+
44+
```javascript
45+
const { smartuiSnapshot } = require('@lambdatest/playwright-driver');
46+
47+
test('should capture homepage snapshot', async ({ page }) => {
48+
// Navigate to your application
49+
await page.goto('https://your-app.com');
50+
51+
// Capture a snapshot
52+
await smartuiSnapshot(page, 'homepage');
53+
});
54+
```
55+
56+
### Advanced Usage
57+
58+
The `smartuiSnapshot` function provides various options to customize your visual testing experience. These options are organized into the following categories:
59+
60+
#### 1. Element Selection Options
61+
These options help you control which elements are included or excluded from your snapshots.
62+
63+
```javascript
64+
await smartuiSnapshot(page, 'homepage', {
65+
// Ignore specific elements from the snapshot
66+
// Useful for excluding dynamic or temporary content
67+
ignoreElements: [
68+
'.dynamic-content', // CSS selector
69+
'#temporary-banner' // CSS selector
70+
],
71+
72+
// Capture only specific elements
73+
// Useful for focusing on particular components
74+
captureElements: [
75+
'.main-content', // CSS selector
76+
'#header' // CSS selector
77+
]
78+
});
79+
```
80+
81+
#### 2. Viewport and Display Options
82+
Control how your page is rendered and captured.
83+
84+
```javascript
85+
await smartuiSnapshot(page, 'homepage', {
86+
// Set the viewport size for the snapshot
87+
// Useful for testing responsive designs
88+
viewport: {
89+
width: 1920,
90+
height: 1080
91+
},
92+
93+
// Set the device scale factor
94+
// Useful for testing high-DPI displays
95+
deviceScaleFactor: 2,
96+
97+
// Set the snapshot background color
98+
// Useful for transparent backgrounds
99+
backgroundColor: '#ffffff'
100+
});
101+
```
102+
103+
#### 3. Image Quality Options
104+
Control the quality and format of the captured snapshots.
105+
106+
```javascript
107+
await smartuiSnapshot(page, 'homepage', {
108+
// Set the snapshot quality (0-100)
109+
// Higher values mean better quality but larger file size
110+
quality: 90,
111+
112+
// Set the snapshot format (png or jpeg)
113+
// PNG for lossless quality, JPEG for smaller file size
114+
format: 'png',
115+
116+
// Set the snapshot compression level (0-9)
117+
// Higher values mean more compression but lower quality
118+
compression: 6
119+
});
120+
```
121+
122+
#### 4. Region Control Options
123+
Define specific regions to capture or modify in your snapshots.
124+
125+
```javascript
126+
await smartuiSnapshot(page, 'homepage', {
127+
// Set the snapshot clip region
128+
// Useful for capturing specific parts of the page
129+
clip: {
130+
x: 0,
131+
y: 0,
132+
width: 800,
133+
height: 600
134+
},
135+
136+
// Set the snapshot mask regions
137+
// Useful for hiding sensitive information
138+
mask: [
139+
{
140+
x: 100,
141+
y: 100,
142+
width: 200,
143+
height: 200
144+
}
145+
],
146+
147+
// Set the snapshot overlay regions
148+
// Useful for highlighting specific areas
149+
overlay: [
150+
{
151+
x: 300,
152+
y: 300,
153+
width: 100,
154+
height: 100,
155+
color: '#ff0000'
156+
}
157+
]
158+
});
159+
```
160+
161+
#### 5. Annotation Options
162+
Add annotations to your snapshots for better documentation.
163+
164+
```javascript
165+
await smartuiSnapshot(page, 'homepage', {
166+
// Set the snapshot annotations
167+
// Useful for adding notes and highlights
168+
annotations: [
169+
{
170+
type: 'text',
171+
text: 'Important Section',
172+
x: 400,
173+
y: 400
174+
}
175+
]
176+
});
177+
```
178+
179+
#### 6. Performance Options
180+
Control the behavior and timing of snapshot captures.
181+
182+
```javascript
183+
await smartuiSnapshot(page, 'homepage', {
184+
// Set the snapshot timeout (in milliseconds)
185+
// Useful for handling slow-loading content
186+
timeout: 30000
187+
});
188+
```
189+
190+
## Error Handling
191+
192+
The SDK will throw errors in the following cases:
193+
- If the page object is not provided
194+
- If the snapshot name is not provided or is not a string
195+
- If the Smart UI server is not running
196+
- If there are any issues during the snapshot capture process
197+
198+
## Support
199+
200+
For any issues or questions, please:
201+
1. Check the [documentation](https://www.lambdatest.com/support/docs/)
202+
2. Contact LambdaTest support
203+
3. Open an issue on the [GitHub repository](https://github.com/LambdaTest/lambdatest-js-sdk/issues)
204+
205+
## License
206+
207+
This project is licensed under the MIT License - see the LICENSE file for details.

0 commit comments

Comments
 (0)