Browse Source

feat(testing): Reduced flakyness

pull/3848/head
Muhammed Mustafa 2 years ago
parent
commit
576581ef7c
  1. 12
      scripts/playwright/pages/Base.ts
  2. 8
      scripts/playwright/pages/Dashboard/Grid/index.ts

12
scripts/playwright/pages/Base.ts

@ -1,5 +1,7 @@
import { Page, expect, Locator } from "@playwright/test";
type ResponseSelector = (json: any) => boolean;
export default abstract class BasePage {
readonly rootPage: Page;
@ -17,4 +19,14 @@ export default abstract class BasePage {
// await this.rootPage.locator('.ant-message .ant-message-notice-content', {hasText: message}).last().waitFor({state: 'detached'});
}
async waitForResponseJson({responseSelector}:{ responseSelector: ResponseSelector }) {
await this.rootPage.waitForResponse(async (res) => {
try {
return responseSelector(await res.json());
} catch(e) {
return false;
}
});
}
}

8
scripts/playwright/pages/Dashboard/Grid/index.ts

@ -66,9 +66,7 @@ export class GridPage extends BasePage {
.locator(`span[title="${columnHeader}"]`)
.click();
await this.rootPage.waitForResponse(async (res) => {
return (await res.json())[columnHeader] === value;
});
await this.waitForResponseJson({responseSelector: (resJson) => resJson?.[columnHeader] === value});
}
async verifyRow({ index }: { index: number }) {
@ -163,9 +161,7 @@ export class GridPage extends BasePage {
async clickPagination({ page }: { page: string }) {
(await this.pagination({ page })).click();
await this.rootPage.waitForResponse(async (res) => {
return (await res.json())?.pageInfo;
});
await this.waitForResponseJson({responseSelector: (resJson) => resJson?.pageInfo});
await this.waitLoading();
}

Loading…
Cancel
Save