From 2a4ed7ea591294513a2622a834a4e0513ee90d88 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Tue, 19 Dec 2023 16:48:08 +0530 Subject: [PATCH] fix: playwright addNewRow wait for response issue --- .../playwright/pages/Dashboard/Grid/index.ts | 24 ++++++------------- .../tests/db/features/undo-redo.spec.ts | 8 +++---- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/tests/playwright/pages/Dashboard/Grid/index.ts b/tests/playwright/pages/Dashboard/Grid/index.ts index 6debe77668..741728cd3d 100644 --- a/tests/playwright/pages/Dashboard/Grid/index.ts +++ b/tests/playwright/pages/Dashboard/Grid/index.ts @@ -103,12 +103,10 @@ export class GridPage extends BasePage { index = 0, columnHeader = 'Title', value, - networkValidation = true, }: { index?: number; columnHeader?: string; value?: string; - networkValidation?: boolean; } = {}) { const rowValue = value ?? `Row ${index}`; // wait for render to complete before count @@ -121,6 +119,11 @@ export class GridPage extends BasePage { await this.rootPage.waitForTimeout(200); await this.rootPage.waitForLoadState('domcontentloaded'); + // Start waiting for response before clicking add new cell. Note no await. + const addNewRowResponse = this.rootPage.waitForResponse( + res => res.url().includes('api/v1/db/data/noco') && res.request().method() === 'POST' && res.status() === 200 + ); + await this.get().locator('.nc-grid-add-new-cell').click(); const rowCount = index + 1; @@ -128,21 +131,8 @@ export class GridPage extends BasePage { await this._fillRow({ index, columnHeader, value: rowValue }); - const clickOnColumnHeaderToSave = () => - this.get().locator(`[data-title="${columnHeader}"]`).locator(`span[data-test-id="${columnHeader}"]`).click(); - - if (networkValidation) { - await this.waitForResponse({ - uiAction: clickOnColumnHeaderToSave, - requestUrlPathToMatch: 'api/v1/db/data/noco', - httpMethodsToMatch: ['POST'], - // numerical types are returned in number format from the server - responseJsonMatcher: resJson => String(resJson?.[columnHeader]) === String(rowValue), - }); - } else { - await clickOnColumnHeaderToSave(); - await this.rootPage.waitForTimeout(300); - } + // Wait for add new row api response + await addNewRowResponse; await this.rootPage.keyboard.press('Escape'); await this.rootPage.waitForTimeout(300); diff --git a/tests/playwright/tests/db/features/undo-redo.spec.ts b/tests/playwright/tests/db/features/undo-redo.spec.ts index d8438dedac..3b337a91c7 100644 --- a/tests/playwright/tests/db/features/undo-redo.spec.ts +++ b/tests/playwright/tests/db/features/undo-redo.spec.ts @@ -134,13 +134,13 @@ test.describe('Undo Redo', () => { await dashboard.treeView.openTable({ title: 'numberBased' }); // Row.Create - await grid.addNewRow({ index: 10, value: '333', columnHeader: 'Number', networkValidation: true }); - await grid.addNewRow({ index: 11, value: '444', columnHeader: 'Number', networkValidation: true }); + await grid.addNewRow({ index: 10, value: '333', columnHeader: 'Number' }); + await grid.addNewRow({ index: 11, value: '444', columnHeader: 'Number' }); await verifyRecords([333, 444]); // Row.Update - await grid.editRow({ index: 10, value: '555', columnHeader: 'Number', networkValidation: true }); - await grid.editRow({ index: 11, value: '666', columnHeader: 'Number', networkValidation: true }); + await grid.editRow({ index: 10, value: '555', columnHeader: 'Number' }); + await grid.editRow({ index: 11, value: '666', columnHeader: 'Number' }); await verifyRecords([555, 666]); // Row.Delete