forked from MarcusFelling/demo.playwright
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.spec.ts
70 lines (62 loc) · 1.86 KB
/
example.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* 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({
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',
}));
});