66 lines
2.3 KiB
Markdown
66 lines
2.3 KiB
Markdown
|
|
# Instructions
|
||
|
|
|
||
|
|
- Following Playwright test failed.
|
||
|
|
- Explain why, be concise, respect Playwright best practices.
|
||
|
|
- Provide a snippet of code with the fix, if possible.
|
||
|
|
|
||
|
|
# Test info
|
||
|
|
|
||
|
|
- Name: atomic_check.spec.js >> Capability demo page atomic tests verification
|
||
|
|
- Location: test/atomic_check.spec.js:3:1
|
||
|
|
|
||
|
|
# Error details
|
||
|
|
|
||
|
|
```
|
||
|
|
Error: expect(received).toContain(expected) // indexOf
|
||
|
|
|
||
|
|
Expected value: "Synchronous State Ready"
|
||
|
|
Received array: []
|
||
|
|
```
|
||
|
|
|
||
|
|
# Page snapshot
|
||
|
|
|
||
|
|
```yaml
|
||
|
|
- generic [ref=e2]:
|
||
|
|
- navigation [ref=e4]
|
||
|
|
- generic [ref=e7]:
|
||
|
|
- heading [level=2]
|
||
|
|
- button "切换主题" [ref=e9] [cursor=pointer]: 切换主题
|
||
|
|
```
|
||
|
|
|
||
|
|
# Test source
|
||
|
|
|
||
|
|
```ts
|
||
|
|
1 | import { test, expect } from '@playwright/test';
|
||
|
|
2 |
|
||
|
|
3 | test('Capability demo page atomic tests verification', async ({ page }) => {
|
||
|
|
4 | page.on('console', msg => console.log('BROWSER:', msg.text()));
|
||
|
|
5 |
|
||
|
|
6 | await page.goto('/test/capability.html');
|
||
|
|
7 | await page.waitForTimeout(3000);
|
||
|
|
8 |
|
||
|
|
9 | const testResults = await page.evaluate(() => {
|
||
|
|
10 | const getTexts = (sel) => Array.from(document.querySelectorAll(sel)).map(el => el.textContent.trim());
|
||
|
|
11 | const getColors = (sel) => Array.from(document.querySelectorAll(sel)).map(el => el.style.color);
|
||
|
|
12 |
|
||
|
|
13 | return {
|
||
|
|
14 | textBinding: getTexts('p.fs-4'),
|
||
|
|
15 | textColor: getColors('p.fs-4'),
|
||
|
|
16 | ifTrue: document.querySelector('.alert-success')?.textContent.trim(),
|
||
|
|
17 | eachItems: getTexts('.card-body .list-group-item'),
|
||
|
|
18 | nestedEachInIf: getTexts('.badge.bg-secondary'),
|
||
|
|
19 | nestedIfInEach: getTexts('.card-body .gap-2 .p-2 span')
|
||
|
|
20 | };
|
||
|
|
21 | });
|
||
|
|
22 |
|
||
|
|
23 | console.log('Atomic Test Results:', JSON.stringify(testResults, null, 2));
|
||
|
|
24 |
|
||
|
|
> 25 | expect(testResults.textBinding).toContain('Synchronous State Ready');
|
||
|
|
| ^ Error: expect(received).toContain(expected) // indexOf
|
||
|
|
26 | expect(testResults.ifTrue).toBe('已激活 ($if="true")');
|
||
|
|
27 | expect(testResults.eachItems).toHaveLength(3);
|
||
|
|
28 | expect(testResults.nestedEachInIf).toHaveLength(3);
|
||
|
|
29 | expect(testResults.nestedIfInEach).toHaveLength(5); // Members 1-5
|
||
|
|
30 | });
|
||
|
|
31 |
|
||
|
|
```
|