From 3840468315840ae785168cacf14cd3df15daf315 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 16 Jan 2025 10:29:58 -0800 Subject: [PATCH] fix: Fix the browser tests. --- core/menu.ts | 5 ++++- tests/browser/test/basic_playground_test.mjs | 2 +- tests/browser/test/delete_blocks_test.mjs | 12 ++++++++---- tests/browser/test/procedure_test.mjs | 3 +++ tests/browser/test/test_setup.mjs | 6 +++--- tests/browser/test/workspace_comment_test.mjs | 3 --- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/core/menu.ts b/core/menu.ts index cce7d7bdec..d1c86a8020 100644 --- a/core/menu.ts +++ b/core/menu.ts @@ -264,7 +264,10 @@ export class Menu { if (el) { aria.setState(el, aria.State.ACTIVEDESCENDANT, item.getId()); } - item.getElement()?.scrollIntoView(); + item.getElement()?.scrollIntoView({ + block: 'nearest', + inline: 'start', + }); } } diff --git a/tests/browser/test/basic_playground_test.mjs b/tests/browser/test/basic_playground_test.mjs index 55ff58e4b0..c0a1f89303 100644 --- a/tests/browser/test/basic_playground_test.mjs +++ b/tests/browser/test/basic_playground_test.mjs @@ -137,7 +137,7 @@ suite('Disabling', function () { 110, ); await connect(this.browser, child, 'OUTPUT', parent, 'IF0'); - + await this.browser.pause(PAUSE_TIME); await contextMenuSelect(this.browser, parent, 'Disable Block'); chai.assert.isTrue(await getIsDisabled(this.browser, child.id)); diff --git a/tests/browser/test/delete_blocks_test.mjs b/tests/browser/test/delete_blocks_test.mjs index 27e17054d5..a5df88705c 100644 --- a/tests/browser/test/delete_blocks_test.mjs +++ b/tests/browser/test/delete_blocks_test.mjs @@ -123,10 +123,14 @@ suite('Delete blocks', function (done) { ) .waitForExist({timeout: 2000, reverse: true}); - // Load the start blocks - await this.browser.execute((blocks) => { - Blockly.serialization.workspaces.load(blocks, Blockly.getMainWorkspace()); - }, startBlocks); + // Load the start blocks. This hangs indefinitely if `startBlocks` is + // passed without being stringified. + this.browser.execute((blocks) => { + Blockly.serialization.workspaces.load( + JSON.parse(blocks), + Blockly.getMainWorkspace(), + ); + }, JSON.stringify(startBlocks)); // Wait for there to be a block on the main workspace before continuing (await getBlockElementById(this.browser, firstBlockId)).waitForExist({ timeout: 2000, diff --git a/tests/browser/test/procedure_test.mjs b/tests/browser/test/procedure_test.mjs index 34368c7324..c01eb49561 100644 --- a/tests/browser/test/procedure_test.mjs +++ b/tests/browser/test/procedure_test.mjs @@ -26,6 +26,9 @@ suite('Testing Connecting Blocks', function (done) { // Setup Selenium for all of the tests suiteSetup(async function () { this.browser = await testSetup(testFileLocations.CODE_DEMO); + // Prevent WebDriver from suppressing alerts + // https://github.com/webdriverio/webdriverio/issues/13610#issuecomment-2357768103 + this.browser.on('dialog', (dialog) => {}); }); test('Testing Procedure', async function () { diff --git a/tests/browser/test/test_setup.mjs b/tests/browser/test/test_setup.mjs index 523a5d851f..f07d559adf 100644 --- a/tests/browser/test/test_setup.mjs +++ b/tests/browser/test/test_setup.mjs @@ -254,9 +254,9 @@ export async function getCategory(browser, categoryName) { export async function getNthBlockOfCategory(browser, categoryName, n) { const category = await getCategory(browser, categoryName); await category.click(); - const block = await browser.$( - `.blocklyFlyout .blocklyBlockCanvas > g:nth-child(${3 + n * 2})`, - ); + const block = ( + await browser.$$(`.blocklyFlyout .blocklyBlockCanvas > .blocklyDraggable`) + )[n]; return block; } diff --git a/tests/browser/test/workspace_comment_test.mjs b/tests/browser/test/workspace_comment_test.mjs index 5719948d0e..516523276f 100644 --- a/tests/browser/test/workspace_comment_test.mjs +++ b/tests/browser/test/workspace_comment_test.mjs @@ -5,7 +5,6 @@ */ import * as chai from 'chai'; -import * as sinon from 'sinon'; import {testFileLocations, testSetup} from './test_setup.mjs'; suite('Workspace comments', function () { @@ -20,8 +19,6 @@ suite('Workspace comments', function () { }); teardown(async function () { - sinon.restore(); - await this.browser.execute(() => { Blockly.getMainWorkspace().clear(); });