-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #457 from t-kurasawa/issues/449
[issues/449] add Playwright E2E test environment
- Loading branch information
Showing
10 changed files
with
357 additions
and
17 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 |
---|---|---|
|
@@ -89,3 +89,9 @@ sw.* | |
|
||
# Vim swap files | ||
*.swp | ||
|
||
# Playwright | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
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
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,77 @@ | ||
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: './test-e2e', | ||
/* 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', | ||
|
||
/* 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: 'npm run start', | ||
// url: 'http://127.0.0.1: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,84 @@ | ||
[E2E テストコード環境を構築する](https://github.com/codeforjapan/mapprint/issues/449) | ||
|
||
## 要望の概要 | What | ||
|
||
E2E テストコード環境を構築する | ||
|
||
## なぜやるのか | Why | ||
|
||
コードの品質維持のため。 | ||
|
||
#319 で Jest 環境は作ったが Vue のテストにはモック化などの整備が不十分である。 | ||
画面数も少ないため E2E テストコード環境を入れる。 | ||
|
||
## どうやるのか | How | ||
|
||
Playwright を導入する。 | ||
|
||
その後、個別のテストコードを実装する | ||
|
||
### テスト実行 | ||
` yarn test:e2e ` | ||
|
||
※Windows の方はコマンドプロンプトから実行してください | ||
|
||
### テストコードの作成方法 | ||
- Playwright には画面操作を行うことでテストコードを生成する機能があります。画面操作を行いテストコードを追加してください。 | ||
|
||
` npx playwright codegen kamimap.com ` | ||
|
||
https://playwright.dev/docs/codegen-intro | ||
|
||
|
||
### [WIP] WSL 向けの環境構築手順 | ||
|
||
- Playwright は WSL ではすぐに動かないため以下の対応をお願いします。 | ||
|
||
- 1. Error: browserType.launch: Executable doesn't exist at /home/user/.cache/ | ||
ms-playwright/chromium-1091/chrome-linux/chrome | ||
╔═════════════════════════════════════════════════════════════════════════╗ | ||
║ Looks like Playwright Test or Playwright was just installed or updated. ║ | ||
║ Please run the following command to download new browsers: ║ | ||
║ ║ | ||
║ yarn playwright install ║ | ||
║ ║ | ||
║ <3 Playwright Team ║ | ||
╚═════════════════════════════════════════════════════════════════════════╝ | ||
3 | | ||
4 | test('URL Check', async () => { | ||
> 5 | const browser = await chromium.launch({ headless: false }); | ||
| ^ | ||
6 | const context = await browser.newContext(); | ||
7 | const page = await context.newPage(); | ||
8 | | ||
|
||
|
||
- 2. Error: browserType.launch: | ||
╔══════════════════════════════════════════════════════╗ | ||
║ Host system is missing dependencies to run browsers. ║ | ||
║ Please install them with the following command: ║ | ||
║ ║ | ||
║ sudo yarn playwright install-deps ║ | ||
║ ║ | ||
║ Alternatively, use apt: ║ | ||
║ sudo apt-get install libnss3\ ║ | ||
║ libnspr4\ ║ | ||
║ libatk1.0-0\ ║ | ||
║ libatk-bridge2.0-0\ ║ | ||
║ libcups2\ ║ | ||
║ libxkbcommon0\ ║ | ||
║ libatspi2.0-0\ ║ | ||
║ libxcomposite1\ ║ | ||
║ libxdamage1\ ║ | ||
║ libxfixes3\ ║ | ||
║ libxrandr2\ ║ | ||
║ libgbm1\ ║ | ||
║ libpango-1.0-0\ ║ | ||
║ libcairo2\ ║ | ||
║ libasound2 ║ | ||
║ ║ | ||
║ <3 Playwright Team ║ | ||
╚══════════════════════════════════════════════════════╝ | ||
|
||
- 3. Error: browserType.launch: Target page, context or browser has been closed | ||
[WIP] WSL で動かす方法は未解決です。 |
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,18 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { chromium } from 'playwright'; | ||
|
||
test('URL Check', async () => { | ||
const browser = await chromium.launch({ headless: false }); | ||
const context = await browser.newContext(); | ||
const page = await context.newPage(); | ||
|
||
try { | ||
await page.goto('https://kamimap.com/'); | ||
await page.waitForLoadState('load'); | ||
await expect(page.url()).toBe('https://kamimap.com/en/'); | ||
} catch (error) { | ||
console.error('Error during page navigation:', error); | ||
} | ||
|
||
await browser.close(); | ||
}); |
File renamed without changes.
8 changes: 4 additions & 4 deletions
8
test/components/Logo.vue.spec.js → test-unit/components/Logo.vue.spec.js
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
4 changes: 2 additions & 2 deletions
4
test/lib/displayHelper.spec.js → test-unit/lib/displayHelper.spec.js
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
Oops, something went wrong.