From d8b0f048548b88894b9da19120ec96b606a6d1ba Mon Sep 17 00:00:00 2001 From: Muhammed Mustafa Date: Wed, 12 Oct 2022 15:16:16 +0530 Subject: [PATCH] feat(testing): Improved verify cell, removed assertInnerTextWithRetry --- scripts/playwright/pages/Base.ts | 22 ------------------- .../pages/Dashboard/Grid/Cell/index.ts | 19 +++++++++++++--- .../pages/Dashboard/ViewSidebar/index.ts | 16 ++++++-------- .../tests/virtualColumnRelational.spec.ts | 15 ++++++------- 4 files changed, 30 insertions(+), 42 deletions(-) diff --git a/scripts/playwright/pages/Base.ts b/scripts/playwright/pages/Base.ts index 13a09569af..9f85f92ed3 100644 --- a/scripts/playwright/pages/Base.ts +++ b/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); - } } \ No newline at end of file diff --git a/scripts/playwright/pages/Dashboard/Grid/Cell/index.ts b/scripts/playwright/pages/Dashboard/Grid/Cell/index.ts index 07f2103e9a..f2b0e76830 100644 --- a/scripts/playwright/pages/Dashboard/Grid/Cell/index.ts +++ b/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); + } } } \ No newline at end of file diff --git a/scripts/playwright/pages/Dashboard/ViewSidebar/index.ts b/scripts/playwright/pages/Dashboard/ViewSidebar/index.ts index 1225cbbc26..e1c958209c 100644 --- a/scripts/playwright/pages/Dashboard/ViewSidebar/index.ts +++ b/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}: { diff --git a/scripts/playwright/tests/virtualColumnRelational.spec.ts b/scripts/playwright/tests/virtualColumnRelational.spec.ts index 579e38fa30..34cf5c50bf 100644 --- a/scripts/playwright/tests/virtualColumnRelational.spec.ts +++ b/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"], }); + + }); });