From 6337eeb54f874768b45d47c8810e70486ee9aa56 Mon Sep 17 00:00:00 2001 From: George Gevoian Date: Thu, 2 May 2024 11:32:05 -0400 Subject: [PATCH] (core) Fix flaky tests Summary: The Ace autocomplete sometimes doesn't appear if keys are entered too quickly. A larger fixture document (World) used in the Importer2 tests sometimes takes longer than 5 seconds to import. Test Plan: N/A Reviewers: paulfitz Reviewed By: paulfitz Subscribers: paulfitz Differential Revision: https://phab.getgrist.com/D4245 --- test/nbrowser/DropdownConditionEditor.ts | 6 ++++-- test/nbrowser/Importer2.ts | 2 +- test/nbrowser/gristUtils.ts | 10 ++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/test/nbrowser/DropdownConditionEditor.ts b/test/nbrowser/DropdownConditionEditor.ts index d12527b6..3cf30bb9 100644 --- a/test/nbrowser/DropdownConditionEditor.ts +++ b/test/nbrowser/DropdownConditionEditor.ts @@ -19,6 +19,7 @@ describe('DropdownConditionEditor', function () { await gu.getCell(1, 1).click(); assert.isFalse(await driver.find('.test-field-dropdown-condition').isPresent()); await driver.find('.test-field-set-dropdown-condition').click(); + await gu.waitAppFocus(false); await gu.sendKeys('c'); await gu.waitToPass(async () => { const completions = await driver.findAll('.ace_autocomplete .ace_line', el => el.getText()); @@ -29,7 +30,7 @@ describe('DropdownConditionEditor', function () { 're\nc\n.Supervisor\n ', ]); }); - await gu.sendKeys('hoice not in $'); + await gu.sendKeysSlowly(['hoice not in $']); await gu.waitToPass(async () => { const completions = await driver.findAll('.ace_autocomplete .ace_line', el => el.getText()); assert.deepEqual(completions, [ @@ -144,7 +145,8 @@ describe('DropdownConditionEditor', function () { await gu.getCell(2, 1).click(); assert.isFalse(await driver.find('.test-field-dropdown-condition').isPresent()); await driver.find('.test-field-set-dropdown-condition').click(); - await gu.sendKeys('choice'); + await gu.waitAppFocus(false); + await gu.sendKeysSlowly(['choice']); await gu.waitToPass(async () => { const completions = await driver.findAll('.ace_autocomplete .ace_line', el => el.getText()); assert.deepEqual(completions, [ diff --git a/test/nbrowser/Importer2.ts b/test/nbrowser/Importer2.ts index 5cb9c179..25f5e6c0 100644 --- a/test/nbrowser/Importer2.ts +++ b/test/nbrowser/Importer2.ts @@ -595,7 +595,7 @@ describe('Importer2', function() { // Finish importing, and check that the destination tables have the correct data. await driver.find('.test-modal-confirm').click(); - await gu.waitForServer(); + await gu.waitForServer(10_000); assert.deepEqual(await gu.getPageNames(), [ 'Table1', 'Table1', diff --git a/test/nbrowser/gristUtils.ts b/test/nbrowser/gristUtils.ts index b53faa3a..8a9a0f1b 100644 --- a/test/nbrowser/gristUtils.ts +++ b/test/nbrowser/gristUtils.ts @@ -1751,6 +1751,16 @@ export async function sendKeys(...keys: string[]) { }); } +/** + * Send keys with a pause between each key. + */ +export async function sendKeysSlowly(keys: string[], delayMs = 40) { + for (const [i, key] of keys.entries()) { + await sendKeys(key); + if (i < keys.length - 1) { await driver.sleep(delayMs); } + } +} + /** * Clears active input/textarea. */