Skip to content

Commit aa48963

Browse files
docs(testing): update testing instructions for debugging tests (#29800)
Adds more information to the testing documentation on how to execute individual tests or pause execution.
1 parent bacded5 commit aa48963

File tree

1 file changed

+67
-3
lines changed

1 file changed

+67
-3
lines changed

docs/core/testing/usage-instructions.md

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ E2E tests verify Ionic components in a real browser. This is useful for testing
1414

1515
Follow these steps to install Playwright dependencies. These steps must also be run whenever the installed version of Playwright changes to ensure that you are testing with the correct browser binaries.
1616

17-
1. Install the Playwright dependency in the `core` directory: `npm ci`
17+
1. Install the Playwright dependency in the `core` directory: `npm ci`
1818
2. Download the correct browsers: `npx playwright install`
1919

2020
## Configuring Docker
@@ -132,15 +132,79 @@ npm run test.e2e src/components/chip
132132
```
133133

134134
Playwright supports the `--headed` flag to run in headed mode which causes the visual representation of the browser to appear:
135-
135+
136136
```shell
137137
# Will run tests in headed mode
138138
npm run test.e2e src/components/chip -- --headed
139139
```
140140

141+
### Debugging Tests
142+
143+
Playwright offers several ways to efficiently isolate and debug specific issues, helping to quickly identify and resolve problems within your test suite.
144+
145+
#### 1. Running Only Individual Tests
146+
147+
The `.only` suffix can be added to individual tests to limit execution to just those tests during debugging. If you add `.only` to a specific test, only that test will be executed, and all other tests in the test suite will be skipped.
148+
149+
**Example:**
150+
151+
```ts
152+
test.only('should do something', async ({ page }) => {
153+
// test code here
154+
});
155+
```
156+
157+
> [!IMPORTANT]
158+
> After debugging, make sure to remove the `.only` suffix to ensure all tests run again during normal execution.
159+
160+
#### 2. Running Only a Test Suite
161+
162+
Similarly, you can focus on an entire test suite by adding `.only` to a `describe` block. This ensures that only the tests within that suite will be executed, while others will be skipped.
163+
164+
**Example:**
165+
166+
```ts
167+
test.describe.only('group of tests', () => {
168+
test('test 1', async ({ page }) => {
169+
// test 1 code here
170+
});
171+
172+
test('test 2', async ({ page }) => {
173+
// test 2 code here
174+
});
175+
});
176+
```
177+
178+
> [!IMPORTANT]
179+
> After debugging, make sure to remove the `.only` suffix to ensure all tests run again during normal execution.
180+
181+
#### 3. Pausing Test Execution
182+
183+
Additionally, you can pause execution of a test by using the `page.pause()` method. This pauses the script execution and allows you to manually inspect the page in the browser.
184+
185+
**Example:**
186+
187+
```ts
188+
const { test, expect } = require('@playwright/test');
189+
190+
test('example test', async ({ page }) => {
191+
await page.goto('https://example.com');
192+
193+
// Pausing the page to inspect manually
194+
await page.pause();
195+
196+
// Further actions will resume after unpausing
197+
const title = await page.title();
198+
expect(title).toBe('Example Domain');
199+
});
200+
```
201+
202+
> [!IMPORTANT]
203+
> After debugging, make sure to remove the `page.pause()` call to restore normal test execution.
204+
141205
## Managing Screenshots
142206

143-
If you are running a test that takes a screenshot, you must first generate the reference screenshot from your reference branch. This is known as generating a "ground truth screenshot". All other screenshots will be compared to this ground truth.
207+
If you are running a test that takes a screenshot, you must first generate the reference screenshot from your reference branch. This is known as generating a "ground truth screenshot". All other screenshots will be compared to this ground truth.
144208

145209
### Generating or Updating Ground Truths With Docker (Local Development)
146210

0 commit comments

Comments
 (0)