-
Notifications
You must be signed in to change notification settings - Fork 856
/
Copy pathautoNextPage.spec.ts
206 lines (187 loc) · 6.48 KB
/
autoNextPage.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import { test, expect } from "@playwright/test";
import { frameworks, url, initSurvey, getSurveyResult } from "../helper";
const title = "autoNextPage";
const json = {
focusFirstQuestionAutomatic: true,
title: "American History",
showProgressBar: "bottom",
goNextPageAutomatic: true,
pages: [
{
elements: [
{
type: "radiogroup",
name: "civilwar",
title: "When was the Civil War?",
choices: [
"1750-1800",
"1800-1850",
"1850-1900",
"1900-1950",
"after 1950"
]
}
]
},
{
elements: [
{
type: "radiogroup",
name: "libertyordeath",
title: "Who said 'Give me liberty or give me death?'",
choices: [
"John Hancock",
"James Madison",
"Patrick Henry",
"Samuel Adams"
]
}
]
},
{
elements: [
{
type: "radiogroup",
name: "magnacarta",
title: "What is the Magna Carta?",
choices: [
"The foundation of the British parliamentary system",
"The Great Seal of the monarchs of England",
"The French Declaration of the Rights of Man",
"The charter signed by the Pilgrims on the Mayflower"
]
}
]
}
],
completedHtml:
"<p>Your anwers are:</p><p>When was the Civil War?: <b>{civilwar}</b>. The correct is: <b>1850-1900</b></p><p>Who said 'Give me liberty or give me death?': <b>{libertyordeath}</b>. The correct is: <b>Patrick Henry</b></p><p>What is the Magna Carta?: <b>{magnacarta}</b>. The correct is: <b>The foundation of the British parliamentary system</b></p>"
};
const json2 = {
focusFirstQuestionAutomatic: true,
goNextPageAutomatic: true,
pages: [
{
elements: [
{
type: "matrix",
name: "q1",
columns: [1, 2, 3],
rows: ["A", "B", "C"]
}
]
}
]
};
const json3 = {
focusFirstQuestionAutomatic: true,
goNextPageAutomatic: true,
pages: [
{
elements: [
{
type: "rating",
name: "q1"
}
]
}
]
};
frameworks.forEach((framework) => {
test.describe(`${framework} ${title}`, () => {
test.beforeEach(async ({ page }) => {
await page.goto(`${url}${framework}`);
});
test("check auto next page", async ({ page }) => {
await initSurvey(page, framework, json);
const getProgressTextPosition = async (index: number) => {
const content = await page.content();
return content.indexOf(`Page ${index} of 3`);
};
const firstRadioElement = page.locator(".sd-radio__decorator").first();
expect(await getProgressTextPosition(1)).not.toBe(-1);
await firstRadioElement.click();
await page.waitForTimeout(500);
expect(await getProgressTextPosition(2)).not.toBe(-1);
await firstRadioElement.click();
await page.waitForTimeout(500);
expect(await getProgressTextPosition(3)).not.toBe(-1);
await firstRadioElement.click();
await page.waitForTimeout(500);
const surveyResult = await getSurveyResult(page);
expect(surveyResult).toEqual({
civilwar: "1750-1800",
libertyordeath: "John Hancock",
magnacarta: "The foundation of the British parliamentary system"
});
});
test("check auto next page with keyboard", async ({ page }) => {
await initSurvey(page, framework, json);
const getProgressTextPosition = async (index: number) => {
const content = await page.content();
return content.indexOf(`Page ${index} of 3`);
};
expect(await getProgressTextPosition(1)).not.toBe(-1);
await page.keyboard.press("ArrowDown");
await page.keyboard.press("Tab");
await page.keyboard.press("Enter");
expect(await getProgressTextPosition(2)).not.toBe(-1);
await page.keyboard.press("ArrowDown");
await page.keyboard.press("Tab");
await page.keyboard.press("Tab");
await page.keyboard.press("Enter");
expect(await getProgressTextPosition(3)).not.toBe(-1);
await page.keyboard.press("ArrowDown");
await page.keyboard.press("Tab");
await page.keyboard.press("Tab");
await page.keyboard.press("Enter");
const surveyResult = await getSurveyResult(page);
expect(surveyResult).toEqual({
civilwar: "1800-1850",
libertyordeath: "James Madison",
magnacarta: "The Great Seal of the monarchs of England"
});
});
test("check auto next page with matrix", async ({ page }) => {
await initSurvey(page, framework, json2);
await page.locator("tr").filter({ hasText: "A" }).locator("span").nth(1).click();
await page.waitForTimeout(500);
await page.locator("tr").filter({ hasText: "B" }).locator("span").nth(2).click();
await page.waitForTimeout(500);
await page.locator("tr").filter({ hasText: "C" }).locator("span").nth(3).click();
await page.waitForTimeout(500);
const surveyResult = await getSurveyResult(page);
expect(surveyResult.q1).toEqual({ A: 1, B: 2, C: 3 });
});
test("check auto next page with matrix + keyboard", async ({ page }) => {
await initSurvey(page, framework, json2);
await page.keyboard.press("Space");
await page.keyboard.press("Tab");
await page.keyboard.press("ArrowRight");
await page.keyboard.press("Tab");
await page.keyboard.press("ArrowRight");
await page.keyboard.press("ArrowRight");
await page.keyboard.press("Tab");
await page.keyboard.press("Enter");
const surveyResult = await getSurveyResult(page);
expect(surveyResult.q1).toEqual({ A: 1, B: 2, C: 3 });
});
test("check auto next page with rating", async ({ page }) => {
await initSurvey(page, framework, json3);
const label3 = page.locator("label", { hasText: "3" });
await label3.click();
await page.waitForTimeout(500);
const surveyResult = await getSurveyResult(page);
expect(surveyResult.q1).toBe(3);
});
test("check auto next page with rating + keyboard", async ({ page }) => {
await initSurvey(page, framework, json3);
await page.keyboard.press("ArrowRight");
await page.keyboard.press("ArrowRight");
await page.keyboard.press("Tab");
await page.keyboard.press("Enter");
const surveyResult = await getSurveyResult(page);
expect(surveyResult.q1).toBe(3);
});
});
});