From 14ddc645fd1fbfebdeab17cf8ca3ebc32e12a938 Mon Sep 17 00:00:00 2001 From: Spoffy Date: Tue, 8 Oct 2024 01:23:14 +0100 Subject: [PATCH 1/5] Makes tests correctly select from widget gallery --- test/getGrist.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/getGrist.ts b/test/getGrist.ts index 18be7d9b..7a2ccad6 100644 --- a/test/getGrist.ts +++ b/test/getGrist.ts @@ -1,7 +1,7 @@ import {ChildProcess, execSync, spawn} from 'child_process'; import FormData from 'form-data'; import fs from 'fs'; -import {driver} from 'mocha-webdriver'; +import { driver, enableDebugCapture } from 'mocha-webdriver'; import fetch from 'node-fetch'; import {GristWebDriverUtils} from 'test/gristWebDriverUtils'; @@ -17,6 +17,8 @@ export function getGrist(): GristUtils { const server = new GristTestServer(); const grist = new GristUtils(server); + enableDebugCapture() + before(async function () { // Server will have started up in a global fixture, we just // need to make sure it is ready. @@ -198,17 +200,16 @@ export class GristUtils extends GristWebDriverUtils { await this.waitForServer(); } - - public async clickWidgetPane() { - const elem = this.driver.find('.test-config-widget-select .test-select-open'); + const elem = this.driver.find('.test-custom-widget-gallery-container'); if (await elem.isPresent()) { await elem.click(); } } public async selectCustomWidget(text: string | RegExp) { - await this.driver.findContent('.test-select-menu li', text).click(); + await this.driver.findContent('.test-custom-widget-gallery-widget', text).click(); + await this.driver.find('.test-custom-widget-gallery-save').click(); await this.waitForServer(); } From a592ebd19b845bc75f1022d6ae42aebfb58b4243 Mon Sep 17 00:00:00 2001 From: Spoffy Date: Tue, 8 Oct 2024 01:24:16 +0100 Subject: [PATCH 2/5] Fixes inspect test looking for wrong widget name --- test/inspect.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/inspect.ts b/test/inspect.ts index 19c7c8de..14bb71f1 100644 --- a/test/inspect.ts +++ b/test/inspect.ts @@ -11,7 +11,7 @@ describe('inspect', function() { await grist.toggleSidePanel('right', 'open'); await grist.addNewSection(/Custom/, /School/, {dismissTips: true}); await grist.clickWidgetPane(); - await grist.selectCustomWidget('Inspect Record'); + await grist.selectCustomWidget('Inspect record'); await grist.setCustomWidgetAccess('full'); await grist.waitToPass(async () => { const txt = await grist.getCustomWidgetBody(); From 72cbaeca331ae635e62d8672b8e2a72848e35527 Mon Sep 17 00:00:00 2001 From: Spoffy Date: Tue, 8 Oct 2024 01:23:55 +0100 Subject: [PATCH 3/5] Increases reliability of prompt dismissal --- test/gristWebDriverUtils.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/test/gristWebDriverUtils.ts b/test/gristWebDriverUtils.ts index 7b2d407a..2f67c6ed 100644 --- a/test/gristWebDriverUtils.ts +++ b/test/gristWebDriverUtils.ts @@ -14,6 +14,17 @@ import escapeRegExp = require('lodash/escapeRegExp'); type SectionTypes = 'Table' | 'Card' | 'Card List' | 'Chart' | 'Custom'; type UserAction = Array; +export async function ignoreMissingElementErrors(callback: () => T): Promise { + try { + return await callback() + } catch (e) { + if (e.name === 'NoSuchElementError' || e.name === 'StaleElementReferenceError') { + return; + } + throw e; + } +} + export class GristWebDriverUtils { public constructor(public driver: WebDriver) { } @@ -145,7 +156,9 @@ export class GristWebDriverUtils { if (options.dismissTips) { await this.dismissBehavioralPrompts(); } if (tableRe) { - const tableEl = driver.findContent('.test-wselect-table', tableRe); + const tableEl = driver.findContentWait('.test-wselect-table', tableRe, 2000); + + if (options.dismissTips) { await this.dismissBehavioralPrompts(); } // unselect all selected columns for (const col of (await driver.findAll('.test-wselect-column[class*=-selected]'))) { @@ -210,8 +223,11 @@ export class GristWebDriverUtils { const max = 10; // Keep dismissing prompts until there are no more, up to a maximum of 10 times. - while (i < max && await this.driver.find('.test-behavioral-prompt').isPresent()) { - await this.driver.find('.test-behavioral-prompt-dismiss').click(); + const getButton = () => { + return this.driver.find('.test-behavioral-prompt-dismiss') + } + while (i < max && await getButton().isPresent()) { + await ignoreMissingElementErrors(() => getButton().click()); await this.waitForServer(); i += 1; } From 71cbbd5f0663812e26d444a648e701fb25adf42d Mon Sep 17 00:00:00 2001 From: Spoffy Date: Tue, 8 Oct 2024 02:30:57 +0100 Subject: [PATCH 4/5] Fixes chart.ts flakiness --- test/chart.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/chart.ts b/test/chart.ts index a6f7275c..eb61def8 100644 --- a/test/chart.ts +++ b/test/chart.ts @@ -44,12 +44,15 @@ describe('chart', function () { await chooseColumnFromFieldDropdown(/Values/, /num/); await chooseColumnFromFieldDropdown(/Labels/, /choice list/); - assert.equal( - await driver.find('.plotly_editor_plot').getText(), + const result = // Percentages inside the pie chart '55.6%\n44.4%\n' + // Legend - 'choice B\nchoice A', + 'choice B\nchoice A'; + + assert.equal( + await driver.findContentWait('.plotly_editor_plot', result, 2000).getText(), + result ); }); }); From d7af5bfe106e14c971455dbe404f2583a8b82df2 Mon Sep 17 00:00:00 2001 From: Spoffy Date: Tue, 12 Nov 2024 13:58:22 +0000 Subject: [PATCH 5/5] Rolls back changes to dismissBehaviouralPrompts --- test/getGrist.ts | 2 +- test/gristWebDriverUtils.ts | 18 ++---------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/test/getGrist.ts b/test/getGrist.ts index 7a2ccad6..f933879f 100644 --- a/test/getGrist.ts +++ b/test/getGrist.ts @@ -17,7 +17,7 @@ export function getGrist(): GristUtils { const server = new GristTestServer(); const grist = new GristUtils(server); - enableDebugCapture() + enableDebugCapture(); before(async function () { // Server will have started up in a global fixture, we just diff --git a/test/gristWebDriverUtils.ts b/test/gristWebDriverUtils.ts index 2f67c6ed..85a573ce 100644 --- a/test/gristWebDriverUtils.ts +++ b/test/gristWebDriverUtils.ts @@ -14,17 +14,6 @@ import escapeRegExp = require('lodash/escapeRegExp'); type SectionTypes = 'Table' | 'Card' | 'Card List' | 'Chart' | 'Custom'; type UserAction = Array; -export async function ignoreMissingElementErrors(callback: () => T): Promise { - try { - return await callback() - } catch (e) { - if (e.name === 'NoSuchElementError' || e.name === 'StaleElementReferenceError') { - return; - } - throw e; - } -} - export class GristWebDriverUtils { public constructor(public driver: WebDriver) { } @@ -223,11 +212,8 @@ export class GristWebDriverUtils { const max = 10; // Keep dismissing prompts until there are no more, up to a maximum of 10 times. - const getButton = () => { - return this.driver.find('.test-behavioral-prompt-dismiss') - } - while (i < max && await getButton().isPresent()) { - await ignoreMissingElementErrors(() => getButton().click()); + while (i < max && await this.driver.find('.test-behavioral-prompt').isPresent()) { + await this.driver.find('.test-behavioral-prompt-dismiss').click(); await this.waitForServer(); i += 1; }