From 994a0d7905ec79af3658b977c96c8fb7cbf4606c Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:26:24 +0530 Subject: [PATCH] Nc test/flaky fix (#8349) * fix: flaky test * Update index.ts * fix: flaky with addNewRow- replace with APIs * fix: groupby flaky * test: retry attempt for calendar sidebar card count * test: use x button instead of escape to close expand modal * test: fix selected cell count retry * test: fix flaky for cmd K * fix: increase wait time after form submission --- .../Dashboard/Calendar/CalendarSideMenu.ts | 14 +++++--- .../pages/Dashboard/ExpandedForm/index.ts | 2 +- .../playwright/pages/Dashboard/Grid/index.ts | 8 +++++ .../pages/Dashboard/common/Toolbar/Groupby.ts | 13 +++++-- tests/playwright/pages/SharedForm/index.ts | 2 +- .../db/columns/columnMultiSelect.spec.ts | 35 +++++++++++++++---- .../tests/db/features/command.spec.ts | 2 ++ .../tests/db/general/cellSelection.spec.ts | 16 +++++---- 8 files changed, 71 insertions(+), 21 deletions(-) diff --git a/tests/playwright/pages/Dashboard/Calendar/CalendarSideMenu.ts b/tests/playwright/pages/Dashboard/Calendar/CalendarSideMenu.ts index e11d08bd4e..c3202e5fae 100644 --- a/tests/playwright/pages/Dashboard/Calendar/CalendarSideMenu.ts +++ b/tests/playwright/pages/Dashboard/Calendar/CalendarSideMenu.ts @@ -30,10 +30,16 @@ export class CalendarSideMenuPage extends BasePage { } async verifySideBarRecords({ records }: { records: string[] }) { - const sideBar = this.get().getByTestId('nc-calendar-side-menu-list'); - - const sideBarRecords = await sideBar.getByTestId('nc-sidebar-record-card'); - + let attempts = 0; + let sideBarRecords: Locator; + while (attempts++ < 5) { + const sideBar = this.get().getByTestId('nc-calendar-side-menu-list'); + sideBarRecords = sideBar.getByTestId('nc-sidebar-record-card'); + + if ((await sideBarRecords.count()) === records.length) break; + // wait for records to load + await this.rootPage.waitForTimeout(200 * attempts); + } await expect(sideBarRecords).toHaveCount(records.length); for (let i = 0; i < records.length; i++) { diff --git a/tests/playwright/pages/Dashboard/ExpandedForm/index.ts b/tests/playwright/pages/Dashboard/ExpandedForm/index.ts index 1a76a78d59..8ad6d110a1 100644 --- a/tests/playwright/pages/Dashboard/ExpandedForm/index.ts +++ b/tests/playwright/pages/Dashboard/ExpandedForm/index.ts @@ -129,7 +129,7 @@ export class ExpandedFormPage extends BasePage { await this.rootPage.locator('[data-testid="grid-load-spinner"]').waitFor({ state: 'hidden' }); // removing focus from toast await this.rootPage.locator('.nc-modal').click(); - await this.get().press('Escape'); + await this.get().locator('.nc-expanded-form-header').locator('.nc-expand-form-close-btn').click(); await this.get().waitFor({ state: 'hidden' }); } diff --git a/tests/playwright/pages/Dashboard/Grid/index.ts b/tests/playwright/pages/Dashboard/Grid/index.ts index c1998fdf3c..694af15598 100644 --- a/tests/playwright/pages/Dashboard/Grid/index.ts +++ b/tests/playwright/pages/Dashboard/Grid/index.ts @@ -441,6 +441,14 @@ export class GridPage extends BasePage { return this.get().locator('.cell.active').count(); } + async getActiveCell() { + return this.get().locator('.cell.active'); + } + + async verifySelectedCellCount({ count }: { count: number }) { + await expect(this.get().locator('.cell.active')).toHaveCount(count); + } + async copyWithKeyboard() { // retry to avoid flakiness, until text is copied to clipboard // diff --git a/tests/playwright/pages/Dashboard/common/Toolbar/Groupby.ts b/tests/playwright/pages/Dashboard/common/Toolbar/Groupby.ts index c47ae79cc5..dc67552c54 100644 --- a/tests/playwright/pages/Dashboard/common/Toolbar/Groupby.ts +++ b/tests/playwright/pages/Dashboard/common/Toolbar/Groupby.ts @@ -49,8 +49,12 @@ export class ToolbarGroupByPage extends BasePage { .locator(`div[label="${title}"]`) .last() .click(); + + //kludge: wait for rendering to stabilize + await this.rootPage.waitForTimeout(1000); + await this.rootPage.locator('.nc-sort-dir-select').nth(index).waitFor({ state: 'visible' }); - await this.rootPage.locator('.nc-sort-dir-select').nth(index).click(); + await this.rootPage.locator('.nc-sort-dir-select').nth(index).click({ force: true }); await this.rootPage .locator('.nc-dropdown-sort-dir') .last() @@ -139,7 +143,12 @@ export class ToolbarGroupByPage extends BasePage { async remove({ index }: { index: number }) { // open group-by menu await this.toolbar.clickGroupBy(); - await this.rootPage.locator('.nc-group-by-item-remove-btn').nth(index).click(); + + await this.waitForResponse({ + uiAction: () => this.rootPage.locator('.nc-group-by-item-remove-btn').nth(index).click(), + requestUrlPathToMatch: '/api/v1/db/data/noco', + httpMethodsToMatch: ['GET'], + }); // close group-by menu await this.toolbar.clickGroupBy(); diff --git a/tests/playwright/pages/SharedForm/index.ts b/tests/playwright/pages/SharedForm/index.ts index fe98197e5e..fc3fe7115e 100644 --- a/tests/playwright/pages/SharedForm/index.ts +++ b/tests/playwright/pages/SharedForm/index.ts @@ -25,7 +25,7 @@ export class SharedFormPage extends BasePage { } async verifySuccessMessage() { - await this.rootPage.locator('.nc-shared-form-success-msg').waitFor({ state: 'visible' }); + await this.rootPage.locator('.nc-shared-form-success-msg').waitFor({ state: 'visible', timeout: 10000 }); await expect( this.get().locator('.ant-alert-success', { hasText: 'Successfully submitted form data', diff --git a/tests/playwright/tests/db/columns/columnMultiSelect.spec.ts b/tests/playwright/tests/db/columns/columnMultiSelect.spec.ts index 0e63cb3c6a..e4fc5ba98e 100644 --- a/tests/playwright/tests/db/columns/columnMultiSelect.spec.ts +++ b/tests/playwright/tests/db/columns/columnMultiSelect.spec.ts @@ -3,6 +3,8 @@ import { DashboardPage } from '../../../pages/Dashboard'; import { GridPage } from '../../../pages/Dashboard/Grid'; import setup, { unsetup } from '../../../setup'; import { ToolbarPage } from '../../../pages/Dashboard/common/Toolbar'; +import { Api } from 'nocodb-sdk'; +let api: Api; test.describe('Multi select', () => { let dashboard: DashboardPage, grid: GridPage; @@ -206,6 +208,13 @@ test.describe('Multi select - filters', () => { toolbar = dashboard.grid.toolbar; grid = dashboard.grid; + api = new Api({ + baseURL: `http://localhost:8080/`, + headers: { + 'xc-auth': context.token, + }, + }); + await dashboard.treeView.createTable({ title: 'sheet1', baseTitle: context.base.title }); await grid.column.create({ title: 'MultiSelect', type: 'MultiSelect' }); @@ -213,12 +222,26 @@ test.describe('Multi select - filters', () => { columnTitle: 'MultiSelect', options: ['foo', 'bar', 'baz'], }); - await grid.addNewRow({ index: 0, value: '1' }); - await grid.addNewRow({ index: 1, value: '2' }); - await grid.addNewRow({ index: 2, value: '3' }); - await grid.addNewRow({ index: 3, value: '4' }); - await grid.addNewRow({ index: 4, value: '5' }); - await grid.addNewRow({ index: 5, value: '6' }); + + try { + const tables = await api.dbTable.list(context.base.id); + const rowAttributes = []; + for (let i = 0; i < 6; i++) { + const row = { + Id: i + 1, + Title: `${i + 1}`, + }; + rowAttributes.push(row); + } + + const tableId = tables.list.find((table: any) => table.table_name === 'sheet1').id; + await api.dbTableRow.bulkCreate('noco', context.base.id, tableId, rowAttributes); + } catch (e) { + console.error(e); + } + + // page reload + await page.reload(); await grid.cell.selectOption.select({ index: 1, columnHeader: 'MultiSelect', option: 'foo', multiSelect: true }); await grid.cell.selectOption.select({ index: 2, columnHeader: 'MultiSelect', option: 'bar', multiSelect: true }); diff --git a/tests/playwright/tests/db/features/command.spec.ts b/tests/playwright/tests/db/features/command.spec.ts index 6bbefb04e1..62adbd14b7 100644 --- a/tests/playwright/tests/db/features/command.spec.ts +++ b/tests/playwright/tests/db/features/command.spec.ts @@ -46,6 +46,8 @@ test.describe('Command Shortcuts', () => { await dashboard.cmdK.searchText('CustomerList'); + await page.waitForTimeout(1000); + await dashboard.get().locator('.nc-active-view-title').waitFor({ state: 'visible' }); await expect(dashboard.get().locator('.nc-active-view-title')).toContainText('Default View'); await dashboard.signOut(); diff --git a/tests/playwright/tests/db/general/cellSelection.spec.ts b/tests/playwright/tests/db/general/cellSelection.spec.ts index f16cac8144..aeebae1ac2 100644 --- a/tests/playwright/tests/db/general/cellSelection.spec.ts +++ b/tests/playwright/tests/db/general/cellSelection.spec.ts @@ -77,9 +77,9 @@ test.describe('Verify cell selection', () => { start: { index: 0, columnHeader: 'Country' }, end: { index: 2, columnHeader: 'Cities' }, }); - expect(await grid.selectedCount()).toBe(9); + await grid.verifySelectedCellCount({ count: 9 }); await grid.cell.get({ index: 0, columnHeader: 'Country' }).click(); - expect(await grid.selectedCount()).toBe(1); + await grid.verifySelectedCellCount({ count: 1 }); expect(await grid.cell.verifyCellActiveSelected({ index: 0, columnHeader: 'Country' })); await dashboard.closeAllTabs(); @@ -89,9 +89,9 @@ test.describe('Verify cell selection', () => { start: { index: 0, columnHeader: 'Country' }, end: { index: 2, columnHeader: 'Cities' }, }); - expect(await grid.selectedCount()).toBe(9); + await grid.verifySelectedCellCount({ count: 9 }); await grid.cell.get({ index: 5, columnHeader: 'Country' }).click(); - expect(await grid.selectedCount()).toBe(1); + await grid.verifySelectedCellCount({ count: 1 }); expect(await grid.cell.verifyCellActiveSelected({ index: 5, columnHeader: 'Country' })); await dashboard.closeAllTabs(); @@ -102,9 +102,9 @@ test.describe('Verify cell selection', () => { start: { index: 2, columnHeader: 'Cities' }, end: { index: 0, columnHeader: 'Country' }, }); - expect(await grid.selectedCount()).toBe(12); + await grid.verifySelectedCellCount({ count: 12 }); await grid.cell.get({ index: 1, columnHeader: 'Country' }).click(); - expect(await grid.selectedCount()).toBe(1); + await grid.verifySelectedCellCount({ count: 1 }); expect(await grid.cell.verifyCellActiveSelected({ index: 1, columnHeader: 'Country' })); await dashboard.grid.toolbar.fields.toggleShowSystemFields(); await dashboard.closeAllTabs(); @@ -115,8 +115,10 @@ test.describe('Verify cell selection', () => { start: { index: 0, columnHeader: 'Country' }, end: { index: 2, columnHeader: 'Cities' }, }); + await grid.verifySelectedCellCount({ count: 9 }); + await grid.rootPage.waitForTimeout(100); await page.keyboard.press('ArrowRight'); - expect(await grid.selectedCount()).toBe(1); + await grid.verifySelectedCellCount({ count: 1 }); expect(await grid.cell.verifyCellActiveSelected({ index: 0, columnHeader: 'LastUpdate' })); await dashboard.closeAllTabs(); });