-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
310 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Playwright Tests | ||
on: | ||
pull_request: | ||
branches: [develop, master] | ||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Prepare temporary contents data | ||
run: npm run prebuild | ||
- name: Install Playwright Browsers | ||
run: npx playwright install --with-deps | ||
- name: Run Playwright tests | ||
run: npx playwright test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { defineConfig, devices } from "@playwright/test"; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: "./tests", | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: "html", | ||
/* 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: 'http://127.0.0.1:3000', | ||
baseURL: "http://localhost:3000", | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: "on-first-retry", | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: "chromium", | ||
use: { ...devices["Desktop Chrome"] }, | ||
}, | ||
|
||
{ | ||
name: "firefox", | ||
use: { ...devices["Desktop Firefox"] }, | ||
}, | ||
|
||
{ | ||
name: "webkit", | ||
use: { ...devices["Desktop Safari"] }, | ||
}, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { ...devices['Pixel 5'] }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { ...devices['iPhone 12'] }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
webServer: { | ||
command: "npx vite dev --port 3000", | ||
url: "http://localhost:3000", | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import fs from "fs"; | ||
import { test, expect } from "@playwright/test"; | ||
|
||
const TEST_DATA = `--- | ||
draft: false | ||
date: "2050-01-01T00:00:00-0800" | ||
title: テスト記事 | ||
description: これはテスト記事です。 | ||
eyecatch: /images/eyecatch/eye-move-to-hono.jpg | ||
tags: | ||
- blog | ||
toc: false | ||
--- | ||
これはテスト記事です。 | ||
# 見出し1 | ||
これはテキストです。`; | ||
|
||
// Annotate entire file as serial. | ||
test.describe.configure({ mode: "serial" }); | ||
|
||
test.describe("Detail Page general UI tests", () => { | ||
test.beforeAll(async () => { | ||
await fs.promises.mkdir("./content/post/2050/01", { recursive: true }); | ||
fs.writeFile(`./content/post/2050/01/test.md`, TEST_DATA, "utf8", (err) => | ||
console.log(err) | ||
); | ||
}); | ||
|
||
test("has specific article", async ({ page }) => { | ||
await page.goto("/"); | ||
const locator = page.locator("article"); | ||
const article = locator.nth(0); | ||
await expect(article.locator(".postCard__title")).toHaveText("テスト記事"); | ||
await expect(article.locator(".postCard__desc")).toHaveText( | ||
"これはテスト記事です。" | ||
); | ||
await expect(article.locator("time")).toHaveText("2050/01/01"); | ||
}); | ||
|
||
test("navigate to the article", async ({ page }) => { | ||
await page.goto("/"); | ||
const locator = page.locator("article"); | ||
const article = locator.nth(0).locator("a"); | ||
await article.click(); | ||
await page.waitForURL(/post\/2050\/01\/test/); | ||
await expect(page).toHaveURL(/post\/2050\/01\/test/); | ||
}); | ||
|
||
test("display proper article", async ({ page }) => { | ||
await page.goto("/post/2050/01/test"); | ||
const locator = page.locator("article"); | ||
await expect(locator.locator("section")).toHaveCount(3); | ||
}); | ||
|
||
test("display proper title", async ({ page }) => { | ||
await page.goto("/post/2050/01/test"); | ||
const locator = page.getByRole("heading"); | ||
await expect(locator.first()).toHaveText("テスト記事"); | ||
}); | ||
|
||
test("display proper content", async ({ page }) => { | ||
await page.goto("/post/2050/01/test"); | ||
const content = page.locator("article > section").nth(1); | ||
await expect(content.locator("p").nth(0)).toHaveText( | ||
"これはテスト記事です。" | ||
); | ||
await expect(content.locator("h1")).toHaveText("見出し1"); | ||
await expect(content.locator("p").nth(1)).toHaveText( | ||
"これはテキストです。" | ||
); | ||
}); | ||
|
||
test("has tag link", async ({ page }) => { | ||
await page.goto("/post/2050/01/test"); | ||
const locator = page.locator(".article__tags__item"); | ||
const link = locator.locator("a"); | ||
await expect(link).toHaveText("blog"); | ||
await expect(link).toHaveAttribute("href", "/tags/blog"); | ||
}); | ||
|
||
test("navigate tag page", async ({ page }) => { | ||
await page.goto("/post/2050/01/test"); | ||
const locator = page.locator(".article__tags__item"); | ||
const link = locator.locator("a"); | ||
await link.click(); | ||
await page.waitForURL(/tags\/blog/); | ||
await expect(page).toHaveURL(/tags\/blog/); | ||
}); | ||
|
||
test("has related posts", async ({ page }) => { | ||
await page.goto("/post/2050/01/test"); | ||
const locator = page.locator(".related-articles--container"); | ||
await expect(locator).toHaveCount(5); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
test.describe("Root Page general UI tests", () => { | ||
test("has title", async ({ page }) => { | ||
await page.goto("/"); | ||
await expect(page).toHaveTitle("NISLOG"); | ||
}); | ||
|
||
test("has proper articles", async ({ page }) => { | ||
await page.goto("/"); | ||
const locator = page.locator("article"); | ||
await expect(locator).toHaveCount(10); | ||
}); | ||
|
||
test("has logo with root page link", async ({ page }) => { | ||
await page.goto("/"); | ||
const locator = page.locator(".logoLink"); | ||
await expect(locator).toHaveAttribute("href", "/"); | ||
await expect(locator).toHaveAttribute("title", "NISLOG"); | ||
}); | ||
|
||
test("has footer", async ({ page }) => { | ||
await page.goto("/"); | ||
const locator = page.locator(".copyright"); | ||
const currentYear = new Date().getFullYear(); | ||
await expect(locator).toContainText(`© 2017 - ${currentYear} NISLOG`); | ||
}); | ||
|
||
test("Pagination:link should work", async ({ page }) => { | ||
await page.goto("/"); | ||
const locator = page.locator('[role="navigation"]:not(.tagCloud__list)'); | ||
const children = locator.locator("li").nth(1); | ||
await children.click(); | ||
await page.waitForURL(/page\/2/); | ||
await expect(page).toHaveURL(/page\/2/); | ||
}); | ||
}); |