Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
/test-results/
/playwright-report/
/playwright/.cache/
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.12.1
20 changes: 20 additions & 0 deletions e2e/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { test, expect } from '@playwright/test';

test('homepage has title and links to intro page', async ({ page }) => {
await page.goto('https://playwright.dev/');

// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Playwright/);

// create a locator
const getStarted = page.getByRole('link', { name: 'Get started' });

// Expect an attribute "to be strictly equal" to the value.
await expect(getStarted).toHaveAttribute('href', '/docs/intro');

// Click the get started link.
await getStarted.click();

// Expects the URL to contain intro.
await expect(page).toHaveURL(/.*intro/);
});
8 changes: 8 additions & 0 deletions e2e/localhost.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { test, expect } from '@playwright/test';

test('test', async ({ page }) => {
await page.goto('http://localhost:8000/');
await page.goto('http://localhost:8000/tasks');
await page.getByRole('link', { name: '123' }).click();
await page.getByRole('link', { name: 'Back' }).click();
});
12 changes: 12 additions & 0 deletions e2e/localhost_django_admin.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test, expect } from '@playwright/test';

test('test', async ({ page }) => {
await page.goto('http://localhost:8000/admin/login/?next=/admin/');
await page.getByLabel('ユーザー名:').click();
await page.getByLabel('ユーザー名:').fill('admin');
await page.getByLabel('ユーザー名:').press('Tab');
await page.getByLabel('パスワード:').fill('pass');
await page.getByRole('button', { name: 'ログイン' }).click();
await page.getByRole('link', { name: 'Tasks' }).click();
await page.getByRole('link', { name: '123' }).click();
});
18 changes: 18 additions & 0 deletions e2e/localhost_django_admin_with_load_storage.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test, expect } from '@playwright/test';
import path from 'path'; // 追加

test.use({
// 差し替え
// storageState: 'secret.json'
storageState: path.join(__dirname, 'secret.json')
});

test('test', async ({ page }) => {
await page.goto('http://localhost:8000/admin/');
await page.getByRole('link', { name: 'Tasks' }).click();
await page.getByText('変更する task を選択 task を追加 操作: --------- 選択された tasks の削除 実行 1個の内ひとつも選択されていません 内容 Upd').click();
await page.locator('input[name="_selected_action"]').check();
await page.getByRole('combobox', { name: '操作:' }).selectOption('delete_selected');
await page.getByRole('button', { name: '実行' }).click();
await page.getByRole('link', { name: '戻る' }).click();
});
8 changes: 8 additions & 0 deletions e2e/localhost_sleep.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { test, expect } from '@playwright/test';

test('test', async ({ page }) => {
await page.goto('http://localhost:8000/');
await page.goto('http://localhost:8000/tasks');
await page.getByRole('link', { name: '123' }).click();
await page.getByRole('link', { name: 'Back' }).click();
});
25 changes: 25 additions & 0 deletions e2e/secret.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"cookies": [
{
"name": "csrftoken",
"value": "HWgAoaHgFP2vqyVzU0nVE8lHgOAEhnD0",
"domain": "localhost",
"path": "/",
"expires": 1704112164.422583,
"httpOnly": false,
"secure": false,
"sameSite": "Lax"
},
{
"name": "sessionid",
"value": "z8nhd1j1s56jn0af84g5b8uskosy0gj0",
"domain": "localhost",
"path": "/",
"expires": 1673872159.310954,
"httpOnly": true,
"secure": false,
"sameSite": "Lax"
}
],
"origins": []
}
74 changes: 74 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "learn_playwright",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.29.1"
}
}
109 changes: 109 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
const config: PlaywrightTestConfig = {
testDir: './e2e',
/* Maximum time one test can run for. */
timeout: 30 * 1000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 5000
},
/* 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: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
// 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',
// name: 'Google Chrome',
use: {
// channel: 'chromium',
...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: {
// channel: 'msedge',
// },
// },
// {
// name: 'Google Chrome',
// use: {
// channel: 'chrome',
// },
// },
],

/* Folder for test artifacts such as screenshots, videos, traces, etc. */
// outputDir: 'test-results/',

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// port: 3000,
// },
};

export default config;