Skip to content

Commit 893f6b1

Browse files
committed
fix: webdriverio tests.
Use tab navigation instead of clicking for selection.
1 parent 911d824 commit 893f6b1

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

test/webdriverio/test/basic_test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ import {
1515
testSetup,
1616
testFileLocations,
1717
PAUSE_TIME,
18-
getBlockElementById,
19-
clickBlock,
18+
tabNavigateToWorkspace,
2019
} from './test_setup.js';
21-
import {Key, ClickOptions} from 'webdriverio';
20+
import {Key} from 'webdriverio';
2221

2322
suite('Keyboard navigation', function () {
2423
// Setting timeout to unlimited as these tests take a longer time to run than most mocha test
@@ -38,9 +37,7 @@ suite('Keyboard navigation', function () {
3837
});
3938

4039
test('Selected block', async function () {
41-
const block = await getBlockElementById(this.browser, 'p5_setup_1');
42-
await clickBlock(this.browser, block, {button: 0} as ClickOptions);
43-
await this.browser.pause(PAUSE_TIME);
40+
await tabNavigateToWorkspace(this.browser);
4441

4542
for (let i = 0; i < 8; i++) {
4643
await this.browser.keys(Key.ArrowDown);

test/webdriverio/test/clipboard_test.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,10 @@ import {
1212
PAUSE_TIME,
1313
getBlockElementById,
1414
getSelectedBlockId,
15-
clickBlock,
1615
ElementWithId,
16+
tabNavigateToWorkspace,
1717
} from './test_setup.js';
18-
import {
19-
ClickOptions,
20-
Key,
21-
KeyAction,
22-
PointerAction,
23-
WheelAction,
24-
} from 'webdriverio';
18+
import {Key, KeyAction, PointerAction, WheelAction} from 'webdriverio';
2519

2620
suite('Clipboard test', function () {
2721
// Setting timeout to unlimited as these tests take longer time to run
@@ -34,17 +28,21 @@ suite('Clipboard test', function () {
3428
});
3529

3630
test('Copy and paste while block selected', async function () {
37-
const block = await getBlockElementById(this.browser, 'draw_circle_1');
38-
await clickBlock(this.browser, block, {button: 0} as ClickOptions);
31+
// Navigate to draw_circle_1.
32+
await tabNavigateToWorkspace(this.browser);
33+
for (let i = 0; i < 8; i++) {
34+
await this.browser.keys(Key.ArrowDown);
35+
await this.browser.pause(PAUSE_TIME);
36+
}
3937

4038
// Copy and paste
4139
await this.browser.keys([Key.Ctrl, 'c']);
4240
await this.browser.keys([Key.Ctrl, 'v']);
4341
await this.browser.pause(PAUSE_TIME);
4442

43+
const block = await getBlockElementById(this.browser, 'draw_circle_1');
4544
const blocks = await getSameBlocks(this.browser, block);
4645
const selectedId = await getSelectedBlockId(this.browser);
47-
4846
chai.assert.equal(await blocks.length, 2);
4947
chai.assert.equal(
5048
selectedId,
@@ -54,8 +52,13 @@ suite('Clipboard test', function () {
5452
});
5553

5654
test('Cut and paste while block selected', async function () {
55+
// Navigate to draw_circle_1.
56+
await tabNavigateToWorkspace(this.browser);
57+
for (let i = 0; i < 8; i++) {
58+
await this.browser.keys(Key.ArrowDown);
59+
await this.browser.pause(PAUSE_TIME);
60+
}
5761
const block = await getBlockElementById(this.browser, 'draw_circle_1');
58-
await clickBlock(this.browser, block, {button: 0} as ClickOptions);
5962

6063
// Cut and paste
6164
await this.browser.keys([Key.Ctrl, 'x']);

test/webdriverio/test/test_setup.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,34 @@ export async function getBlockElementById(
260260
return elem;
261261
}
262262

263+
/**
264+
* Uses tabs to navigate to the workspace on the test page (i.e. by going
265+
* through top-level tab stops).
266+
*
267+
* @param browser The active WebdriverIO Browser object.
268+
* @param hasToolbox Whether a toolbox is configured on the test page.
269+
* @param hasFlyout Whether a flyout is configured on the test page.
270+
*/
271+
export async function tabNavigateToWorkspace(
272+
browser: WebdriverIO.Browser,
273+
hasToolbox = true,
274+
hasFlyout = true,
275+
) {
276+
if (hasToolbox) tabNavigateForward(browser);
277+
if (hasFlyout) tabNavigateForward(browser);
278+
tabNavigateForward(browser); // Tab to the workspace itself.
279+
}
280+
281+
/**
282+
* Navigates forward to the test page's next tab stop.
283+
*
284+
* @param browser The active WebdriverIO Browser object.
285+
*/
286+
export async function tabNavigateForward(browser: WebdriverIO.Browser) {
287+
await browser.keys(webdriverio.Key.Tab);
288+
await browser.pause(PAUSE_TIME);
289+
}
290+
263291
/**
264292
* Copied from blockly browser test_setup.mjs and amended for typescript
265293
*

0 commit comments

Comments
 (0)