forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexam-results.spec.ts
114 lines (108 loc) · 3.52 KB
/
exam-results.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
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
109
110
111
112
113
114
import * as fs from 'fs';
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
import intro from '../client/i18n/locales/english/intro.json';
const examUrl =
'/learn/foundational-c-sharp-with-microsoft/foundational-c-sharp-with-microsoft-certification-exam/foundational-c-sharp-with-microsoft-certification-exam';
test.describe('Exam Results E2E Test Suite', () => {
test.beforeEach(async ({ page }) => {
await page.goto(examUrl);
await page
.getByRole('button', {
name: translations.buttons['click-start-exam']
})
.click();
const QUESTION_COUNT = 5;
for (let i = 0; i < QUESTION_COUNT; i++) {
await page.getByRole('radio').first().check({ force: true });
if (i < QUESTION_COUNT - 1) {
await page
.getByRole('button', {
name: translations.buttons['next-question']
})
.click();
} else {
await page
.getByRole('button', {
name: translations.buttons['finish-exam']
})
.click();
await page
.getByRole('button', { name: translations.learn.exam['finish-yes'] })
.click();
}
}
});
test('Verifies the Correct Rendering of the Exam results', async ({
page
}) => {
await expect(
page
.locator('div.exam-results-wrapper')
.getByText(
intro['foundational-c-sharp-with-microsoft'].blocks[
'foundational-c-sharp-with-microsoft-certification-exam'
].title
)
).toBeVisible();
await expect(
page
.locator('div.exam-results-wrapper')
.getByText(translations.learn.exam['not-passed-message'])
).toBeVisible();
await expect(
page
.locator('div.exam-results-wrapper')
.getByTestId('exam-results-question-results')
).toBeVisible();
await expect(
page.locator('div.exam-results-wrapper').getByText(/\d% correct/)
).toBeVisible();
await expect(
page.locator('div.exam-results-wrapper').getByText(/Time: \d:\d/)
).toBeVisible();
await expect(
page
.locator('div.exam-results-wrapper')
.getByTestId('download-exam-results')
).toBeVisible();
await expect(
page
.locator('div.exam-results-wrapper')
.getByRole('button', { name: translations.buttons.exit })
).toBeVisible();
});
test('Exam Results when the User clicks on Exit button', async ({ page }) => {
await page
.locator('div.exam-results-wrapper')
.getByRole('button', { name: translations.buttons.exit })
.click();
await expect(
page
.locator('div.exam-results-wrapper')
.getByText(
intro['foundational-c-sharp-with-microsoft'].blocks[
'foundational-c-sharp-with-microsoft-certification-exam'
].title
)
).not.toBeVisible();
await expect(page).not.toHaveURL(examUrl);
});
test.describe('Exam Results E2E Test Suite', () => {
test('Exam Results When the User clicks on Download button', async ({
page
}) => {
const [download] = await Promise.all([
page.waitForEvent('download'),
page
.locator('div.exam-results-wrapper')
.getByTestId('download-exam-results')
.click()
]);
const suggestedFileName = download.suggestedFilename();
await download.saveAs(suggestedFileName);
expect(fs.existsSync(suggestedFileName)).toBeTruthy();
await download.delete();
});
});
});