Skip to content

Commit 2a9b888

Browse files
committed
More fixes on e2e tests
1 parent 542f4e1 commit 2a9b888

File tree

8 files changed

+58
-37
lines changed

8 files changed

+58
-37
lines changed

package-lock.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"test": "TZ=Europe/Rome LANG='it-IT' vitest"
1515
},
1616
"devDependencies": {
17-
"@playwright/test": "^1.40.0",
17+
"@playwright/test": "^1.41.2",
1818
"@sveltejs/adapter-auto": "^2.0.0",
1919
"@sveltejs/adapter-node": "^1.2.4",
2020
"@sveltejs/kit": "^1.15.7",

tests/add_single_task.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from '@playwright/test';
2-
import { waitPageLoading } from './utils.js';
2+
import { waitPageLoading, waitStopSpinnerIn } from './utils.js';
33
import { fileURLToPath } from 'url';
44
import path from 'path';
55

@@ -177,6 +177,7 @@ async function getCreatedTaskModalData(page, taskName) {
177177
const modalTitle = page.locator('.modal.show .modal-title');
178178
await modalTitle.waitFor();
179179
await expect(modalTitle).toHaveText(`Task ${taskName}`);
180+
await waitStopSpinnerIn(page, '.modal.show');
180181
const items = await page.locator('.modal.show .modal-body').getByRole('listitem').all();
181182
const task = {
182183
name: await items[1].innerText(),

tests/admin_jobs.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ test('Execute a job and show it on the job tables', async ({ page, request }) =>
2525
await page.goto('/');
2626
await waitPageLoading(page);
2727
await page.getByRole('link', { name: 'Admin area' }).click();
28-
await page.waitForURL('/admin');
28+
await waitPageLoading(page);
29+
await page.getByRole('link', { name: 'Manage users' }).waitFor();
2930
});
3031

3132
await test.step('Open the admin jobs', async () => {
3233
await page.getByRole('link', { name: 'Jobs' }).nth(1).click();
33-
await page.waitForURL('/admin/jobs');
34+
await waitPageLoading(page);
35+
await page.getByRole('button', { name: 'Search jobs' }).waitFor();
3436
});
3537

3638
await test.step('Search with empty form fields', async () => {

tests/login_logout.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test('Login and Logout', async ({ page }) => {
1010

1111
await page.getByRole('link', { name: 'Login' }).first().click();
1212

13-
await page.waitForURL('/auth/login');
13+
await waitPageLoading(page);
1414
await login(page);
1515

1616
await expect(page.getByText('[email protected]')).toHaveCount(1);

tests/profile.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ test('User profile', async ({ page }) => {
77
await waitPageLoading(page);
88
await page.getByRole('button', { name: '[email protected]' }).click();
99
await page.getByRole('link', { name: 'My profile' }).click();
10-
await page.waitForURL('/profile');
10+
await waitPageLoading(page);
11+
await page.getByText('User ID').waitFor();
1112

1213
const cells = await page.locator('table td').all();
1314
expect(await cells[0].innerText()).toEqual('1');

tests/users_crud.spec.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ test('Create, update and delete a user', async ({ page }) => {
66
await page.goto('/');
77
await waitPageLoading(page);
88
await page.getByRole('link', { name: 'Admin area' }).click();
9-
await page.waitForURL('/admin');
9+
await waitPageLoading(page);
1010
});
1111

1212
await test.step('Open the manage users page', async () => {
1313
await page.getByRole('link', { name: 'Manage users' }).click();
14-
await page.waitForURL('/admin/users');
1514
await waitPageLoading(page);
15+
await page.getByText('Users list').waitFor();
1616
});
1717

1818
await test.step('Open the user registration page', async () => {
1919
await page.getByRole('link', { name: 'Register new user' }).click();
20-
await page.waitForURL('/admin/users/register');
2120
await waitPageLoading(page);
21+
await page.getByText('Registering new user').waitFor();
2222
});
2323

2424
const randomUserName = Math.random().toString(36).substring(7);
@@ -46,7 +46,8 @@ test('Create, update and delete a user', async ({ page }) => {
4646
await page.getByLabel('Cache dir').fill('/tmp/test');
4747

4848
await page.getByRole('button', { name: 'Save' }).click();
49-
await page.waitForURL('/admin/users');
49+
await waitPageLoading(page);
50+
await page.getByText('Users list').waitFor();
5051

5152
await expect(page.getByRole('cell', { name: randomUserName })).toHaveCount(3);
5253

@@ -65,7 +66,6 @@ test('Create, update and delete a user', async ({ page }) => {
6566
await test.step('Display the user info page', async () => {
6667
const userRow = await getUserRow(page, randomUserName);
6768
await userRow.getByRole('link', { name: 'Info' }).click();
68-
await page.waitForURL(`/admin/users/${userId}`);
6969
await waitPageLoading(page);
7070
const cells = await page.locator('table td').all();
7171
expect(await cells[0].innerText()).toEqual(userId);
@@ -79,14 +79,14 @@ test('Create, update and delete a user', async ({ page }) => {
7979
expect(await cells[8].innerText()).toEqual('/tmp/test');
8080
});
8181

82-
// Go back to previous page
83-
await page.getByRole('link', { name: 'Manage users' }).click();
84-
await page.waitForURL('/admin/users');
82+
await test.step('Go back to previous page', async () => {
83+
await page.getByRole('link', { name: 'Manage users' }).click();
84+
await waitPageLoading(page);
85+
});
8586

8687
await test.step('Open edit user page', async () => {
8788
const userRow = await getUserRow(page, randomUserName);
8889
await userRow.getByRole('link', { name: 'Edit' }).click();
89-
await page.waitForURL(`/admin/users/${userId}/edit`);
9090
await waitPageLoading(page);
9191
});
9292

@@ -111,8 +111,12 @@ test('Create, update and delete a user', async ({ page }) => {
111111
await test.step('SLURM account validation error', async () => {
112112
await page.getByRole('button', { name: 'Add SLURM account' }).click();
113113
await page.getByRole('button', { name: 'Add SLURM account' }).click();
114-
await page.getByRole('textbox', { name: /^SLURM account #1/ }).fill(randomUserName + '-slurm-account');
115-
await page.getByRole('textbox', { name: /^SLURM account #2/ }).fill(randomUserName + '-slurm-account');
114+
await page
115+
.getByRole('textbox', { name: /^SLURM account #1/ })
116+
.fill(randomUserName + '-slurm-account');
117+
await page
118+
.getByRole('textbox', { name: /^SLURM account #2/ })
119+
.fill(randomUserName + '-slurm-account');
116120
await page.getByRole('button', { name: 'Save' }).click();
117121
await page.getByText('`slurm_accounts` list has repetitions').waitFor();
118122
await page.getByLabel('Remove SLURM account').first().click();
@@ -128,7 +132,7 @@ test('Create, update and delete a user', async ({ page }) => {
128132
await page.getByLabel('SLURM user').fill(randomUserName + '_slurm-renamed');
129133
await page.getByRole('button', { name: 'Save' }).click();
130134

131-
await page.waitForURL('/admin/users');
135+
await waitPageLoading(page);
132136

133137
const userRowCells = await getUserRowCells(page, randomUserName + '-renamed');
134138
expect(await userRowCells[1].innerText()).toEqual(randomUserName + '@example.com');
@@ -142,7 +146,6 @@ test('Create, update and delete a user', async ({ page }) => {
142146
await test.step('Display the user info page', async () => {
143147
const userRow = await getUserRow(page, randomUserName + '-renamed');
144148
await userRow.getByRole('link', { name: 'Info' }).click();
145-
await page.waitForURL(`/admin/users/${userId}`);
146149
await waitPageLoading(page);
147150
const cells = await page.locator('table td').all();
148151
expect(await cells[0].innerText()).toEqual(userId);
@@ -158,14 +161,13 @@ test('Create, update and delete a user', async ({ page }) => {
158161

159162
await test.step('Go back clicking on breadcrumb', async () => {
160163
await page.getByText('Manage users').click();
161-
await page.waitForURL(`/admin/users`);
162164
await waitPageLoading(page);
165+
await page.getByText('Users list').waitFor();
163166
});
164167

165168
await test.step('Grant superuser privilege', async () => {
166169
const userRow = await getUserRow(page, randomUserName + '-renamed');
167170
await userRow.getByRole('link', { name: 'Edit' }).click();
168-
await page.waitForURL(`/admin/users/${userId}/edit`);
169171
await page.locator('#superuser').check();
170172
await page.getByRole('button', { name: 'Save' }).click();
171173

@@ -176,7 +178,7 @@ test('Create, update and delete a user', async ({ page }) => {
176178
'Do you really want to grant superuser privilege to this user?'
177179
);
178180
await page.locator('.modal.show').getByRole('button', { name: 'Confirm' }).click();
179-
await page.waitForURL('/admin/users');
181+
await page.getByText('Users list').waitFor();
180182
await page.reload();
181183

182184
await waitPageLoading(page);
@@ -190,7 +192,8 @@ test('Create, update and delete a user', async ({ page }) => {
190192
await test.step('Revoke superuser privilege', async () => {
191193
const userRow = await getUserRow(page, randomUserName + '-renamed');
192194
await userRow.getByRole('link', { name: 'Edit' }).click();
193-
await page.waitForURL(`/admin/users/${userId}/edit`);
195+
await waitPageLoading(page);
196+
await page.getByText('Editing user #').waitFor();
194197
await page.locator('#superuser').uncheck();
195198
await page.getByRole('button', { name: 'Save' }).click();
196199

@@ -201,7 +204,8 @@ test('Create, update and delete a user', async ({ page }) => {
201204
'Do you really want to revoke superuser privilege to this user?'
202205
);
203206
await page.locator('.modal.show').getByRole('button', { name: 'Confirm' }).click();
204-
await page.waitForURL('/admin/users');
207+
await waitPageLoading(page);
208+
await page.getByText('Users list').waitFor();
205209
await page.reload();
206210

207211
await waitPageLoading(page);
@@ -235,6 +239,7 @@ async function getUserRowCells(page, username) {
235239
* @returns {Promise<import('@playwright/test').Locator>}
236240
*/
237241
async function getUserRow(page, username) {
242+
await page.getByRole('row').getByText(username, { exact: true }).waitFor();
238243
const rows = await page.locator('tbody tr').all();
239244
for (const row of rows) {
240245
const cells = await row.locator('td').all();

tests/utils.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function generateUUID() {
55
}
66

77
/**
8-
* Wait until spinner disappear
8+
* Wait until page spinner disappear
99
* @param {import('@playwright/test').Page} page
1010
*/
1111
export async function waitPageLoading(page) {
@@ -19,3 +19,15 @@ export async function waitPageLoading(page) {
1919
export async function waitModalClosed(page) {
2020
await page.waitForFunction(() => document.querySelector('.modal.show') === null);
2121
}
22+
23+
/**
24+
* Wait until spinner inside selected element disappears
25+
* @param {import('@playwright/test').Page} page
26+
* @param {string} selector
27+
*/
28+
export async function waitStopSpinnerIn(page, selector) {
29+
await page.waitForFunction((selector) => {
30+
const element = /** @type {HTMLElement} */ (document.querySelector(selector));
31+
return element.querySelectorAll('.spinner-border').length === 0;
32+
}, selector);
33+
}

0 commit comments

Comments
 (0)