Refactored e2e tests to use Promise.all for parallel execution

In this update, several end-to-end (e2e) tests were refactored to use Promise.all for parallel execution of operations. This was done to improve the efficiency and stability of the tests, as waiting for each operation one by one could cause bottlenecks and potential failures in the test execution. Receives and click actions were grouped together to allow them to be executed concurrently where possible. The changes were applied across different test scenarios.
This commit is contained in:
giancarlo
2024-05-07 17:29:54 +07:00
parent 171a404379
commit 7c447c8848
6 changed files with 105 additions and 58 deletions

View File

@@ -28,23 +28,31 @@ export class TeamAccountsPageObject {
}
goToSettings() {
return this.page
.locator('a', {
hasText: 'Settings',
})
.click();
return expect(async () => {
await this.page
.locator('a', {
hasText: 'Settings',
})
.click();
await this.page.waitForURL('**/home/*/settings');
}).toPass();
}
goToBilling() {
return this.page
.locator('a', {
hasText: 'Billing',
})
.click();
return expect(async () => {
await this.page
.locator('a', {
hasText: 'Billing',
})
.click();
return await this.page.waitForURL('**/home/*/billing');
}).toPass();
}
async openAccountsSelector() {
await expect(async () => {
openAccountsSelector() {
return expect(async () => {
await this.page.click('[data-test="account-selector-trigger"]');
return expect(
@@ -58,9 +66,14 @@ export class TeamAccountsPageObject {
await this.page.click('[data-test="create-team-account-trigger"]');
await this.page.fill('[data-test="create-team-form"] input', teamName);
await this.page.click('[data-test="create-team-form"] button:last-child');
await this.page.waitForURL(`/home/${slug}`);
const click = this.page.click(
'[data-test="create-team-form"] button:last-child',
);
const response = this.page.waitForURL(`/home/${slug}`);
await Promise.all([click, response]);
}
async updateName(name: string, slug: string) {
@@ -70,14 +83,14 @@ export class TeamAccountsPageObject {
name,
);
await this.page.click(
const click = this.page.click(
'[data-test="update-team-account-name-form"] button',
);
// the slug should be updated to match the new team name
await expect(this.page).toHaveURL(
`http://localhost:3000/home/${slug}/settings`,
);
const response = this.page.waitForURL(`**/home/${slug}/settings`);
return Promise.all([click, response]);
}).toPass();
}
@@ -94,9 +107,13 @@ export class TeamAccountsPageObject {
teamName,
);
await this.page.click('[data-test="delete-team-form-confirm-button"]');
const click = this.page.click(
'[data-test="delete-team-form-confirm-button"]',
);
await this.page.waitForURL('http://localhost:3000/home');
const response = this.page.waitForURL('**/home');
return Promise.all([click, response]);
}).toPass();
}

View File

@@ -17,10 +17,13 @@ test.describe('Team Accounts', () => {
const { teamName, slug } = teamAccounts.createTeamName();
await teamAccounts.goToSettings();
await teamAccounts.updateName(teamName, slug);
const request = teamAccounts.updateName(teamName, slug);
// the slug should be updated to match the new team name
await page.waitForURL(`http://localhost:3000/home/${slug}/settings`);
const newUrl = page.waitForURL(`**/home/${slug}/settings`);
await Promise.all([request, newUrl]);
await teamAccounts.openAccountsSelector();