Browse Source

feat(testing): Improved verify cell, removed assertInnerTextWithRetry

pull/3848/head
Muhammed Mustafa 2 years ago
parent
commit
d8b0f04854
  1. 22
      scripts/playwright/pages/Base.ts
  2. 19
      scripts/playwright/pages/Dashboard/Grid/Cell/index.ts
  3. 16
      scripts/playwright/pages/Dashboard/ViewSidebar/index.ts
  4. 15
      scripts/playwright/tests/virtualColumnRelational.spec.ts

22
scripts/playwright/pages/Base.ts

@ -17,26 +17,4 @@ export default abstract class BasePage {
await this.rootPage.locator('.ant-message .ant-message-notice-content', {hasText: message}).last().textContent()
.then((text) => expect(text).toContain(message));
}
async assertInnerTextWithRetry({locator, text, retryCount = 5, retryInterval = 100}: {locator: Locator, text: string, retryCount?: number, retryInterval?: number}) {
for(let i = 0; i < retryCount; i++) {
const innerText = await locator.innerText();
if(innerText === text) {
break;
}
await this.rootPage.waitForTimeout(retryInterval);
}
return expect(await locator.innerText()).toBe(text);
}
async assertNotInnerTextWithRetry({locator, text, retryCount = 5, retryInterval = 100}: {locator: Locator, text: string, retryCount?: number, retryInterval?: number}) {
for(let i = 0; i < retryCount; i++) {
const innerText = await locator.innerText();
if(innerText !== text) {
break;
}
await this.rootPage.waitForTimeout(retryInterval);
}
return expect(await locator.innerText()).not.toBe(text);
}
}

19
scripts/playwright/pages/Dashboard/Grid/Cell/index.ts

@ -1,4 +1,4 @@
import { Locator } from "@playwright/test";
import { expect, Locator } from "@playwright/test";
import { GridPage } from "..";
import BasePage from "../../../Base";
import { SelectOptionCellPageObject } from "./SelectOptionCell";
@ -25,7 +25,20 @@ export class CellPageObject extends BasePage {
return this.get({index, columnHeader}).dblclick();
}
async verify({index, columnHeader, value}: {index: number, columnHeader: string, value: string}) {
return await this.assertInnerTextWithRetry({locator: this.get({index, columnHeader}), text: value});
async verify({index, columnHeader, value}: {index: number, columnHeader: string, value: string | string[]}) {
const _verify = async (text) => {
await expect.poll(async () => {
const innerTexts = await this.get({index, columnHeader}).allInnerTexts()
return typeof(innerTexts) === "string" ? [innerTexts]: innerTexts;
}).toContain(text);
}
if(Array.isArray(value)) {
for(const text of value) {
await _verify(text);
}
} else {
await _verify(value);
}
}
}

16
scripts/playwright/pages/Dashboard/ViewSidebar/index.ts

@ -1,4 +1,4 @@
import { Locator } from "@playwright/test";
import { expect, Locator } from "@playwright/test";
import { DashboardPage } from "../";
import BasePage from "../../Base";
@ -47,10 +47,9 @@ export class ViewSidebarPage extends BasePage {
}
async verifyView({ title, index }: { title: string, index: number }) {
return await this.assertInnerTextWithRetry({
locator: this.get().locator(`.nc-views-menu`).locator('.ant-menu-title-content').nth(index),
text: title,
})
return await expect.poll(async() => {
await this.get().locator(`.nc-views-menu`).locator('.ant-menu-title-content').nth(index).textContent();
}).toBe(title);
}
async verifyViewNotPresent({ title, index }: { title: string, index: number }) {
@ -59,10 +58,9 @@ export class ViewSidebarPage extends BasePage {
return true
}
return await this.assertNotInnerTextWithRetry({
locator: this.get().locator(`.nc-views-menu`).locator('.ant-menu-title-content').nth(index),
text: title,
})
return await expect.poll(async() => {
await this.get().locator(`.nc-views-menu`).locator('.ant-menu-title-content').nth(index).textContent();
}).not.toBe(title);
}
async reorderViews({sourceView, destinationView}: {

15
scripts/playwright/tests/virtualColumnRelational.spec.ts

@ -1,17 +1,14 @@
import { test } from "@playwright/test";
import { expect } from "@playwright/test";
import { DashboardPage } from "../pages/Dashboard";
import { SettingsPage } from "../pages/Dashboard/Settings";
import setup from "../setup";
test.describe.only("Relational Columns", () => {
let dashboard: DashboardPage, settings: SettingsPage;
test.describe("Relational Columns", () => {
let dashboard: DashboardPage;
let context: any;
test.beforeEach(async ({ page }) => {
context = await setup({ page });
dashboard = new DashboardPage(page, context.project);
settings = new SettingsPage(page);
});
test("Belongs To", async () => {
@ -19,8 +16,8 @@ test.describe.only("Relational Columns", () => {
await dashboard.closeTab({ title: "Team & Auth" });
await dashboard.treeView.openTable({ title: "Country" });
const cell = await dashboard.grid.cell.get({
index: 0,
const firstCell = await dashboard.grid.cell.get({
index: 1,
columnHeader: "City List",
});
@ -30,7 +27,9 @@ test.describe.only("Relational Columns", () => {
await dashboard.grid.cell.verify({
index: 0,
columnHeader: "City List",
value: "Kabul",
value: ["Kabul"],
});
});
});

Loading…
Cancel
Save