diff --git a/test/webdriverio/test/actions_test.ts b/test/webdriverio/test/actions_test.ts index 7f9b27e2..6b0a86c6 100644 --- a/test/webdriverio/test/actions_test.ts +++ b/test/webdriverio/test/actions_test.ts @@ -14,27 +14,31 @@ import { tabNavigateToWorkspace, testFileLocations, testSetup, + sendKeyAndWait, keyRight, contextMenuItems, } from './test_setup.js'; suite('Menus test', function () { - // Setting timeout to unlimited as these tests take longer time to run - this.timeout(0); + // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run. + if (PAUSE_TIME) this.timeout(0); - // Clear the workspace and load start blocks + // Clear the workspace and load start blocks. setup(async function () { + // This is the first test suite, which must wait for Chrome + + // chromedriver to start up, which can be slow—perhaps a few + // seconds. Allow 30s just in case. + this.timeout(30000); + this.browser = await testSetup(testFileLocations.BASE); await this.browser.pause(PAUSE_TIME); }); test('Menu on block', async function () { // Navigate to draw_circle_1. - await tabNavigateToWorkspace(this.browser); await focusOnBlock(this.browser, 'draw_circle_1'); await this.browser.pause(PAUSE_TIME); - await this.browser.keys([Key.Ctrl, Key.Return]); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, [Key.Ctrl, Key.Return]); chai.assert.deepEqual( process.platform === 'darwin' @@ -70,14 +74,12 @@ suite('Menus test', function () { test('Menu on block in the toolbox', async function () { // Navigate to draw_circle_1. - await tabNavigateToWorkspace(this.browser); await focusOnBlock(this.browser, 'draw_circle_1'); // Navigate to a toolbox category await moveToToolboxCategory(this.browser, 'Functions'); // Move to flyout. await keyRight(this.browser); - await this.browser.keys([Key.Ctrl, Key.Return]); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, [Key.Ctrl, Key.Return]); chai.assert.deepEqual( process.platform === 'darwin' @@ -100,9 +102,8 @@ suite('Menus test', function () { test('Menu on workspace', async function () { // Navigate to draw_circle_1. await tabNavigateToWorkspace(this.browser); - await this.browser.keys('w'); - await this.browser.keys([Key.Ctrl, Key.Return]); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, 'w'); + await sendKeyAndWait(this.browser, [Key.Ctrl, Key.Return]); chai.assert.deepEqual( process.platform === 'darwin' @@ -132,12 +133,11 @@ suite('Menus test', function () { test('Menu on block during drag is not shown', async function () { // Navigate to draw_circle_1. - await tabNavigateToWorkspace(this.browser); await focusOnBlock(this.browser, 'draw_circle_1'); // Start moving the block - await this.browser.keys('m'); - await this.browser.keys([Key.Ctrl, Key.Return]); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, 'm'); + await sendKeyAndWait(this.browser, [Key.Ctrl, Key.Return]); + chai.assert.isTrue( await contextMenuExists(this.browser, 'Collapse Block', true), 'The menu should not be openable during a move', diff --git a/test/webdriverio/test/basic_test.ts b/test/webdriverio/test/basic_test.ts index abfd7dde..98912a38 100644 --- a/test/webdriverio/test/basic_test.ts +++ b/test/webdriverio/test/basic_test.ts @@ -16,6 +16,7 @@ import { testSetup, testFileLocations, PAUSE_TIME, + sendKeyAndWait, tabNavigateToWorkspace, keyLeft, keyRight, @@ -25,10 +26,10 @@ import { import {Key} from 'webdriverio'; suite('Keyboard navigation on Blocks', function () { - // Setting timeout to unlimited as these tests take a longer time to run than most mocha test - this.timeout(0); + // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run. + if (PAUSE_TIME) this.timeout(0); - // Setup Selenium for all of the tests + // Clear the workspace and load start blocks. suiteSetup(async function () { this.browser = await testSetup(testFileLocations.NAVIGATION_TEST_BLOCKS); }); @@ -53,8 +54,6 @@ suite('Keyboard navigation on Blocks', function () { }); test('Down from statement block selects next block across stacks', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'p5_canvas_1'); await this.browser.pause(PAUSE_TIME); await keyDown(this.browser); @@ -65,8 +64,6 @@ suite('Keyboard navigation on Blocks', function () { }); test('Up from statement block selects previous block', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'simple_circle_1'); await this.browser.pause(PAUSE_TIME); await keyUp(this.browser); @@ -77,8 +74,6 @@ suite('Keyboard navigation on Blocks', function () { }); test('Down from parent block selects first child block', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'p5_setup_1'); await this.browser.pause(PAUSE_TIME); await keyDown(this.browser); @@ -88,8 +83,6 @@ suite('Keyboard navigation on Blocks', function () { }); test('Up from child block selects parent block', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'p5_canvas_1'); await this.browser.pause(PAUSE_TIME); await keyUp(this.browser); @@ -99,8 +92,6 @@ suite('Keyboard navigation on Blocks', function () { }); test('Right from block selects first field', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'p5_canvas_1'); await this.browser.pause(PAUSE_TIME); await keyRight(this.browser); @@ -113,8 +104,6 @@ suite('Keyboard navigation on Blocks', function () { }); test('Right from block selects first inline input', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'simple_circle_1'); await this.browser.pause(PAUSE_TIME); await keyRight(this.browser); @@ -126,8 +115,6 @@ suite('Keyboard navigation on Blocks', function () { }); test('Up from inline input selects statement block', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'math_number_2'); await this.browser.pause(PAUSE_TIME); await keyUp(this.browser); @@ -139,8 +126,6 @@ suite('Keyboard navigation on Blocks', function () { }); test('Left from first inline input selects block', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'math_number_2'); await this.browser.pause(PAUSE_TIME); await keyLeft(this.browser); @@ -152,8 +137,6 @@ suite('Keyboard navigation on Blocks', function () { }); test('Right from first inline input selects second inline input', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'math_number_2'); await this.browser.pause(PAUSE_TIME); await keyRight(this.browser); @@ -165,8 +148,6 @@ suite('Keyboard navigation on Blocks', function () { }); test('Left from second inline input selects first inline input', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'math_number_3'); await this.browser.pause(PAUSE_TIME); await keyLeft(this.browser); @@ -178,8 +159,6 @@ suite('Keyboard navigation on Blocks', function () { }); test('Right from last inline input selects next block', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'colour_picker_1'); await this.browser.pause(PAUSE_TIME); await keyRight(this.browser); @@ -190,8 +169,6 @@ suite('Keyboard navigation on Blocks', function () { }); test('Down from inline input selects next block', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'colour_picker_1'); await this.browser.pause(PAUSE_TIME); await keyDown(this.browser); @@ -202,8 +179,6 @@ suite('Keyboard navigation on Blocks', function () { }); test("Down from inline input selects block's child block", async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'logic_boolean_1'); await this.browser.pause(PAUSE_TIME); await keyDown(this.browser); @@ -214,8 +189,6 @@ suite('Keyboard navigation on Blocks', function () { }); test('Right from text block selects shadow block then field', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'text_print_1'); await this.browser.pause(PAUSE_TIME); await keyRight(this.browser); @@ -236,33 +209,27 @@ suite('Keyboard navigation on Blocks', function () { }); test('Losing focus cancels move', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'text_print_1'); - await this.browser.keys('m'); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, 'm'); chai.assert.isTrue(await isDragging(this.browser)); - await this.browser.keys(Key.Tab); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Tab); chai.assert.isFalse(await isDragging(this.browser)); }); }); suite('Keyboard navigation on Fields', function () { - // Setting timeout to unlimited as these tests take a longer time to run than most mocha test - this.timeout(0); + // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run. + if (PAUSE_TIME) this.timeout(0); - // Setup Selenium for all of the tests + // Clear the workspace and load start blocks. suiteSetup(async function () { this.browser = await testSetup(testFileLocations.NAVIGATION_TEST_BLOCKS); }); test('Up from first field selects block', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlockField(this.browser, 'p5_canvas_1', 'WIDTH'); await this.browser.pause(PAUSE_TIME); await keyUp(this.browser); @@ -274,8 +241,6 @@ suite('Keyboard navigation on Fields', function () { }); test('Left from first field selects block', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlockField(this.browser, 'p5_canvas_1', 'WIDTH'); await this.browser.pause(PAUSE_TIME); await keyLeft(this.browser); @@ -287,8 +252,6 @@ suite('Keyboard navigation on Fields', function () { }); test('Right from first field selects second field', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlockField(this.browser, 'p5_canvas_1', 'WIDTH'); await this.browser.pause(PAUSE_TIME); await keyRight(this.browser); @@ -301,8 +264,6 @@ suite('Keyboard navigation on Fields', function () { }); test('Left from second field selects first field', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlockField(this.browser, 'p5_canvas_1', 'HEIGHT'); await this.browser.pause(PAUSE_TIME); await keyLeft(this.browser); @@ -315,8 +276,6 @@ suite('Keyboard navigation on Fields', function () { }); test('Right from second field selects next block', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlockField(this.browser, 'p5_canvas_1', 'HEIGHT'); await this.browser.pause(PAUSE_TIME); await keyRight(this.browser); @@ -327,8 +286,6 @@ suite('Keyboard navigation on Fields', function () { }); test('Down from field selects next block', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlockField(this.browser, 'p5_canvas_1', 'WIDTH'); await this.browser.pause(PAUSE_TIME); await keyDown(this.browser); @@ -339,8 +296,6 @@ suite('Keyboard navigation on Fields', function () { }); test("Down from field selects block's child block", async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlockField(this.browser, 'controls_repeat_1', 'TIMES'); await this.browser.pause(PAUSE_TIME); await keyDown(this.browser); @@ -354,8 +309,7 @@ suite('Keyboard navigation on Fields', function () { // Open a field editor dropdown await focusOnBlockField(this.browser, 'logic_boolean_1', 'BOOL'); await this.browser.pause(PAUSE_TIME); - await this.browser.keys(Key.Enter); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Enter); // Try to navigate to a different block await keyRight(this.browser); @@ -368,13 +322,12 @@ suite('Keyboard navigation on Fields', function () { // Open colour picker await focusOnBlockField(this.browser, 'colour_picker_1', 'COLOUR'); await this.browser.pause(PAUSE_TIME); - await this.browser.keys(Key.Enter); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Enter); // Move right to pick a new colour. await keyRight(this.browser); // Enter to choose. - await this.browser.keys(Key.Enter); + await sendKeyAndWait(this.browser, Key.Enter); // Focus seems to take longer than a single pause to settle. await this.browser.waitUntil( diff --git a/test/webdriverio/test/block_comment_test.ts b/test/webdriverio/test/block_comment_test.ts index e965f3ff..08e7af9e 100644 --- a/test/webdriverio/test/block_comment_test.ts +++ b/test/webdriverio/test/block_comment_test.ts @@ -13,14 +13,15 @@ import { sendKeyAndWait, testFileLocations, keyRight, + PAUSE_TIME, } from './test_setup.js'; import {Key} from 'webdriverio'; suite('Block comment navigation', function () { - // Setting timeout to unlimited as these tests take a longer time to run than most mocha test - this.timeout(0); + // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run. + if (PAUSE_TIME) this.timeout(0); - // Setup Selenium for all of the tests + // Clear the workspace and load start blocks. setup(async function () { this.browser = await testSetup(testFileLocations.NAVIGATION_TEST_BLOCKS); await this.browser.execute(() => { diff --git a/test/webdriverio/test/clipboard_test.ts b/test/webdriverio/test/clipboard_test.ts index b9e9f42e..afe4253a 100644 --- a/test/webdriverio/test/clipboard_test.ts +++ b/test/webdriverio/test/clipboard_test.ts @@ -13,19 +13,19 @@ import { getBlockElementById, getSelectedBlockId, ElementWithId, - tabNavigateToWorkspace, focusOnBlock, focusOnBlockField, blockIsPresent, getFocusedBlockType, + sendKeyAndWait, } from './test_setup.js'; import {Key, KeyAction, PointerAction, WheelAction} from 'webdriverio'; suite('Clipboard test', function () { - // Setting timeout to unlimited as these tests take longer time to run - this.timeout(0); + // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run. + if (PAUSE_TIME) this.timeout(0); - // Clear the workspace and load start blocks + // Clear the workspace and load start blocks. setup(async function () { this.browser = await testSetup(testFileLocations.BASE); await this.browser.pause(PAUSE_TIME); @@ -33,13 +33,11 @@ suite('Clipboard test', function () { test('Copy and paste while block selected', async function () { // Navigate to draw_circle_1. - await tabNavigateToWorkspace(this.browser); await focusOnBlock(this.browser, 'draw_circle_1'); // Copy and paste - await this.browser.keys([Key.Ctrl, 'c']); - await this.browser.keys([Key.Ctrl, 'v']); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, [Key.Ctrl, 'c']); + await sendKeyAndWait(this.browser, [Key.Ctrl, 'v']); const block = await getBlockElementById(this.browser, 'draw_circle_1'); const blocks = await getSameBlocks(this.browser, block); @@ -54,15 +52,13 @@ suite('Clipboard test', function () { test('Cut and paste while block selected', async function () { // Navigate to draw_circle_1. - await tabNavigateToWorkspace(this.browser); await focusOnBlock(this.browser, 'draw_circle_1'); const block = await getBlockElementById(this.browser, 'draw_circle_1'); // Cut and paste - await this.browser.keys([Key.Ctrl, 'x']); + await sendKeyAndWait(this.browser, [Key.Ctrl, 'x']); await block.waitForExist({reverse: true}); - await this.browser.keys([Key.Ctrl, 'v']); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, [Key.Ctrl, 'v']); const focusedType = await getFocusedBlockType(this.browser); @@ -117,11 +113,10 @@ suite('Clipboard test', function () { // Open a field editor await focusOnBlockField(this.browser, 'draw_circle_1_color', 'COLOUR'); await this.browser.pause(PAUSE_TIME); - await this.browser.keys(Key.Enter); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Enter); // Try to cut block while field editor is open - await this.browser.keys([Key.Ctrl, 'x']); + await sendKeyAndWait(this.browser, [Key.Ctrl, 'x']); // Block is not deleted chai.assert.isTrue( diff --git a/test/webdriverio/test/delete_test.ts b/test/webdriverio/test/delete_test.ts index 8564fabd..0503b45b 100644 --- a/test/webdriverio/test/delete_test.ts +++ b/test/webdriverio/test/delete_test.ts @@ -15,23 +15,23 @@ import { testFileLocations, PAUSE_TIME, tabNavigateToWorkspace, + sendKeyAndWait, keyRight, focusOnBlockField, } from './test_setup.js'; import {Key} from 'webdriverio'; suite('Deleting Blocks', function () { - // Setting timeout to unlimited as these tests take a longer time to run than most mocha test - this.timeout(0); + // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run. + if (PAUSE_TIME) this.timeout(0); + // Clear the workspace and load start blocks. setup(async function () { this.browser = await testSetup(testFileLocations.NAVIGATION_TEST_BLOCKS); await this.browser.pause(PAUSE_TIME); }); test('Deleting block selects parent block', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'controls_if_2'); await this.browser.pause(PAUSE_TIME); @@ -39,8 +39,7 @@ suite('Deleting Blocks', function () { .expect(await blockIsPresent(this.browser, 'controls_if_2')) .equal(true); - await this.browser.keys(Key.Backspace); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Backspace); chai .expect(await blockIsPresent(this.browser, 'controls_if_2')) @@ -52,8 +51,6 @@ suite('Deleting Blocks', function () { }); test('Cutting block selects parent block', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'controls_if_2'); await this.browser.pause(PAUSE_TIME); @@ -61,8 +58,7 @@ suite('Deleting Blocks', function () { .expect(await blockIsPresent(this.browser, 'controls_if_2')) .equal(true); - await this.browser.keys([Key.Ctrl, 'x']); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, [Key.Ctrl, 'x']); chai .expect(await blockIsPresent(this.browser, 'controls_if_2')) @@ -74,8 +70,6 @@ suite('Deleting Blocks', function () { }); test('Deleting block also deletes children and inputs', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'controls_if_2'); await this.browser.pause(PAUSE_TIME); @@ -84,8 +78,7 @@ suite('Deleting Blocks', function () { .equal(true); chai.expect(await blockIsPresent(this.browser, 'text_print_1')).equal(true); - await this.browser.keys(Key.Backspace); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Backspace); chai .expect(await blockIsPresent(this.browser, 'logic_boolean_1')) @@ -96,8 +89,6 @@ suite('Deleting Blocks', function () { }); test('Cutting block also removes children and inputs', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'controls_if_2'); await this.browser.pause(PAUSE_TIME); @@ -106,8 +97,7 @@ suite('Deleting Blocks', function () { .equal(true); chai.expect(await blockIsPresent(this.browser, 'text_print_1')).equal(true); - await this.browser.keys([Key.Ctrl, 'x']); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, [Key.Ctrl, 'x']); chai .expect(await blockIsPresent(this.browser, 'logic_boolean_1')) @@ -118,8 +108,6 @@ suite('Deleting Blocks', function () { }); test('Deleting inline input selects parent block', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'logic_boolean_1'); await this.browser.pause(PAUSE_TIME); @@ -127,8 +115,7 @@ suite('Deleting Blocks', function () { .expect(await blockIsPresent(this.browser, 'logic_boolean_1')) .equal(true); - await this.browser.keys(Key.Backspace); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Backspace); chai .expect(await blockIsPresent(this.browser, 'logic_boolean_1')) @@ -140,8 +127,6 @@ suite('Deleting Blocks', function () { }); test('Cutting inline input selects parent block', async function () { - await tabNavigateToWorkspace(this.browser); - await this.browser.pause(PAUSE_TIME); await focusOnBlock(this.browser, 'logic_boolean_1'); await this.browser.pause(PAUSE_TIME); @@ -149,8 +134,7 @@ suite('Deleting Blocks', function () { .expect(await blockIsPresent(this.browser, 'logic_boolean_1')) .equal(true); - await this.browser.keys([Key.Ctrl, 'x']); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, [Key.Ctrl, 'x']); chai .expect(await blockIsPresent(this.browser, 'logic_boolean_1')) @@ -176,16 +160,13 @@ suite('Deleting Blocks', function () { // Move to flyout. await keyRight(this.browser); // Select number block. - await this.browser.keys(Key.Enter); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Enter); // Confirm move. - await this.browser.keys(Key.Enter); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Enter); chai.assert.equal('math_number', await getFocusedBlockType(this.browser)); - await this.browser.keys(Key.Backspace); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Backspace); chai.assert.equal( await getCurrentFocusedBlockId(this.browser), @@ -203,16 +184,13 @@ suite('Deleting Blocks', function () { // Move to flyout. await keyRight(this.browser); // Select number block. - await this.browser.keys(Key.Enter); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Enter); // Confirm move. - await this.browser.keys(Key.Enter); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Enter); chai.assert.equal('math_number', await getFocusedBlockType(this.browser)); - await this.browser.keys([Key.Ctrl, 'x']); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, [Key.Ctrl, 'x']); chai.assert.equal( await getCurrentFocusedBlockId(this.browser), @@ -224,11 +202,10 @@ suite('Deleting Blocks', function () { // Open a field editor await focusOnBlockField(this.browser, 'colour_picker_1', 'COLOUR'); await this.browser.pause(PAUSE_TIME); - await this.browser.keys(Key.Enter); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Enter); // Try to delete block while field editor is open - await this.browser.keys(Key.Backspace); + await sendKeyAndWait(this.browser, Key.Backspace); // Block is not deleted chai.assert.isTrue(await blockIsPresent(this.browser, 'colour_picker_1')); diff --git a/test/webdriverio/test/duplicate_test.ts b/test/webdriverio/test/duplicate_test.ts index 2cef7808..93e33a4c 100644 --- a/test/webdriverio/test/duplicate_test.ts +++ b/test/webdriverio/test/duplicate_test.ts @@ -14,13 +14,14 @@ import { tabNavigateToWorkspace, testFileLocations, testSetup, + sendKeyAndWait, } from './test_setup.js'; suite('Duplicate test', function () { - // Setting timeout to unlimited as these tests take longer time to run - this.timeout(0); + // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run. + if (PAUSE_TIME) this.timeout(0); - // Clear the workspace and load start blocks + // Clear the workspace and load start blocks. setup(async function () { this.browser = await testSetup(testFileLocations.BASE); await this.browser.pause(PAUSE_TIME); @@ -32,8 +33,7 @@ suite('Duplicate test', function () { await focusOnBlock(this.browser, 'draw_circle_1'); // Duplicate - await this.browser.keys('d'); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, 'd'); // Check a different block of the same type has focus. chai.assert.notEqual( @@ -65,7 +65,7 @@ suite('Duplicate test', function () { await this.browser.pause(PAUSE_TIME); // Duplicate. - await this.browser.keys('d'); + await sendKeyAndWait(this.browser, 'd'); // Assert we have two comments with the same text. const commentTexts = await this.browser.execute(() => diff --git a/test/webdriverio/test/flyout_test.ts b/test/webdriverio/test/flyout_test.ts index b6beacf8..769a895b 100644 --- a/test/webdriverio/test/flyout_test.ts +++ b/test/webdriverio/test/flyout_test.ts @@ -14,13 +14,17 @@ import { keyDown, tabNavigateBackward, tabNavigateToWorkspace, + sendKeyAndWait, keyRight, getCurrentFocusNodeId, getCurrentFocusedBlockId, } from './test_setup.js'; suite('Toolbox and flyout test', function () { - // Clear the workspace and load start blocks + // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run. + if (PAUSE_TIME) this.timeout(0); + + // Clear the workspace and load start blocks. setup(async function () { this.browser = await testSetup(testFileLocations.BASE); await this.browser.pause(PAUSE_TIME); @@ -164,7 +168,7 @@ suite('Toolbox and flyout test', function () { test('Tabbing to the workspace after selecting flyout block via workspace toolbox shortcut should close the flyout', async function () { await tabNavigateToWorkspace(this.browser); - await this.browser.keys('t'); + await sendKeyAndWait(this.browser, 't'); await keyRight(this.browser); await tabNavigateForward(this.browser); diff --git a/test/webdriverio/test/insert_test.ts b/test/webdriverio/test/insert_test.ts index 7563f65e..e2305f97 100644 --- a/test/webdriverio/test/insert_test.ts +++ b/test/webdriverio/test/insert_test.ts @@ -14,6 +14,7 @@ import { tabNavigateToWorkspace, testFileLocations, testSetup, + sendKeyAndWait, keyRight, getCurrentFocusedBlockId, blockIsPresent, @@ -22,10 +23,10 @@ import { } from './test_setup.js'; suite('Insert test', function () { - // Setting timeout to unlimited as these tests take longer time to run - this.timeout(0); + // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run. + if (PAUSE_TIME) this.timeout(0); - // Clear the workspace and load start blocks + // Clear the workspace and load start blocks. setup(async function () { this.browser = await testSetup(testFileLocations.BASE); await this.browser.pause(PAUSE_TIME); @@ -36,15 +37,15 @@ suite('Insert test', function () { await tabNavigateToWorkspace(this.browser); await focusOnBlock(this.browser, 'draw_circle_1'); // Insert 'if' block - await this.browser.keys('t'); + await sendKeyAndWait(this.browser, 't'); await keyRight(this.browser); - await this.browser.keys(Key.Enter); + await sendKeyAndWait(this.browser, Key.Enter); chai.assert.equal('controls_if', await getFocusedBlockType(this.browser)); const ifId = await getCurrentFocusedBlockId(this.browser); chai.assert.ok(ifId); // Cancel - await this.browser.keys(Key.Escape); + await sendKeyAndWait(this.browser, Key.Escape); chai.assert.isFalse(await blockIsPresent(this.browser, ifId)); }); @@ -52,17 +53,17 @@ suite('Insert test', function () { test('Insert and cancel with workspace selection', async function () { // Navigate to workspace. await tabNavigateToWorkspace(this.browser); - await this.browser.keys('w'); + await sendKeyAndWait(this.browser, 'w'); // Insert 'if' block - await this.browser.keys('t'); + await sendKeyAndWait(this.browser, 't'); await keyRight(this.browser); - await this.browser.keys(Key.Enter); + await sendKeyAndWait(this.browser, Key.Enter); chai.assert.equal('controls_if', await getFocusedBlockType(this.browser)); const ifId = await getCurrentFocusedBlockId(this.browser); chai.assert.ok(ifId); // Cancel - await this.browser.keys(Key.Escape); + await sendKeyAndWait(this.browser, Key.Escape); chai.assert.isFalse(await blockIsPresent(this.browser, ifId)); }); @@ -76,9 +77,9 @@ suite('Insert test', function () { // Move to flyout. await keyRight(this.browser); // Select Function block. - await this.browser.keys(Key.Enter); + await sendKeyAndWait(this.browser, Key.Enter); // Confirm move. - await this.browser.keys(Key.Enter); + await sendKeyAndWait(this.browser, Key.Enter); chai.assert.equal( 'procedures_defnoreturn', @@ -92,9 +93,9 @@ suite('Insert test', function () { // Insert 'if' block await keyRight(this.browser); // Choose. - await this.browser.keys(Key.Enter); + await sendKeyAndWait(this.browser, Key.Enter); // Confirm position. - await this.browser.keys(Key.Enter); + await sendKeyAndWait(this.browser, Key.Enter); // Assert inserted inside first block p5_setup not at top-level. chai.assert.equal('controls_if', await getFocusedBlockType(this.browser)); diff --git a/test/webdriverio/test/keyboard_mode_test.ts b/test/webdriverio/test/keyboard_mode_test.ts index d022c69a..8a362182 100644 --- a/test/webdriverio/test/keyboard_mode_test.ts +++ b/test/webdriverio/test/keyboard_mode_test.ts @@ -14,6 +14,7 @@ import { getBlockElementById, tabNavigateToWorkspace, clickBlock, + sendKeyAndWait, } from './test_setup.js'; import {Key} from 'webdriverio'; @@ -26,8 +27,8 @@ const isKeyboardNavigating = function (browser: WebdriverIO.Browser) { suite( 'Keyboard navigation mode set on mouse or keyboard interaction', function () { - // Setting timeout to unlimited as these tests take a longer time to run than most mocha tests - this.timeout(0); + // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run. + if (PAUSE_TIME) this.timeout(0); setup(async function () { // Reload the page between tests @@ -46,8 +47,7 @@ suite( test('T to open toolbox enables keyboard mode', async function () { await this.browser.pause(PAUSE_TIME); - await this.browser.keys('t'); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, 't'); chai.assert.isTrue(await isKeyboardNavigating(this.browser)); }); @@ -55,15 +55,14 @@ suite( test('M for move mode enables keyboard mode', async function () { await focusOnBlock(this.browser, 'controls_if_2'); await this.browser.pause(PAUSE_TIME); - await this.browser.keys('m'); + await sendKeyAndWait(this.browser, 'm'); chai.assert.isTrue(await isKeyboardNavigating(this.browser)); }); test('W for workspace cursor enables keyboard mode', async function () { await this.browser.pause(PAUSE_TIME); - await this.browser.keys('w'); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, 'w'); chai.assert.isTrue(await isKeyboardNavigating(this.browser)); }); @@ -71,8 +70,7 @@ suite( test('X to disconnect enables keyboard mode', async function () { await focusOnBlock(this.browser, 'controls_if_2'); await this.browser.pause(PAUSE_TIME); - await this.browser.keys('x'); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, 'x'); chai.assert.isTrue(await isKeyboardNavigating(this.browser)); }); @@ -81,8 +79,7 @@ suite( // Make sure we're on a copyable block so that copy occurs await focusOnBlock(this.browser, 'controls_if_2'); await this.browser.pause(PAUSE_TIME); - await this.browser.keys([Key.Ctrl, 'c']); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, [Key.Ctrl, 'c']); chai.assert.isFalse(await isKeyboardNavigating(this.browser)); @@ -91,8 +88,7 @@ suite( }); await this.browser.pause(PAUSE_TIME); - await this.browser.keys([Key.Ctrl, 'c']); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, [Key.Ctrl, 'c']); chai.assert.isTrue(await isKeyboardNavigating(this.browser)); }); @@ -101,8 +97,7 @@ suite( // Make sure we're on a deletable block so that delete occurs await focusOnBlock(this.browser, 'controls_if_2'); await this.browser.pause(PAUSE_TIME); - await this.browser.keys(Key.Backspace); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Backspace); chai.assert.isFalse(await isKeyboardNavigating(this.browser)); @@ -113,8 +108,7 @@ suite( // Focus a different deletable block await focusOnBlock(this.browser, 'controls_if_1'); await this.browser.pause(PAUSE_TIME); - await this.browser.keys(Key.Backspace); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Backspace); chai.assert.isTrue(await isKeyboardNavigating(this.browser)); }); diff --git a/test/webdriverio/test/move_test.ts b/test/webdriverio/test/move_test.ts index 3a603e26..9de0ee19 100644 --- a/test/webdriverio/test/move_test.ts +++ b/test/webdriverio/test/move_test.ts @@ -18,10 +18,11 @@ import { } from './test_setup.js'; suite('Move tests', function () { - // Setting timeout to unlimited as these tests take longer time to run - this.timeout(0); + // Increase timeout to 10s for this longer test (but disable + // timeouts if when non-zero PAUSE_TIME is used to watch tests) run. + this.timeout(PAUSE_TIME ? 0 : 10000); - // Clear the workspace and load start blocks + // Clear the workspace and load start blocks. setup(async function () { this.browser = await testSetup(testFileLocations.MOVE_TEST_BLOCKS); await this.browser.pause(PAUSE_TIME); @@ -50,7 +51,7 @@ suite('Move tests', function () { chai.assert(info.nextId, 'selected block has no next block'); // Start move. - await this.browser.keys('m'); + await sendKeyAndWait(this.browser, 'm'); // Check that the moving block has nothing connected it its // next/previous connections, and same thing connected to value @@ -85,7 +86,7 @@ suite('Move tests', function () { ); // Abort move. - await this.browser.keys(Key.Escape); + await sendKeyAndWait(this.browser, Key.Escape); } }); @@ -110,7 +111,7 @@ suite('Move tests', function () { chai.assert(info.valueId, 'selected block has no child value block'); // Start move. - await this.browser.keys('m'); + await sendKeyAndWait(this.browser, 'm'); // Check that the moving block has nothing connected it its // next/previous connections, and same thing connected to value @@ -144,7 +145,7 @@ suite('Move tests', function () { ); // Abort move. - await this.browser.keys(Key.Escape); + await sendKeyAndWait(this.browser, Key.Escape); } }); @@ -168,7 +169,7 @@ suite('Move tests', function () { await tabNavigateToWorkspace(this.browser); await focusOnBlock(this.browser, BLOCK); const startCoordinate = await getCoordinate(this.browser, BLOCK); - await this.browser.keys('m'); + await sendKeyAndWait(this.browser, 'm'); // Check constrained moves have no effect. await keyDown(this.browser, 5); @@ -201,7 +202,7 @@ suite('Move tests', function () { } // Abort move. - await this.browser.keys(Key.Escape); + await sendKeyAndWait(this.browser, Key.Escape); }); }); diff --git a/test/webdriverio/test/mutator_test.ts b/test/webdriverio/test/mutator_test.ts index 16db298a..3e03c576 100644 --- a/test/webdriverio/test/mutator_test.ts +++ b/test/webdriverio/test/mutator_test.ts @@ -15,16 +15,17 @@ import { testFileLocations, PAUSE_TIME, tabNavigateToWorkspace, + sendKeyAndWait, keyRight, keyDown, } from './test_setup.js'; import {Key} from 'webdriverio'; suite('Mutator navigation', function () { - // Setting timeout to unlimited as these tests take a longer time to run than most mocha test - this.timeout(0); + // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run. + if (PAUSE_TIME) this.timeout(0); - // Setup Selenium for all of the tests + // Clear the workspace and load start blocks. setup(async function () { this.browser = await testSetup(testFileLocations.NAVIGATION_TEST_BLOCKS); this.openMutator = async () => { @@ -35,8 +36,7 @@ suite('Mutator navigation', function () { // Navigate to the mutator icon await keyRight(this.browser); // Activate the icon - await this.browser.keys(Key.Enter); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Enter); }; }); @@ -54,8 +54,7 @@ suite('Mutator navigation', function () { test('Escape dismisses mutator', async function () { await this.openMutator(); - await this.browser.keys(Key.Escape); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Escape); // Main workspace should be the focused tree (since mutator workspace is gone) const mainWorkspaceFocused = await focusedTreeIsMainWorkspace(this.browser); @@ -75,11 +74,9 @@ suite('Mutator navigation', function () { test('Escape in the mutator flyout focuses the mutator workspace', async function () { await this.openMutator(); // Focus the flyout - await this.browser.keys('t'); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, 't'); // Hit escape to return focus to the mutator workspace - await this.browser.keys(Key.Escape); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Escape); // The "if" placeholder block in the mutator should be focused const focusedBlockType = await getFocusedBlockType(this.browser); chai.assert.equal(focusedBlockType, 'controls_if_if'); @@ -87,8 +84,7 @@ suite('Mutator navigation', function () { test('T focuses the mutator flyout', async function () { await this.openMutator(); - await this.browser.keys('t'); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, 't'); // The "else if" block in the mutator flyout should be focused const focusedBlockType = await getFocusedBlockType(this.browser); @@ -97,16 +93,14 @@ suite('Mutator navigation', function () { test('Blocks can be inserted from the mutator flyout', async function () { await this.openMutator(); - await this.browser.keys('t'); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, 't'); // Navigate down to the second block in the flyout await keyDown(this.browser); await this.browser.pause(PAUSE_TIME); // Hit enter to enter insert mode - await this.browser.keys(Key.Enter); - await this.browser.pause(PAUSE_TIME); + await sendKeyAndWait(this.browser, Key.Enter); // Hit enter again to lock it into place on the connection - await this.browser.keys(Key.Enter); + await sendKeyAndWait(this.browser, Key.Enter); const topBlocks = await this.browser.execute(() => { const focusedTree = Blockly.getFocusManager().getFocusedTree(); diff --git a/test/webdriverio/test/scroll_test.ts b/test/webdriverio/test/scroll_test.ts index 305ca31c..ac64b6d8 100644 --- a/test/webdriverio/test/scroll_test.ts +++ b/test/webdriverio/test/scroll_test.ts @@ -8,6 +8,7 @@ import * as Blockly from 'blockly'; import * as chai from 'chai'; import {Key} from 'webdriverio'; import { + sendKeyAndWait, keyDown, keyRight, PAUSE_TIME, @@ -17,25 +18,43 @@ import { } from './test_setup.js'; suite('Scrolling into view', function () { - // Setting timeout to unlimited as these tests take longer time to run - this.timeout(0); + // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run. + if (PAUSE_TIME) this.timeout(0); - // Clear the workspace and load start blocks - setup(async function () { + // Resize browser to provide predictable small window size for scrolling. + // + // N.B. that this is called only one per suite, not once per test. + suiteSetup(async function () { this.browser = await testSetup(testFileLocations.BASE); - // Predictable small window size for scrolling. + this.windowSize = await this.browser.getWindowSize(); await this.browser.setWindowSize(800, 600); await this.browser.pause(PAUSE_TIME); }); + // Restore original browser window size. + suiteTeardown(async function () { + await this.browser.setWindowSize( + this.windowSize.width, + this.windowSize.height, + ); + }); + + // Clear the workspace and load start blocks. + setup(async function () { + await testSetup(testFileLocations.BASE); + }); + test('Insert scrolls new block into view', async function () { + // Increase timeout to 10s for this longer test. + this.timeout(PAUSE_TIME ? 0 : 10000); + await tabNavigateToWorkspace(this.browser); // Separate the two top-level blocks by moving p5_draw_1 further down. await keyDown(this.browser, 3); - await this.browser.keys('m'); - await this.browser.keys([Key.Alt, ...new Array(25).fill(Key.ArrowDown)]); - await this.browser.keys(Key.Enter); + await sendKeyAndWait(this.browser, 'm'); + await sendKeyAndWait(this.browser, [Key.Alt, Key.ArrowDown], 25); + await sendKeyAndWait(this.browser, Key.Enter); // Scroll back up, leaving cursor on the draw block out of the viewport. await this.browser.execute(() => { const workspace = Blockly.getMainWorkspace() as Blockly.WorkspaceSvg; @@ -47,10 +66,9 @@ suite('Scrolling into view', function () { }); // Insert and confirm the test block which should be scrolled into view. - await this.browser.keys('t'); + await sendKeyAndWait(this.browser, 't'); await keyRight(this.browser); - await this.browser.keys(Key.Enter); - await this.browser.keys(Key.Enter); + await sendKeyAndWait(this.browser, Key.Enter, 2); // Assert new block has been scrolled into the viewport. await this.browser.pause(PAUSE_TIME); diff --git a/test/webdriverio/test/stack_navigation.ts b/test/webdriverio/test/stack_navigation.ts index 08c9942f..2699e45d 100644 --- a/test/webdriverio/test/stack_navigation.ts +++ b/test/webdriverio/test/stack_navigation.ts @@ -12,13 +12,11 @@ import { tabNavigateToWorkspace, testFileLocations, testSetup, + sendKeyAndWait, } from './test_setup.js'; suite('Stack navigation', function () { - // Setting timeout to unlimited as these tests take longer time to run - this.timeout(0); - - // Clear the workspace and load start blocks + // Clear the workspace and load start blocks. setup(async function () { this.browser = await testSetup(testFileLocations.COMMENTS); await this.browser.pause(PAUSE_TIME); @@ -30,17 +28,17 @@ suite('Stack navigation', function () { 'p5_setup_1', await getCurrentFocusedBlockId(this.browser), ); - await this.browser.keys('n'); + await sendKeyAndWait(this.browser, 'n'); chai.assert.equal( 'p5_draw_1', await getCurrentFocusedBlockId(this.browser), ); - await this.browser.keys('n'); + await sendKeyAndWait(this.browser, 'n'); chai.assert.equal( 'workspace_comment_1', await getCurrentFocusNodeId(this.browser), ); - await this.browser.keys('n'); + await sendKeyAndWait(this.browser, 'n'); // Looped around. chai.assert.equal( 'p5_setup_1', @@ -54,18 +52,18 @@ suite('Stack navigation', function () { 'p5_setup_1', await getCurrentFocusedBlockId(this.browser), ); - await this.browser.keys('b'); + await sendKeyAndWait(this.browser, 'b'); // Looped to bottom. chai.assert.equal( 'workspace_comment_1', await getCurrentFocusNodeId(this.browser), ); - await this.browser.keys('b'); + await sendKeyAndWait(this.browser, 'b'); chai.assert.equal( 'p5_draw_1', await getCurrentFocusedBlockId(this.browser), ); - await this.browser.keys('b'); + await sendKeyAndWait(this.browser, 'b'); chai.assert.equal( 'p5_setup_1', await getCurrentFocusedBlockId(this.browser), diff --git a/test/webdriverio/test/styling_test.ts b/test/webdriverio/test/styling_test.ts index efa2514b..c2153f27 100644 --- a/test/webdriverio/test/styling_test.ts +++ b/test/webdriverio/test/styling_test.ts @@ -18,10 +18,10 @@ import { import * as chai from 'chai'; suite('Styling test', function () { - // Setting timeout to unlimited as these tests take longer time to run - this.timeout(0); + // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run. + if (PAUSE_TIME) this.timeout(0); - // Clear the workspace and load start blocks + // Clear the workspace and load start blocks. setup(async function () { this.browser = await testSetup(testFileLocations.BASE); await this.browser.pause(PAUSE_TIME); diff --git a/test/webdriverio/test/test_setup.ts b/test/webdriverio/test/test_setup.ts index e5d47aa7..ccba37c1 100644 --- a/test/webdriverio/test/test_setup.ts +++ b/test/webdriverio/test/test_setup.ts @@ -11,9 +11,9 @@ * This file is to be used in the suiteSetup for any automated fuctional test. * * Note: In this file many functions return browser elements that can - * be clicked or otherwise interacted with through Selenium WebDriver. These + * be clicked or otherwise interacted with through WebdriverIO. These * elements are not the raw HTML and SVG elements on the page; they are - * identifiers that Selenium can use to find those elements. + * identifiers that WebdriverIO can use to find those elements. */ import * as Blockly from 'blockly'; @@ -27,16 +27,30 @@ import {fileURLToPath} from 'url'; let driver: webdriverio.Browser | null = null; /** - * The default amount of time to wait during a test. Increase this to make - * tests easier to watch; decrease it to make tests run faster. + * The default amount of time to wait during a test, in ms. Increase + * this to make tests easier to watch; decrease it to make tests run + * faster. + * + * The _test.js files in this directory are set up to disable timeouts + * automatically when PAUSE_TIME is set to a nonzero value via + * + * if (PAUSE_TIME) this.timeout(0); + * + * at the top of each suite. + * + * Tests should pass reliably even with this set to zero; use one of + * the browser.wait* functions if you need your test to wait for + * something to happen after sending input. */ -export const PAUSE_TIME = 50; +export const PAUSE_TIME = 0; /** - * Start up the test page. This should only be done once, to avoid - * constantly popping browser windows open and closed. + * Start up WebdriverIO and load the test page. This should only be + * done once, to avoid constantly popping browser windows open and + * closed. * - * @returns A Promise that resolves to a webdriverIO browser that tests can manipulate. + * @returns A Promise that resolves to a WebdriverIO browser that + * tests can manipulate. */ export async function driverSetup(): Promise { const options = { @@ -68,14 +82,14 @@ export async function driverSetup(): Promise { // https://github.com/google/blockly/issues/5345 for details. options.capabilities['goog:chromeOptions'].args.push('--disable-gpu'); } - // Use Selenium to bring up the page + // Use webdriver to bring up the page console.log('Starting webdriverio...'); driver = await webdriverio.remote(options); return driver; } /** - * End the webdriverIO session. + * End the WebdriverIO session. * * @return A Promise that resolves after the actions have been completed. */ @@ -90,7 +104,8 @@ export async function driverTeardown() { * * @param playgroundUrl The URL to open for the test, which should be * a Blockly playground with a workspace. - * @returns A Promise that resolves to a webdriverIO browser that tests can manipulate. + * @returns A Promise that resolves to a WebdriverIO browser that + * tests can manipulate. */ export async function testSetup( playgroundUrl: string, @@ -440,8 +455,14 @@ export async function tabNavigateToWorkspace( hasToolbox = true, hasFlyout = true, ) { - // Navigate past the initial pre-injection focusable div element. - await tabNavigateForward(browser); + // Move focus to initial pre-injection focusable div element. + // + // Ideally we'd just reset focus state to the state it is in when + // the document initially loads (and then send one tab), but alas + // there's no straightforward way to do that; see + // https://stackoverflow.com/q/51518855/4969945 + await browser.execute(() => document.getElementById('focusableDiv')?.focus()); + // Navigate to workspace. if (hasToolbox) await tabNavigateForward(browser); if (hasFlyout) await tabNavigateForward(browser); await tabNavigateForward(browser); // Tab to the workspace itself. @@ -679,7 +700,7 @@ export async function clickBlock( findableId, ); - // In the test context, get the Webdriverio Element that we've identified. + // In the test context, get the WebdriverIO Element that we've identified. const elem = await browser.$(`#${findableId}`); await elem.click(clickOptions); diff --git a/test/webdriverio/test/toast_test.ts b/test/webdriverio/test/toast_test.ts index cd4721d5..bf774491 100644 --- a/test/webdriverio/test/toast_test.ts +++ b/test/webdriverio/test/toast_test.ts @@ -9,6 +9,10 @@ import * as Blockly from 'blockly/core'; import {PAUSE_TIME, testFileLocations, testSetup} from './test_setup.js'; suite('HTML toasts', function () { + // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run. + if (PAUSE_TIME) this.timeout(0); + + // Clear the workspace and load start blocks. setup(async function () { this.browser = await testSetup(testFileLocations.BASE); await this.browser.pause(PAUSE_TIME); diff --git a/test/webdriverio/test/workspace_comment_test.ts b/test/webdriverio/test/workspace_comment_test.ts index eb882e27..f97ddcde 100644 --- a/test/webdriverio/test/workspace_comment_test.ts +++ b/test/webdriverio/test/workspace_comment_test.ts @@ -19,14 +19,15 @@ import { keyDown, keyUp, contextMenuItems, + PAUSE_TIME, } from './test_setup.js'; import {Key} from 'webdriverio'; suite('Workspace comment navigation', function () { - // Setting timeout to unlimited as these tests take a longer time to run than most mocha test - this.timeout(0); + // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run. + if (PAUSE_TIME) this.timeout(0); - // Setup Selenium for all of the tests + // Clear the workspace and load start blocks. setup(async function () { this.browser = await testSetup(testFileLocations.NAVIGATION_TEST_BLOCKS); [this.commentId1, this.commentId2] = await this.browser.execute(() => {