@@ -111,7 +111,6 @@ npx playwright install
111
111
Playwright tests are written using the Playwright Test framework. Here's a basic example:
112
112
113
113
``` typescript
114
- // e2e/example.spec.ts
115
114
import { test , expect } from ' @playwright/test' ;
116
115
117
116
test (' basic test' , async ({ page }) => {
@@ -134,29 +133,13 @@ test('basic test', async ({ page }) => {
134
133
To run all Playwright tests:
135
134
136
135
``` bash
137
- npx playwright test
136
+ yarn playwright: test
138
137
```
139
138
140
139
To run a specific test file:
141
140
142
141
``` bash
143
- npx playwright test e2e/example.spec.ts
144
- ```
145
-
146
- To run tests in headed mode (with browser visible):
147
-
148
- ``` bash
149
- npx playwright test --headed
150
- ```
151
-
152
- To run tests in a specific browser:
153
-
154
- ``` bash
155
- npx playwright test --browser=chromium
156
- # or
157
- npx playwright test --browser=firefox
158
- # or
159
- npx playwright test --browser=webkit
142
+ yarn playwright:test tests/basic-tests.spec.ts
160
143
```
161
144
162
145
### Debugging Playwright Tests
@@ -166,7 +149,7 @@ To debug tests:
166
149
1 . Run with the ` --debug ` flag:
167
150
168
151
``` bash
169
- npx playwright test --debug
152
+ yarn playwright: test --debug
170
153
```
171
154
172
155
2 . Use the Playwright Inspector to step through the test.
@@ -178,65 +161,13 @@ npx playwright test --debug
178
161
To generate an HTML report:
179
162
180
163
``` bash
181
- npx playwright test --reporter=html
164
+ yarn playwright: test --reporter=html
182
165
```
183
166
184
167
Then open the report:
185
168
186
169
``` bash
187
- npx playwright show-report
188
- ```
189
-
190
- ### Testing Mobile Web Views
191
-
192
- For testing mobile web views:
193
-
194
- ``` typescript
195
- test (' mobile view test' , async ({ browser }) => {
196
- // Create a new context with mobile device emulation
197
- const context = await browser .newContext ({
198
- viewport: { width: 375 , height: 667 },
199
- userAgent:
200
- ' Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1'
201
- });
202
-
203
- const page = await context .newPage ();
204
- // Continue with your test...
205
- });
206
- ```
207
-
208
- ### CI Integration
209
-
210
- Playwright tests can be integrated into your CI pipeline. Here's an example GitHub Actions workflow:
211
-
212
- ``` yaml
213
- name : Playwright Tests
214
- on :
215
- push :
216
- branches : [main, master]
217
- pull_request :
218
- branches : [main, master]
219
- jobs :
220
- test :
221
- timeout-minutes : 60
222
- runs-on : ubuntu-latest
223
- steps :
224
- - uses : actions/checkout@v3
225
- - uses : actions/setup-node@v3
226
- with :
227
- node-version : 16
228
- - name : Install dependencies
229
- run : yarn install
230
- - name : Install Playwright Browsers
231
- run : npx playwright install --with-deps
232
- - name : Run Playwright tests
233
- run : npx playwright test
234
- - uses : actions/upload-artifact@v3
235
- if : always()
236
- with :
237
- name : playwright-report
238
- path : playwright-report/
239
- retention-days : 30
170
+ yarn playwright:test show-report
240
171
```
241
172
242
173
For more information, refer to the [ Playwright documentation] ( https://playwright.dev/docs/intro ) .
0 commit comments