From 229e167525130bc106b17a7b507a3aa8557e4109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E6=B5=A9?= Date: Sat, 12 Oct 2024 12:48:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20CI=20=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E6=B5=81=E4=BB=A5=E4=BD=BF=E7=94=A8=E6=96=B0=E7=9A=84=E5=AE=B9?= =?UTF-8?q?=E5=99=A8=EF=BC=8C=E4=BF=AE=E6=94=B9=20Playwright=20=E5=9F=BA?= =?UTF-8?q?=E7=A1=80=20URL=EF=BC=8C=E5=A2=9E=E5=BC=BA=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E4=BB=A5=E9=99=84=E5=8A=A0=E6=88=AA=E5=9B=BE?= =?UTF-8?q?=E5=92=8C=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yaml | 4 +++- playwright.config.ts | 2 +- tests/e2e/test-1.spec.ts | 10 ++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ec928fc..7441efe 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,14 +29,16 @@ jobs: - name: 部署到 Vercel run: pnpm exec vercel deploy --prebuilt --target=production --token=${{ secrets.VERCEL_TOKEN }} - playwright: + playwright: # act --job playwright --workflows .github/workflows/ci.yaml --pull=false --dryrun runs-on: ubuntu-latest + container: yanhao98/runner-images:pnpm-with-playwright steps: - uses: yanhao98/composite-actions/setup-node-environment@main - run: pnpm run build-only env: VITE_BUILD_COMMIT: ${{ github.sha }} - name: 部署到 Surge + if: ${{ !env.ACT }} # https://nektosact.com/usage/index.html#skipping-steps id: surge_deploy # pnpm exec surge token / pnpx surge token # https://github.com/Tencent/tdesign-vue-next/pull/1604#issuecomment-1236244550 diff --git a/playwright.config.ts b/playwright.config.ts index 6ff59ac..7e217a6 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -26,7 +26,7 @@ export default defineConfig({ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Base URL to use in actions like `await page.goto('/')`. */ - baseURL: process.env.BASE_URL || 'https://vue-ts-example.surge.sh', + baseURL: process.env.BASE_URL || 'https://vue-ts-example.oo1.dev', /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', diff --git a/tests/e2e/test-1.spec.ts b/tests/e2e/test-1.spec.ts index cbdeb4d..7d0ecd0 100644 --- a/tests/e2e/test-1.spec.ts +++ b/tests/e2e/test-1.spec.ts @@ -1,7 +1,13 @@ import { test, expect } from '@playwright/test'; -test('页面加载正常', async ({ page }) => { +test('页面加载正常', async ({ page }, testInfo) => { await page.goto('/'); - console.log(page.url()); + console.log(`page.url() === ${page.url()}`); await expect(page.getByRole('link', { name: '中文-页面.page.vue' })).toBeVisible(); + await testInfo.attach('screenshot', { body: await page.screenshot({ fullPage: true }), contentType: 'image/png' }); + + // 使用文本选择器查找包含 "commit:" 的元素 + const commitElement = page.locator('text=commit:').first(); + const innerText = await commitElement.innerText(); + console.log(`Commit 文本内容: "${innerText}"`); });