Skip to content

Commit edc1700

Browse files
Fixed e2e tests when running multiple browsers concurrently (#2799)
Co-authored-by: Lionqueen94 <lionqueen94@gmail.com>
1 parent d239dcf commit edc1700

File tree

1 file changed

+141
-47
lines changed

1 file changed

+141
-47
lines changed

frontend/e2e-tests/tests/full-flow.e2e.ts

Lines changed: 141 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { stat } from "node:fs/promises";
22
import { expect } from "@playwright/test";
33
import { test } from "e2e-tests/fixtures";
4-
import { getTestPassword } from "e2e-tests/helpers-utils/e2e-test-api-helpers";
4+
import { getTestPassword, loginAs } from "e2e-tests/helpers-utils/e2e-test-api-helpers";
55
import {
66
createInvestigation,
77
fillCandidatesListPages,
@@ -61,23 +61,99 @@ const investigations = [
6161
},
6262
];
6363

64-
const typistUsers = ["typist3", "typist4"];
64+
const typistBaseNameUsers = ["typist3", "typist4"];
6565

6666
test.describe.configure({ mode: "serial" });
6767

6868
test.describe("full flow", () => {
6969
let electionId: number | null = null;
7070

71-
test(`create typists for flow`, async ({ page }) => {
71+
test("create browser-specific admin user account", async ({ admin, browserName }) => {
72+
const { request } = admin;
73+
74+
// Create admin user for each browser.
75+
const username = `admin-${browserName}`;
76+
const response = await request.post("/api/users", {
77+
data: {
78+
role: "administrator",
79+
fullname: "John Doe",
80+
username: username,
81+
temp_password: getTestPassword(username, "Temp"),
82+
},
83+
});
84+
expect(response.status()).toBe(201);
85+
86+
const loginResponse = await loginAs(request, username, "Temp");
87+
expect(loginResponse.status()).toBe(200);
88+
89+
const response2 = await request.put("/api/account", {
90+
data: {
91+
username: username,
92+
fullname: "John Doe",
93+
password: getTestPassword(username),
94+
},
95+
});
96+
97+
expect(response2.status()).toBe(200);
98+
});
99+
100+
test(`create browser-specific coordinator for flow`, async ({ page, browserName }) => {
101+
await page.goto("/account/login");
102+
103+
const adminUsername = `admin-${browserName}`;
104+
const loginPage = new LoginPgObj(page);
105+
await loginPage.login(adminUsername, getTestPassword(adminUsername));
106+
107+
const navBar = new AdminNavBar(page);
108+
await expect(navBar.username).toHaveText(`John Doe`);
109+
110+
await page.goto(`/users`);
111+
112+
const userListPgObj = new UserListPgObj(page);
113+
await userListPgObj.create.click();
114+
115+
const userCreateRolePgObj = new UserCreateRolePgObj(page);
116+
await userCreateRolePgObj.coordinator.click();
117+
await userCreateRolePgObj.continue.click();
118+
119+
const coordinatorUsername = `coordinator-${browserName}`;
120+
const userCreateDetailsPgObj = new UserCreateDetailsPgObj(page);
121+
await userCreateDetailsPgObj.username.fill(coordinatorUsername);
122+
await userCreateDetailsPgObj.fullname.fill(`Coordinator ${coordinatorUsername}`);
123+
await userCreateDetailsPgObj.password.fill(getTestPassword(coordinatorUsername, "Temp"));
124+
await userCreateDetailsPgObj.save.click();
125+
126+
await expect(userListPgObj.alert).toContainText(`${coordinatorUsername} is toegevoegd met de rol Coördinator`);
127+
});
128+
129+
test(`complete account for coordinator`, async ({ page, browserName }) => {
130+
await page.goto("/account/login");
131+
const loginPage = new LoginPgObj(page);
132+
const username = `coordinator-${browserName}`;
133+
await loginPage.login(username, getTestPassword(username, "Temp"));
134+
135+
const password = getTestPassword(username);
136+
const accountSetupPage = new AccountSetupPgObj(page);
137+
await accountSetupPage.password.fill(password);
138+
await accountSetupPage.passwordRepeat.fill(password);
139+
await accountSetupPage.saveBtn.click();
140+
141+
const overviewPage = new ElectionsOverviewPgObj(page);
142+
await expect(overviewPage.alertAccountSetup).toBeVisible();
143+
});
144+
145+
test(`create browser-specific typists for flow`, async ({ page, browserName }) => {
72146
await page.goto("/account/login");
73147

148+
const adminUsername = `admin-${browserName}`;
74149
const loginPage = new LoginPgObj(page);
75-
await loginPage.login("admin2", getTestPassword("admin2"));
150+
await loginPage.login(adminUsername, getTestPassword(adminUsername));
76151

77152
const navBar = new AdminNavBar(page);
78-
await expect(navBar.username).toHaveText(`Jef van Reybrouck`);
153+
await expect(navBar.username).toHaveText(`John Doe`);
79154

80-
for (const username of typistUsers) {
155+
// Create browser-specific typists
156+
for (const username of typistBaseNameUsers) {
81157
await page.goto(`/users`);
82158

83159
const userListPgObj = new UserListPgObj(page);
@@ -90,21 +166,23 @@ test.describe("full flow", () => {
90166
const userCreateTypePgObj = new UserCreateTypePgObj(page);
91167
await userCreateTypePgObj.continue.click();
92168

169+
const typistUsername = `${username}-${browserName}`;
93170
const userCreateDetailsPgObj = new UserCreateDetailsPgObj(page);
94-
await userCreateDetailsPgObj.username.fill(username);
95-
await userCreateDetailsPgObj.fullname.fill(`Typist ${username}`);
96-
await userCreateDetailsPgObj.password.fill(username.repeat(3));
171+
await userCreateDetailsPgObj.username.fill(typistUsername);
172+
await userCreateDetailsPgObj.fullname.fill(`Typist ${typistUsername}`);
173+
await userCreateDetailsPgObj.password.fill(typistUsername.repeat(3));
97174
await userCreateDetailsPgObj.save.click();
98175

99-
await expect(userListPgObj.alert).toContainText(`${username} is toegevoegd met de rol Invoerder`);
176+
await expect(userListPgObj.alert).toContainText(`${typistUsername} is toegevoegd met de rol Invoerder`);
100177
}
101178
});
102179

103-
test("create election and a new polling station", async ({ page }) => {
180+
test("create election and a new polling station", async ({ page, browserName }) => {
104181
await page.goto("/account/login");
105182

183+
const adminUsername = `admin-${browserName}`;
106184
const loginPage = new LoginPgObj(page);
107-
await loginPage.login("admin2", getTestPassword("admin2"));
185+
await loginPage.login(adminUsername, getTestPassword(adminUsername));
108186

109187
const electionsOverviewPage = new ElectionsOverviewPgObj(page);
110188
await electionsOverviewPage.create.click();
@@ -157,11 +235,12 @@ test.describe("full flow", () => {
157235
);
158236
});
159237

160-
test("start data entry", async ({ page }) => {
238+
test("start data entry", async ({ page, browserName }) => {
161239
await page.goto("/account/login");
162240

241+
const username = `coordinator-${browserName}`;
163242
const loginPage = new LoginPgObj(page);
164-
await loginPage.login("coordinator2", getTestPassword("coordinator2"));
243+
await loginPage.login(username, getTestPassword(username));
165244

166245
const overviewPage = new ElectionsOverviewPgObj(page);
167246
await expect(overviewPage.header).toBeVisible();
@@ -183,11 +262,12 @@ test.describe("full flow", () => {
183262
await expect(electionStatus.header).toContainText("Eerste zitting");
184263
});
185264

186-
test("download Na 31-2 documents", async ({ page }) => {
265+
test("download Na 31-2 documents", async ({ page, browserName }) => {
187266
await page.goto("/account/login");
188267

189268
const loginPage = new LoginPgObj(page);
190-
await loginPage.login("coordinator2", getTestPassword("coordinator2"));
269+
const username = `coordinator-${browserName}`;
270+
await loginPage.login(username, getTestPassword(username));
191271

192272
const overviewPage = new ElectionsOverviewPgObj(page);
193273
await expect(overviewPage.header).toBeVisible();
@@ -204,11 +284,12 @@ test.describe("full flow", () => {
204284
expect((await stat(await download.path())).size).toBeGreaterThan(1024);
205285
});
206286

207-
test("download N10-2 documents", async ({ page }) => {
287+
test("download N10-2 documents", async ({ page, browserName }) => {
208288
await page.goto("/account/login");
209289

210290
const loginPage = new LoginPgObj(page);
211-
await loginPage.login("coordinator2", getTestPassword("coordinator2"));
291+
const username = `coordinator-${browserName}`;
292+
await loginPage.login(username, getTestPassword(username));
212293

213294
const overviewPage = new ElectionsOverviewPgObj(page);
214295
await expect(overviewPage.header).toBeVisible();
@@ -225,11 +306,12 @@ test.describe("full flow", () => {
225306
expect((await stat(await download.path())).size).toBeGreaterThan(1024);
226307
});
227308

228-
for (const typist of typistUsers) {
229-
test(`complete account for ${typist}`, async ({ page }) => {
309+
for (const typist of typistBaseNameUsers) {
310+
test(`complete account for ${typist}`, async ({ page, browserName }) => {
230311
await page.goto("/account/login");
231312
const loginPage = new LoginPgObj(page);
232-
await loginPage.login(typist, typist.repeat(3));
313+
const username = `${typist}-${browserName}`;
314+
await loginPage.login(username, username.repeat(3));
233315

234316
const password = getTestPassword(typist);
235317
const accountSetupPage = new AccountSetupPgObj(page);
@@ -246,11 +328,12 @@ test.describe("full flow", () => {
246328
{ number: "1", name: "Stadhuis" },
247329
{ number: "2", name: "Basisschool de Regenboog" },
248330
]) {
249-
test(`first data entry ${station.name}`, async ({ page }) => {
331+
test(`first data entry ${station.name}`, async ({ page, browserName }) => {
250332
await page.goto("/account/login");
251333

334+
const username = `typist3-${browserName}`;
252335
const loginPage = new LoginPgObj(page);
253-
await loginPage.login("typist3", getTestPassword("typist3"));
336+
await loginPage.login(username, getTestPassword("typist3"));
254337

255338
const overviewPage = new ElectionsOverviewPgObj(page);
256339
await expect(overviewPage.header).toBeVisible();
@@ -265,11 +348,12 @@ test.describe("full flow", () => {
265348
await fillDataEntryPagesAndSave(page, noRecountNoDifferencesDataEntry);
266349
});
267350

268-
test(`second data entry ${station.name}`, async ({ page }) => {
351+
test(`second data entry ${station.name}`, async ({ page, browserName }) => {
269352
await page.goto("/account/login");
270353

354+
const username = `typist4-${browserName}`;
271355
const loginPage = new LoginPgObj(page);
272-
await loginPage.login("typist4", getTestPassword("typist4"));
356+
await loginPage.login(username, getTestPassword("typist4"));
273357

274358
const overviewPage = new ElectionsOverviewPgObj(page);
275359
await expect(overviewPage.header).toBeVisible();
@@ -285,11 +369,12 @@ test.describe("full flow", () => {
285369
});
286370
}
287371

288-
test("finish data entry", async ({ page }) => {
372+
test("finish data entry", async ({ page, browserName }) => {
289373
await page.goto("/account/login");
290374

291375
const loginPage = new LoginPgObj(page);
292-
await loginPage.login("coordinator2", getTestPassword("coordinator2"));
376+
const username = `coordinator-${browserName}`;
377+
await loginPage.login(username, getTestPassword(username));
293378

294379
const overviewPage = new ElectionsOverviewPgObj(page);
295380
await expect(overviewPage.header).toBeVisible();
@@ -315,11 +400,12 @@ test.describe("full flow", () => {
315400
expect((await stat(await download.path())).size).toBeGreaterThan(1024);
316401
});
317402

318-
test("create new committee session", async ({ page }) => {
403+
test("create new committee session", async ({ page, browserName }) => {
319404
await page.goto("/account/login");
320405

321406
const loginPage = new LoginPgObj(page);
322-
await loginPage.login("coordinator2", getTestPassword("coordinator2"));
407+
const username = `coordinator-${browserName}`;
408+
await loginPage.login(username, getTestPassword(username));
323409

324410
const overviewPage = new ElectionsOverviewPgObj(page);
325411
await expect(overviewPage.header).toBeVisible();
@@ -332,11 +418,12 @@ test.describe("full flow", () => {
332418
await expect(electionDetailsPage.investigationsOverviewButton).toBeVisible();
333419
});
334420

335-
test("download Na 31-2 inlegvel", async ({ page }) => {
421+
test("download Na 31-2 inlegvel", async ({ page, browserName }) => {
336422
await page.goto("/account/login");
337423

338424
const loginPage = new LoginPgObj(page);
339-
await loginPage.login("coordinator2", getTestPassword("coordinator2"));
425+
const username = `coordinator-${browserName}`;
426+
await loginPage.login(username, getTestPassword(username));
340427

341428
const overviewPage = new ElectionsOverviewPgObj(page);
342429
await expect(overviewPage.header).toBeVisible();
@@ -353,11 +440,12 @@ test.describe("full flow", () => {
353440
expect((await stat(await download.path())).size).toBeGreaterThan(1024);
354441
});
355442

356-
test("add missing polling station", async ({ page }) => {
443+
test("add missing polling station", async ({ page, browserName }) => {
357444
await page.goto("/account/login");
358445

359446
const loginPage = new LoginPgObj(page);
360-
await loginPage.login("coordinator2", getTestPassword("coordinator2"));
447+
const username = `coordinator-${browserName}`;
448+
await loginPage.login(username, getTestPassword(username));
361449

362450
const overviewPage = new ElectionsOverviewPgObj(page);
363451
await expect(overviewPage.header).toBeVisible();
@@ -388,11 +476,12 @@ test.describe("full flow", () => {
388476
});
389477

390478
for (const station of investigations) {
391-
test(`create investigation for ${station.name}`, async ({ page }) => {
479+
test(`create investigation for ${station.name}`, async ({ page, browserName }) => {
392480
await page.goto("/account/login");
393481

394482
const loginPage = new LoginPgObj(page);
395-
await loginPage.login("coordinator2", getTestPassword("coordinator2"));
483+
const username = `coordinator-${browserName}`;
484+
await loginPage.login(username, getTestPassword(username));
396485

397486
const overviewPage = new ElectionsOverviewPgObj(page);
398487
await expect(overviewPage.header).toBeVisible();
@@ -402,11 +491,12 @@ test.describe("full flow", () => {
402491
});
403492
}
404493

405-
test("start data entry of corrected results", async ({ page }) => {
494+
test("start data entry of corrected results", async ({ page, browserName }) => {
406495
await page.goto("/account/login");
407496

408497
const loginPage = new LoginPgObj(page);
409-
await loginPage.login("coordinator2", getTestPassword("coordinator2"));
498+
const username = `coordinator-${browserName}`;
499+
await loginPage.login(username, getTestPassword(username));
410500

411501
const overviewPage = new ElectionsOverviewPgObj(page);
412502
await expect(overviewPage.header).toBeVisible();
@@ -420,11 +510,12 @@ test.describe("full flow", () => {
420510
});
421511

422512
for (const station of investigations) {
423-
test(`finish investigation for ${station.name}`, async ({ page }) => {
513+
test(`finish investigation for ${station.name}`, async ({ page, browserName }) => {
424514
await page.goto("/account/login");
425515

426516
const loginPage = new LoginPgObj(page);
427-
await loginPage.login("coordinator2", getTestPassword("coordinator2"));
517+
const username = `coordinator-${browserName}`;
518+
await loginPage.login(username, getTestPassword(username));
428519

429520
const overviewPage = new ElectionsOverviewPgObj(page);
430521
await expect(overviewPage.header).toBeVisible();
@@ -452,12 +543,13 @@ test.describe("full flow", () => {
452543
});
453544
}
454545

455-
for (const typist of typistUsers) {
456-
test(`corrected data entry with ${typist}`, async ({ page }) => {
546+
for (const typist of typistBaseNameUsers) {
547+
test(`corrected data entry with ${typist}`, async ({ page, browserName }) => {
457548
await page.goto("/account/login");
458549

550+
const username = `${typist}-${browserName}`;
459551
const loginPage = new LoginPgObj(page);
460-
await loginPage.login(typist, getTestPassword(typist));
552+
await loginPage.login(username, getTestPassword(typist));
461553

462554
const overviewPage = new ElectionsOverviewPgObj(page);
463555
await expect(overviewPage.header).toBeVisible();
@@ -498,12 +590,13 @@ test.describe("full flow", () => {
498590
});
499591
}
500592

501-
for (const typist of typistUsers) {
502-
test(`data entry for new pollings station with ${typist}`, async ({ page }) => {
593+
for (const typist of typistBaseNameUsers) {
594+
test(`data entry for new polling station with ${typist}`, async ({ page, browserName }) => {
503595
await page.goto("/account/login");
504596

597+
const username = `${typist}-${browserName}`;
505598
const loginPage = new LoginPgObj(page);
506-
await loginPage.login(typist, getTestPassword(typist));
599+
await loginPage.login(username, getTestPassword(typist));
507600

508601
const overviewPage = new ElectionsOverviewPgObj(page);
509602
await expect(overviewPage.header).toBeVisible();
@@ -535,11 +628,12 @@ test.describe("full flow", () => {
535628
});
536629
}
537630

538-
test("check progress", async ({ page }) => {
631+
test("check progress", async ({ page, browserName }) => {
539632
await page.goto("/account/login");
540633

541634
const loginPage = new LoginPgObj(page);
542-
await loginPage.login("coordinator2", getTestPassword("coordinator2"));
635+
const username = `coordinator-${browserName}`;
636+
await loginPage.login(username, getTestPassword(username));
543637

544638
const overviewPage = new ElectionsOverviewPgObj(page);
545639
await expect(overviewPage.header).toBeVisible();

0 commit comments

Comments
 (0)