-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathtest.js
More file actions
108 lines (78 loc) · 3.06 KB
/
test.js
File metadata and controls
108 lines (78 loc) · 3.06 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const { expect, test } = require('@playwright/test');
let page;
const baseUrl = 'https://the-internet.herokuapp.com/';
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
await page.goto(baseUrl);
await page.waitForTimeout(3000);
await expect(page).toHaveTitle('The Internet');
// await page.getByRole('link', { name: 'Checkboxes' }).click();
// const checkbox1 = page.getByRole('checkbox').first();
// const checkbox2 = page.getByRole('checkbox').last();
// expect(await checkbox1.isChecked()).toBe(false);
// await checkbox1.check();
// expect(await checkbox1.isChecked()).toBe(true);
// expect(await checkbox2.isChecked()).toBe(true);
// await checkbox2.uncheck();
// expect(await checkbox2.isChecked()).toBe(false);
// await page.goto(baseUrl);
// await page.getByRole('link', { name: 'Dropdown' }).click();
// const dropdown = page.locator('#dropdown');
// await dropdown.selectOption({ label: 'Option 1' });
// await page.goBack();
});
test('flaky test - intermittently passes and fails', async () => {
const headingName = Math.random() > 0.7 ? 'Available Examples' : 'Some Other Heading';
const availableExamples = page.getByRole('heading', { name: headingName });
const headingText = await availableExamples.textContent();
expect(headingText).toContain('Available Examples');
});
test('always failing test - incorrect page title', { tag: ['@regression'] }, async () => {
await page.goto(baseUrl);
await page.waitForTimeout(3000);
await expect(page).toHaveTitle('Wrong title');
});
test('always failing test - same stacktrace 1', async () => {
throw new Error("NullPointerError: Cannot read property 'foo' of null");
});
// test('always failing test - same stacktrace 2', async () => {
// throw new Error("NullPointerError: Cannot read property 'foo' of null");
// });
test('always pasing test - example F', async () => {
expect(true).toBe(true);
});
test('always pasing test - example G', async () => {
expect(true).toBe(true);
});
// test('always pasing test - example H', async () => {
// expect(true).toBe(true);
// });
test('always pasing test - example I', { tag: ['@p1'] }, async () => {
expect(true).toBe(true);
});
test('always passing test - verify page title', async () => {
await page.goto(baseUrl);
await page.waitForTimeout(3000);
await expect(page).toHaveTitle('The Internet');
})
test.describe(() => {
test.describe.configure({ retries: 2 });
test('Test with framework-level retry - 2 retries configured', async () => {
const randomOutcome = Math.random() > 0.7; // 30% chance of passing
if (!randomOutcome) {
throw new Error("Test failed, retrying...");
}
});
});
// test.describe(() => {
// test.describe.configure({ retries: 2 });
// test('Another Test with framework-level retry - 2 retries configured', async () => {
// const randomOutcome = Math.random() > 0.7; // 30% chance of passing
// if (!randomOutcome) {
// throw new Error("Test failed, retrying...");
// }
// });
// });
test.afterAll(async () => {
await page.close();
});