-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(button): add e2e UI snapshot #34
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,88 @@ | ||||||||||||||||||||||||||||||||||||||
import { expect, test } from '@playwright/test' | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
test.describe('button 组件xdesign规范', () => { | ||||||||||||||||||||||||||||||||||||||
test('button默认--UI截图', async ({ page }) => { | ||||||||||||||||||||||||||||||||||||||
page.on('pageerror', (exception) => expect(exception).toBeNull()) | ||||||||||||||||||||||||||||||||||||||
await page.goto('button#basic-usage') | ||||||||||||||||||||||||||||||||||||||
const demo = page.locator('#basic-usage .pc-demo') | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toBeInViewport() | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toHaveScreenshot('basic-usage.png') | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// hover时截图 | ||||||||||||||||||||||||||||||||||||||
const btns = await demo.locator('.tiny-button').all() | ||||||||||||||||||||||||||||||||||||||
let i=1; | ||||||||||||||||||||||||||||||||||||||
for(const btn of btns){ | ||||||||||||||||||||||||||||||||||||||
await btn.hover() | ||||||||||||||||||||||||||||||||||||||
await page.waitForTimeout(100) | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toBeInViewport() | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toHaveScreenshot({threshold:10}) | ||||||||||||||||||||||||||||||||||||||
i++ | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
test('幽灵--UI截图', async ({ page }) => { | ||||||||||||||||||||||||||||||||||||||
page.on('pageerror', (exception) => expect(exception).toBeNull()) | ||||||||||||||||||||||||||||||||||||||
await page.goto('button#ghost') | ||||||||||||||||||||||||||||||||||||||
const demo = page.locator('#ghost .pc-demo') | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toBeInViewport() | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toHaveScreenshot('basic-usage.png') | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct the screenshot filename The screenshot filename Apply this diff to correct the filename: await expect(demo).toHaveScreenshot('basic-usage.png');
+ await expect(demo).toHaveScreenshot('ghost.png'); Or replace the line: - await expect(demo).toHaveScreenshot('basic-usage.png');
+ await expect(demo).toHaveScreenshot('ghost.png'); Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// hover时截图 | ||||||||||||||||||||||||||||||||||||||
const btns = await demo.locator('.tiny-button').all() | ||||||||||||||||||||||||||||||||||||||
let i=1; | ||||||||||||||||||||||||||||||||||||||
for(const btn of btns){ | ||||||||||||||||||||||||||||||||||||||
await btn.hover() | ||||||||||||||||||||||||||||||||||||||
await page.waitForTimeout(100) | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toBeInViewport() | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toHaveScreenshot({threshold:10}) | ||||||||||||||||||||||||||||||||||||||
i++ | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+31
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specify unique filenames for screenshots in the hover loop Similar to the previous test case, the screenshots in the hover loop do not have specified filenames, and the variable Apply this diff: let i = 1;
for (const btn of btns) {
await btn.hover();
await page.waitForTimeout(100);
await expect(demo).toBeInViewport();
- await expect(demo).toHaveScreenshot({ threshold: 10 });
+ await expect(demo).toHaveScreenshot(`ghost-hover-${i}.png`, { threshold: 10 });
i++;
} Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
test('动态禁用--UI截图', async ({ page }) => { | ||||||||||||||||||||||||||||||||||||||
page.on('pageerror', (exception) => expect(exception).toBeNull()) | ||||||||||||||||||||||||||||||||||||||
await page.goto('button#dynamic-disabled') | ||||||||||||||||||||||||||||||||||||||
const demo = page.locator('#dynamic-disabled .pc-demo') | ||||||||||||||||||||||||||||||||||||||
await page.waitForTimeout(100) | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toBeInViewport() | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toHaveScreenshot('dynamic-disabled1.png') | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
const switchBtn = demo.locator('.tiny-switch') | ||||||||||||||||||||||||||||||||||||||
await switchBtn.click() | ||||||||||||||||||||||||||||||||||||||
await page.waitForTimeout(100) | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toBeInViewport() | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toHaveScreenshot('dynamic-disabled2.png') | ||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
test('图标--UI截图', async ({ page }) => { | ||||||||||||||||||||||||||||||||||||||
page.on('pageerror', (exception) => expect(exception).toBeNull()) | ||||||||||||||||||||||||||||||||||||||
await page.goto('button#icon') | ||||||||||||||||||||||||||||||||||||||
const demo = page.locator('#icon .pc-demo') | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toBeInViewport() | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toHaveScreenshot('icon.png') | ||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
test('文字--UI截图', async ({ page }) => { | ||||||||||||||||||||||||||||||||||||||
page.on('pageerror', (exception) => expect(exception).toBeNull()) | ||||||||||||||||||||||||||||||||||||||
await page.goto('button#text') | ||||||||||||||||||||||||||||||||||||||
const demo = page.locator('#text .pc-demo') | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toBeInViewport() | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toHaveScreenshot('text.png') | ||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
test('加载--UI截图', async ({ page }) => { | ||||||||||||||||||||||||||||||||||||||
page.on('pageerror', (exception) => expect(exception).toBeNull()) | ||||||||||||||||||||||||||||||||||||||
await page.goto('button#loading') | ||||||||||||||||||||||||||||||||||||||
const demo = page.locator('#loading .pc-demo') | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toBeInViewport() | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toHaveScreenshot('loading.png') | ||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
test('尺寸--UI截图', async ({ page }) => { | ||||||||||||||||||||||||||||||||||||||
page.on('pageerror', (exception) => expect(exception).toBeNull()) | ||||||||||||||||||||||||||||||||||||||
await page.goto('button#size') | ||||||||||||||||||||||||||||||||||||||
const demo = page.locator('#size .pc-demo') | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toBeInViewport() | ||||||||||||||||||||||||||||||||||||||
await expect(demo).toHaveScreenshot('size.png') | ||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+4
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor duplicated code to improve maintainability There is a significant amount of duplicated code across the test cases, such as setting up page error handling, navigating to pages, locating demo elements, and taking screenshots. Consider refactoring this code by creating helper functions or utilizing |
||||||||||||||||||||||||||||||||||||||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify unique filenames for screenshots in the hover loop
Within the hover loop, screenshots are taken without specifying filenames, and the variable
i
is incremented but not used. This may cause screenshots to overwrite each other or not be saved properly. Consider usingi
to create unique filenames for each screenshot.Apply this diff to specify unique filenames:
Committable suggestion