0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Github ActionsでPlaywrightのテストを動かす

Posted at

はじめに

表題通り、GithubActionsでPlaywrightを動かしていきます。

成果物

Appleのサイトのタブ遷移をサンプルにしています

apple.gif

ソースコード

ディレクトリ構成
~/develop/playwright_actions  (main)$ tree -I node_modules/
.
├── package-lock.json
├── package.json
├── playwright-report
│   └── index.html
├── playwright.config.ts
├── test-results
├── tests
│   └── apple.spec.ts
└── tsconfig.json

4 directories, 6 files
tests/apple.spec.ts
import { test} from "@playwright/test";

test("test", async ({ page }) => {
	await page.goto("https://www.apple.com/store");
	await page.getByLabel("Mac", { exact: true }).click();
	await page.getByLabel("iPad", { exact: true }).click();
	await page.getByLabel("Watch", { exact: true }).click();
	await page.getByLabel("Vision", { exact: true }).click();
	await page.getByLabel("AirPods", { exact: true }).click();
	await page.getByLabel("TV and Home", { exact: true }).click();
	await page.getByLabel("Entertainment", { exact: true }).click();
	await page.getByLabel("Store", { exact: true }).click();
});

playwright.config.ts
import { defineConfig } from "@playwright/test";

export default defineConfig({
	reporter: [
		["list"], // テストの進行状況が一つ一つコンソールに表示される
		["html", { outputFolder: "playwright-report", open: "never" }], //
	],
	use: {
		launchOptions: {
			slowMo: 1000,
		},
	},
});
name: Playwright Tests

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '16'

      - name: Install dependencies
        run: npm install

      - name: Install Playwright Browsers
        run: npx playwright install --with-deps

      - name: Run Playwright tests
        run: npx playwright test

      - name: Upload Playwright report
        if: always() # テストが成功・失敗に関わらず実行
        uses: actions/upload-artifact@v3
        with:
          name: playwright-report
          path: playwright-report
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?