ci: 完善项目持续集成配置并添加 Playwright 测试
This commit is contained in:
53
e2e/playwright/vue.spec.ts
Normal file
53
e2e/playwright/vue.spec.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
|
||||
test.describe('Vue App', () => {
|
||||
test('visits the app root url', async ({ page }) => {
|
||||
await page.goto('/')
|
||||
await expect(page.locator('h1')).toHaveText('You did it!')
|
||||
})
|
||||
|
||||
test('displays Vue documentation link', async ({ page }) => {
|
||||
await page.goto('/')
|
||||
const link = page.locator('a[href="https://vuejs.org/"]')
|
||||
await expect(link).toBeVisible()
|
||||
await expect(link).toHaveText('vuejs.org')
|
||||
await expect(link).toHaveAttribute('target', '_blank')
|
||||
await expect(link).toHaveAttribute('rel', 'noopener')
|
||||
})
|
||||
|
||||
test('displays button with initial name state', async ({ page }) => {
|
||||
await page.goto('/')
|
||||
const button = page.locator('button[aria-label="get name"]')
|
||||
await expect(button).toBeVisible()
|
||||
await expect(button).toHaveText('Name from API is: Unknown')
|
||||
})
|
||||
|
||||
test('button click triggers API call', async ({ page }) => {
|
||||
await page.goto('/')
|
||||
|
||||
await page.route('/api/', async (route) => {
|
||||
await route.fulfill({
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ name: 'Test User' }),
|
||||
})
|
||||
})
|
||||
|
||||
const button = page.locator('button[aria-label="get name"]')
|
||||
await button.click()
|
||||
|
||||
await expect(button).toHaveText('Name from API is: Test User')
|
||||
})
|
||||
|
||||
test('handles API error gracefully', async ({ page }) => {
|
||||
await page.goto('/')
|
||||
|
||||
await page.route('/api/', async (route) => {
|
||||
await route.abort('failed')
|
||||
})
|
||||
|
||||
const button = page.locator('button[aria-label="get name"]')
|
||||
await button.click()
|
||||
|
||||
await expect(button).toHaveText('Name from API is: Unknown')
|
||||
})
|
||||
})
|
@@ -1,8 +0,0 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
|
||||
// See here how to get started:
|
||||
// https://playwright.dev/docs/intro
|
||||
test('visits the app root url', async ({ page }) => {
|
||||
await page.goto('/')
|
||||
await expect(page.locator('h1')).toHaveText('You did it!')
|
||||
})
|
Reference in New Issue
Block a user