참고소스 수정본
This commit is contained in:
3
참고/playwright-main/examples/github-api/.gitignore
vendored
Normal file
3
참고/playwright-main/examples/github-api/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
test-results/
|
||||
playwright-report/
|
||||
13
참고/playwright-main/examples/github-api/package.json
Normal file
13
참고/playwright-main/examples/github-api/package.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "github-api",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"test": "playwright test"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.17.1"
|
||||
}
|
||||
}
|
||||
35
참고/playwright-main/examples/github-api/playwright.config.ts
Normal file
35
참고/playwright-main/examples/github-api/playwright.config.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
/* eslint-disable notice/notice */
|
||||
|
||||
import { defineConfig } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* See https://playwright.dev/docs/test-configuration.
|
||||
*/
|
||||
export default defineConfig({
|
||||
|
||||
testDir: './tests',
|
||||
|
||||
/* Maximum time one test can run for. */
|
||||
timeout: 30 * 1000,
|
||||
|
||||
/* 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://localhost:3000',
|
||||
|
||||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
||||
trace: 'on-first-retry',
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,74 @@
|
||||
/* eslint-disable notice/notice */
|
||||
|
||||
/**
|
||||
* In this script, we will login and run a few tests that use GitHub API.
|
||||
*
|
||||
* Steps summary
|
||||
* 1. Create a new repo.
|
||||
* 2. Run tests that programmatically create new issues.
|
||||
* 3. Delete the repo.
|
||||
*/
|
||||
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
const user = process.env.GITHUB_USER;
|
||||
const repo = 'Test-Repo-1';
|
||||
|
||||
test.use({
|
||||
baseURL: 'https://api.github.com',
|
||||
extraHTTPHeaders: {
|
||||
'Accept': 'application/vnd.github.v3+json',
|
||||
// Add authorization token to all requests.
|
||||
'Authorization': `token ${process.env.API_TOKEN}`,
|
||||
}
|
||||
});
|
||||
|
||||
test.beforeAll(async ({ request }) => {
|
||||
// Create repo
|
||||
const response = await request.post('/user/repos', {
|
||||
data: {
|
||||
name: repo
|
||||
}
|
||||
});
|
||||
expect(response.ok()).toBeTruthy();
|
||||
});
|
||||
|
||||
test.afterAll(async ({ request }) => {
|
||||
// Delete repo
|
||||
const response = await request.delete(`/repos/${user}/${repo}`);
|
||||
expect(response.ok()).toBeTruthy();
|
||||
});
|
||||
|
||||
test('should create bug report', async ({ request }) => {
|
||||
const newIssue = await request.post(`/repos/${user}/${repo}/issues`, {
|
||||
data: {
|
||||
title: '[Bug] report 1',
|
||||
body: 'Bug description',
|
||||
}
|
||||
});
|
||||
expect(newIssue.ok()).toBeTruthy();
|
||||
|
||||
const issues = await request.get(`/repos/${user}/${repo}/issues`);
|
||||
expect(issues.ok()).toBeTruthy();
|
||||
expect(await issues.json()).toContainEqual(expect.objectContaining({
|
||||
title: '[Bug] report 1',
|
||||
body: 'Bug description'
|
||||
}));
|
||||
});
|
||||
|
||||
test('should create feature request', async ({ request }) => {
|
||||
const newIssue = await request.post(`/repos/${user}/${repo}/issues`, {
|
||||
data: {
|
||||
title: '[Feature] request 1',
|
||||
body: 'Feature description',
|
||||
}
|
||||
});
|
||||
expect(newIssue.ok()).toBeTruthy();
|
||||
|
||||
const issues = await request.get(`/repos/${user}/${repo}/issues`);
|
||||
expect(issues.ok()).toBeTruthy();
|
||||
expect(await issues.json()).toContainEqual(expect.objectContaining({
|
||||
title: '[Feature] request 1',
|
||||
body: 'Feature description'
|
||||
}));
|
||||
});
|
||||
Reference in New Issue
Block a user