Skip to content

Commit 2b237e3

Browse files
committed
chore: Add new test helpers.
1 parent 754193e commit 2b237e3

File tree

5 files changed

+68
-59
lines changed

5 files changed

+68
-59
lines changed

test/webdriverio/test/actions_test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
tabNavigateToWorkspace,
1515
testFileLocations,
1616
testSetup,
17+
keyRight,
1718
} from './test_setup.js';
1819

1920
suite('Menus test', function () {
@@ -46,7 +47,7 @@ suite('Menus test', function () {
4647
// Navigate to a toolbox category
4748
await moveToToolboxCategory(this.browser, 'Functions');
4849
// Move to flyout.
49-
await this.browser.keys(Key.ArrowRight);
50+
await keyRight(this.browser);
5051
await this.browser.keys([Key.Ctrl, Key.Return]);
5152
await this.browser.pause(PAUSE_TIME);
5253

test/webdriverio/test/basic_test.ts

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import {
1717
testFileLocations,
1818
PAUSE_TIME,
1919
tabNavigateToWorkspace,
20+
keyLeft,
21+
keyRight,
22+
keyUp,
23+
keyDown,
2024
} from './test_setup.js';
2125
import {Key} from 'webdriverio';
2226

@@ -40,10 +44,7 @@ suite('Keyboard navigation on Blocks', function () {
4044
test('Selected block', async function () {
4145
await tabNavigateToWorkspace(this.browser);
4246

43-
for (let i = 0; i < 14; i++) {
44-
await this.browser.keys(Key.ArrowDown);
45-
await this.browser.pause(PAUSE_TIME);
46-
}
47+
await keyDown(this.browser, 14);
4748

4849
chai
4950
.expect(await getCurrentFocusedBlockId(this.browser))
@@ -55,8 +56,7 @@ suite('Keyboard navigation on Blocks', function () {
5556
await this.browser.pause(PAUSE_TIME);
5657
await focusOnBlock(this.browser, 'p5_canvas_1');
5758
await this.browser.pause(PAUSE_TIME);
58-
await this.browser.keys(Key.ArrowDown);
59-
await this.browser.pause(PAUSE_TIME);
59+
await keyDown(this.browser);
6060

6161
chai
6262
.expect(await getCurrentFocusedBlockId(this.browser))
@@ -68,8 +68,7 @@ suite('Keyboard navigation on Blocks', function () {
6868
await this.browser.pause(PAUSE_TIME);
6969
await focusOnBlock(this.browser, 'simple_circle_1');
7070
await this.browser.pause(PAUSE_TIME);
71-
await this.browser.keys(Key.ArrowUp);
72-
await this.browser.pause(PAUSE_TIME);
71+
await keyUp(this.browser);
7372

7473
chai
7574
.expect(await getCurrentFocusedBlockId(this.browser))
@@ -81,8 +80,7 @@ suite('Keyboard navigation on Blocks', function () {
8180
await this.browser.pause(PAUSE_TIME);
8281
await focusOnBlock(this.browser, 'p5_setup_1');
8382
await this.browser.pause(PAUSE_TIME);
84-
await this.browser.keys(Key.ArrowDown);
85-
await this.browser.pause(PAUSE_TIME);
83+
await keyDown(this.browser);
8684
chai
8785
.expect(await getCurrentFocusedBlockId(this.browser))
8886
.equal('p5_canvas_1');
@@ -93,8 +91,7 @@ suite('Keyboard navigation on Blocks', function () {
9391
await this.browser.pause(PAUSE_TIME);
9492
await focusOnBlock(this.browser, 'p5_canvas_1');
9593
await this.browser.pause(PAUSE_TIME);
96-
await this.browser.keys(Key.ArrowUp);
97-
await this.browser.pause(PAUSE_TIME);
94+
await keyUp(this.browser);
9895
chai
9996
.expect(await getCurrentFocusedBlockId(this.browser))
10097
.equal('p5_setup_1');
@@ -105,8 +102,7 @@ suite('Keyboard navigation on Blocks', function () {
105102
await this.browser.pause(PAUSE_TIME);
106103
await focusOnBlock(this.browser, 'p5_canvas_1');
107104
await this.browser.pause(PAUSE_TIME);
108-
await this.browser.keys(Key.ArrowRight);
109-
await this.browser.pause(PAUSE_TIME);
105+
await keyRight(this.browser);
110106

111107
chai
112108
.expect(await getCurrentFocusNodeId(this.browser))
@@ -120,8 +116,7 @@ suite('Keyboard navigation on Blocks', function () {
120116
await this.browser.pause(PAUSE_TIME);
121117
await focusOnBlock(this.browser, 'simple_circle_1');
122118
await this.browser.pause(PAUSE_TIME);
123-
await this.browser.keys(Key.ArrowRight);
124-
await this.browser.pause(PAUSE_TIME);
119+
await keyRight(this.browser);
125120

126121
chai.assert.equal(
127122
await getCurrentFocusedBlockId(this.browser),
@@ -134,8 +129,7 @@ suite('Keyboard navigation on Blocks', function () {
134129
await this.browser.pause(PAUSE_TIME);
135130
await focusOnBlock(this.browser, 'math_number_2');
136131
await this.browser.pause(PAUSE_TIME);
137-
await this.browser.keys(Key.ArrowUp);
138-
await this.browser.pause(PAUSE_TIME);
132+
await keyUp(this.browser);
139133

140134
chai.assert.equal(
141135
await getCurrentFocusedBlockId(this.browser),
@@ -148,8 +142,7 @@ suite('Keyboard navigation on Blocks', function () {
148142
await this.browser.pause(PAUSE_TIME);
149143
await focusOnBlock(this.browser, 'math_number_2');
150144
await this.browser.pause(PAUSE_TIME);
151-
await this.browser.keys(Key.ArrowLeft);
152-
await this.browser.pause(PAUSE_TIME);
145+
await keyLeft(this.browser);
153146

154147
chai.assert.equal(
155148
await getCurrentFocusedBlockId(this.browser),
@@ -162,8 +155,7 @@ suite('Keyboard navigation on Blocks', function () {
162155
await this.browser.pause(PAUSE_TIME);
163156
await focusOnBlock(this.browser, 'math_number_2');
164157
await this.browser.pause(PAUSE_TIME);
165-
await this.browser.keys(Key.ArrowRight);
166-
await this.browser.pause(PAUSE_TIME);
158+
await keyRight(this.browser);
167159

168160
chai.assert.equal(
169161
await getCurrentFocusedBlockId(this.browser),
@@ -176,8 +168,7 @@ suite('Keyboard navigation on Blocks', function () {
176168
await this.browser.pause(PAUSE_TIME);
177169
await focusOnBlock(this.browser, 'math_number_3');
178170
await this.browser.pause(PAUSE_TIME);
179-
await this.browser.keys(Key.ArrowLeft);
180-
await this.browser.pause(PAUSE_TIME);
171+
await keyLeft(this.browser);
181172

182173
chai.assert.equal(
183174
await getCurrentFocusedBlockId(this.browser),
@@ -190,8 +181,7 @@ suite('Keyboard navigation on Blocks', function () {
190181
await this.browser.pause(PAUSE_TIME);
191182
await focusOnBlock(this.browser, 'colour_picker_1');
192183
await this.browser.pause(PAUSE_TIME);
193-
await this.browser.keys(Key.ArrowRight);
194-
await this.browser.pause(PAUSE_TIME);
184+
await keyRight(this.browser);
195185

196186
chai
197187
.expect(await getCurrentFocusedBlockId(this.browser))
@@ -203,8 +193,7 @@ suite('Keyboard navigation on Blocks', function () {
203193
await this.browser.pause(PAUSE_TIME);
204194
await focusOnBlock(this.browser, 'colour_picker_1');
205195
await this.browser.pause(PAUSE_TIME);
206-
await this.browser.keys(Key.ArrowDown);
207-
await this.browser.pause(PAUSE_TIME);
196+
await keyDown(this.browser);
208197

209198
chai
210199
.expect(await getCurrentFocusedBlockId(this.browser))
@@ -216,8 +205,7 @@ suite('Keyboard navigation on Blocks', function () {
216205
await this.browser.pause(PAUSE_TIME);
217206
await focusOnBlock(this.browser, 'logic_boolean_1');
218207
await this.browser.pause(PAUSE_TIME);
219-
await this.browser.keys(Key.ArrowDown);
220-
await this.browser.pause(PAUSE_TIME);
208+
await keyDown(this.browser);
221209

222210
chai
223211
.expect(await getCurrentFocusedBlockId(this.browser))
@@ -229,20 +217,17 @@ suite('Keyboard navigation on Blocks', function () {
229217
await this.browser.pause(PAUSE_TIME);
230218
await focusOnBlock(this.browser, 'text_print_1');
231219
await this.browser.pause(PAUSE_TIME);
232-
await this.browser.keys(Key.ArrowRight);
233-
await this.browser.pause(PAUSE_TIME);
220+
await keyRight(this.browser);
234221

235222
chai.assert.equal(await getCurrentFocusedBlockId(this.browser), 'text_1');
236223

237-
await this.browser.keys(Key.ArrowRight);
238-
await this.browser.pause(PAUSE_TIME);
224+
await keyRight(this.browser);
239225

240226
chai
241227
.expect(await getCurrentFocusNodeId(this.browser))
242228
.to.include('text_1_field_');
243229

244-
await this.browser.keys(Key.ArrowRight);
245-
await this.browser.pause(PAUSE_TIME);
230+
await keyRight(this.browser);
246231

247232
chai
248233
.expect(await getCurrentFocusedBlockId(this.browser))
@@ -283,8 +268,7 @@ suite('Keyboard navigation on Fields', function () {
283268
'WIDTH',
284269
);
285270
await this.browser.pause(PAUSE_TIME);
286-
await this.browser.keys(Key.ArrowUp);
287-
await this.browser.pause(PAUSE_TIME);
271+
await keyUp(this.browser);
288272

289273
chai.assert.equal(
290274
await getCurrentFocusedBlockId(this.browser),
@@ -301,8 +285,7 @@ suite('Keyboard navigation on Fields', function () {
301285
'WIDTH',
302286
);
303287
await this.browser.pause(PAUSE_TIME);
304-
await this.browser.keys(Key.ArrowLeft);
305-
await this.browser.pause(PAUSE_TIME);
288+
await keyLeft(this.browser);
306289

307290
chai.assert.equal(
308291
await getCurrentFocusedBlockId(this.browser),
@@ -319,8 +302,7 @@ suite('Keyboard navigation on Fields', function () {
319302
'WIDTH',
320303
);
321304
await this.browser.pause(PAUSE_TIME);
322-
await this.browser.keys(Key.ArrowRight);
323-
await this.browser.pause(PAUSE_TIME);
305+
await keyRight(this.browser);
324306

325307
chai
326308
.expect(await getCurrentFocusNodeId(this.browser))
@@ -338,8 +320,7 @@ suite('Keyboard navigation on Fields', function () {
338320
'HEIGHT',
339321
);
340322
await this.browser.pause(PAUSE_TIME);
341-
await this.browser.keys(Key.ArrowLeft);
342-
await this.browser.pause(PAUSE_TIME);
323+
await keyLeft(this.browser);
343324

344325
chai
345326
.expect(await getCurrentFocusNodeId(this.browser))
@@ -357,8 +338,7 @@ suite('Keyboard navigation on Fields', function () {
357338
'HEIGHT',
358339
);
359340
await this.browser.pause(PAUSE_TIME);
360-
await this.browser.keys(Key.ArrowRight);
361-
await this.browser.pause(PAUSE_TIME);
341+
await keyRight(this.browser);
362342

363343
chai
364344
.expect(await getCurrentFocusedBlockId(this.browser))
@@ -374,8 +354,7 @@ suite('Keyboard navigation on Fields', function () {
374354
'WIDTH',
375355
);
376356
await this.browser.pause(PAUSE_TIME);
377-
await this.browser.keys(Key.ArrowDown);
378-
await this.browser.pause(PAUSE_TIME);
357+
await keyDown(this.browser);
379358

380359
chai
381360
.expect(await getCurrentFocusedBlockId(this.browser))
@@ -391,8 +370,7 @@ suite('Keyboard navigation on Fields', function () {
391370
'TIMES',
392371
);
393372
await this.browser.pause(PAUSE_TIME);
394-
await this.browser.keys(Key.ArrowDown);
395-
await this.browser.pause(PAUSE_TIME);
373+
await keyDown(this.browser);
396374

397375
chai
398376
.expect(await getCurrentFocusedBlockId(this.browser))

test/webdriverio/test/delete_test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
testFileLocations,
1616
PAUSE_TIME,
1717
tabNavigateToWorkspace,
18+
keyRight,
1819
} from './test_setup.js';
1920
import {Key} from 'webdriverio';
2021

@@ -172,8 +173,7 @@ suite('Deleting Blocks', function () {
172173
await moveToToolboxCategory(this.browser, 'Math');
173174
await this.browser.pause(PAUSE_TIME);
174175
// Move to flyout.
175-
await this.browser.keys(Key.ArrowRight);
176-
await this.browser.pause(PAUSE_TIME);
176+
await keyRight(this.browser);
177177
// Select number block.
178178
await this.browser.keys(Key.Enter);
179179
await this.browser.pause(PAUSE_TIME);
@@ -200,8 +200,7 @@ suite('Deleting Blocks', function () {
200200
await moveToToolboxCategory(this.browser, 'Math');
201201
await this.browser.pause(PAUSE_TIME);
202202
// Move to flyout.
203-
await this.browser.keys(Key.ArrowRight);
204-
await this.browser.pause(PAUSE_TIME);
203+
await keyRight(this.browser);
205204
// Select number block.
206205
await this.browser.keys(Key.Enter);
207206
await this.browser.pause(PAUSE_TIME);

test/webdriverio/test/insert_test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
tabNavigateToWorkspace,
1515
testFileLocations,
1616
testSetup,
17+
keyRight,
1718
} from './test_setup.js';
1819

1920
suite('Insert test', function () {
@@ -33,7 +34,7 @@ suite('Insert test', function () {
3334

3435
await moveToToolboxCategory(this.browser, 'Functions');
3536
// Move to flyout.
36-
await this.browser.keys(Key.ArrowRight);
37+
await keyRight(this.browser);
3738
// Select Function block.
3839
await this.browser.keys(Key.Enter);
3940
// Confirm move.

test/webdriverio/test/test_setup.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,7 @@ export async function moveToToolboxCategory(
195195
if (categoryIndex < 0) {
196196
throw new Error(`No category found: ${category}`);
197197
}
198-
if (categoryIndex > 0) {
199-
await browser.keys(webdriverio.Key.ArrowDown.repeat(categoryIndex));
200-
}
198+
if (categoryIndex > 0) await keyDown(browser, categoryIndex);
201199
}
202200

203201
/**
@@ -400,6 +398,8 @@ export async function tabNavigateToWorkspace(
400398
hasToolbox = true,
401399
hasFlyout = true,
402400
) {
401+
// Navigate past the initial pre-injection focusable div element.
402+
tabNavigateForward(browser);
403403
if (hasToolbox) tabNavigateForward(browser);
404404
if (hasFlyout) tabNavigateForward(browser);
405405
tabNavigateForward(browser); // Tab to the workspace itself.
@@ -415,6 +415,36 @@ export async function tabNavigateForward(browser: WebdriverIO.Browser) {
415415
await browser.pause(PAUSE_TIME);
416416
}
417417

418+
export async function tabNavigateBackward(browser: WebdriverIO.Browser) {
419+
await browser.keys([webdriverio.Key.Shift, webdriverio.Key.Tab]);
420+
await browser.pause(PAUSE_TIME);
421+
}
422+
423+
export async function keyLeft(browser: WebdriverIO.Browser, times: number = 1) {
424+
await sendKeyAndWait(browser, webdriverio.Key.ArrowLeft, times);
425+
}
426+
427+
export async function keyRight(
428+
browser: WebdriverIO.Browser, times: number = 1) {
429+
await sendKeyAndWait(browser, webdriverio.Key.ArrowRight, times);
430+
}
431+
432+
export async function keyUp(browser: WebdriverIO.Browser, times: number = 1) {
433+
await sendKeyAndWait(browser, webdriverio.Key.ArrowUp, times);
434+
}
435+
436+
export async function keyDown(browser: WebdriverIO.Browser, times: number = 1) {
437+
await sendKeyAndWait(browser, webdriverio.Key.ArrowDown, times);
438+
}
439+
440+
export async function sendKeyAndWait(
441+
browser: WebdriverIO.Browser, key: string, times: number) {
442+
for (let i = 0; i < times; i++) {
443+
await browser.keys(key);
444+
await browser.pause(PAUSE_TIME);
445+
}
446+
}
447+
418448
/**
419449
* Returns whether there's a drag in progress on the main workspace.
420450
*

0 commit comments

Comments
 (0)