Skip to content

Commit 0d726a2

Browse files
committed
refactor(tests): Use sendKeyAndWait where appropriate
In most places we were already following browser.keys with a browser.pause(PAUSE_TIME), so using sendKeysAndWait is more succinct; in other places we didn't have the pause but it is not harmful to add a pause (especially now the default PAUSE_TIME is zero) and could be helpful when watching tests run with a non-zero PAUSE_TIME.
1 parent f105370 commit 0d726a2

File tree

12 files changed

+90
-118
lines changed

12 files changed

+90
-118
lines changed

test/webdriverio/test/actions_test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
tabNavigateToWorkspace,
1515
testFileLocations,
1616
testSetup,
17+
sendKeyAndWait,
1718
keyRight,
1819
contextMenuItems,
1920
} from './test_setup.js';
@@ -33,8 +34,7 @@ suite('Menus test', function () {
3334
await tabNavigateToWorkspace(this.browser);
3435
await focusOnBlock(this.browser, 'draw_circle_1');
3536
await this.browser.pause(PAUSE_TIME);
36-
await this.browser.keys([Key.Ctrl, Key.Return]);
37-
await this.browser.pause(PAUSE_TIME);
37+
await sendKeyAndWait(this.browser, [Key.Ctrl, Key.Return]);
3838

3939
chai.assert.deepEqual(
4040
process.platform === 'darwin'
@@ -76,8 +76,7 @@ suite('Menus test', function () {
7676
await moveToToolboxCategory(this.browser, 'Functions');
7777
// Move to flyout.
7878
await keyRight(this.browser);
79-
await this.browser.keys([Key.Ctrl, Key.Return]);
80-
await this.browser.pause(PAUSE_TIME);
79+
await sendKeyAndWait(this.browser, [Key.Ctrl, Key.Return]);
8180

8281
chai.assert.deepEqual(
8382
process.platform === 'darwin'
@@ -100,9 +99,8 @@ suite('Menus test', function () {
10099
test('Menu on workspace', async function () {
101100
// Navigate to draw_circle_1.
102101
await tabNavigateToWorkspace(this.browser);
103-
await this.browser.keys('w');
104-
await this.browser.keys([Key.Ctrl, Key.Return]);
105-
await this.browser.pause(PAUSE_TIME);
102+
await sendKeyAndWait(this.browser, 'w');
103+
await sendKeyAndWait(this.browser, [Key.Ctrl, Key.Return]);
106104

107105
chai.assert.deepEqual(
108106
process.platform === 'darwin'
@@ -135,9 +133,9 @@ suite('Menus test', function () {
135133
await tabNavigateToWorkspace(this.browser);
136134
await focusOnBlock(this.browser, 'draw_circle_1');
137135
// Start moving the block
138-
await this.browser.keys('m');
139-
await this.browser.keys([Key.Ctrl, Key.Return]);
140-
await this.browser.pause(PAUSE_TIME);
136+
await sendKeyAndWait(this.browser, 'm');
137+
await sendKeyAndWait(this.browser, [Key.Ctrl, Key.Return]);
138+
141139
chai.assert.isTrue(
142140
await contextMenuExists(this.browser, 'Collapse Block', true),
143141
'The menu should not be openable during a move',

test/webdriverio/test/basic_test.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
testSetup,
1717
testFileLocations,
1818
PAUSE_TIME,
19+
sendKeyAndWait,
1920
tabNavigateToWorkspace,
2021
keyLeft,
2122
keyRight,
@@ -239,13 +240,11 @@ suite('Keyboard navigation on Blocks', function () {
239240
await tabNavigateToWorkspace(this.browser);
240241
await this.browser.pause(PAUSE_TIME);
241242
await focusOnBlock(this.browser, 'text_print_1');
242-
await this.browser.keys('m');
243-
await this.browser.pause(PAUSE_TIME);
243+
await sendKeyAndWait(this.browser, 'm');
244244

245245
chai.assert.isTrue(await isDragging(this.browser));
246246

247-
await this.browser.keys(Key.Tab);
248-
await this.browser.pause(PAUSE_TIME);
247+
await sendKeyAndWait(this.browser, Key.Tab);
249248

250249
chai.assert.isFalse(await isDragging(this.browser));
251250
});
@@ -354,8 +353,7 @@ suite('Keyboard navigation on Fields', function () {
354353
// Open a field editor dropdown
355354
await focusOnBlockField(this.browser, 'logic_boolean_1', 'BOOL');
356355
await this.browser.pause(PAUSE_TIME);
357-
await this.browser.keys(Key.Enter);
358-
await this.browser.pause(PAUSE_TIME);
356+
await sendKeyAndWait(this.browser, Key.Enter);
359357

360358
// Try to navigate to a different block
361359
await keyRight(this.browser);
@@ -368,13 +366,12 @@ suite('Keyboard navigation on Fields', function () {
368366
// Open colour picker
369367
await focusOnBlockField(this.browser, 'colour_picker_1', 'COLOUR');
370368
await this.browser.pause(PAUSE_TIME);
371-
await this.browser.keys(Key.Enter);
372-
await this.browser.pause(PAUSE_TIME);
369+
await sendKeyAndWait(this.browser, Key.Enter);
373370

374371
// Move right to pick a new colour.
375372
await keyRight(this.browser);
376373
// Enter to choose.
377-
await this.browser.keys(Key.Enter);
374+
await sendKeyAndWait(this.browser, Key.Enter);
378375

379376
// Focus seems to take longer than a single pause to settle.
380377
await this.browser.waitUntil(

test/webdriverio/test/clipboard_test.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
focusOnBlockField,
1919
blockIsPresent,
2020
getFocusedBlockType,
21+
sendKeyAndWait,
2122
} from './test_setup.js';
2223
import {Key, KeyAction, PointerAction, WheelAction} from 'webdriverio';
2324

@@ -37,9 +38,8 @@ suite('Clipboard test', function () {
3738
await focusOnBlock(this.browser, 'draw_circle_1');
3839

3940
// Copy and paste
40-
await this.browser.keys([Key.Ctrl, 'c']);
41-
await this.browser.keys([Key.Ctrl, 'v']);
42-
await this.browser.pause(PAUSE_TIME);
41+
await sendKeyAndWait(this.browser, [Key.Ctrl, 'c']);
42+
await sendKeyAndWait(this.browser, [Key.Ctrl, 'v']);
4343

4444
const block = await getBlockElementById(this.browser, 'draw_circle_1');
4545
const blocks = await getSameBlocks(this.browser, block);
@@ -59,10 +59,9 @@ suite('Clipboard test', function () {
5959
const block = await getBlockElementById(this.browser, 'draw_circle_1');
6060

6161
// Cut and paste
62-
await this.browser.keys([Key.Ctrl, 'x']);
62+
await sendKeyAndWait(this.browser, [Key.Ctrl, 'x']);
6363
await block.waitForExist({reverse: true});
64-
await this.browser.keys([Key.Ctrl, 'v']);
65-
await this.browser.pause(PAUSE_TIME);
64+
await sendKeyAndWait(this.browser, [Key.Ctrl, 'v']);
6665

6766
const focusedType = await getFocusedBlockType(this.browser);
6867

@@ -117,11 +116,10 @@ suite('Clipboard test', function () {
117116
// Open a field editor
118117
await focusOnBlockField(this.browser, 'draw_circle_1_color', 'COLOUR');
119118
await this.browser.pause(PAUSE_TIME);
120-
await this.browser.keys(Key.Enter);
121-
await this.browser.pause(PAUSE_TIME);
119+
await sendKeyAndWait(this.browser, Key.Enter);
122120

123121
// Try to cut block while field editor is open
124-
await this.browser.keys([Key.Ctrl, 'x']);
122+
await sendKeyAndWait(this.browser, [Key.Ctrl, 'x']);
125123

126124
// Block is not deleted
127125
chai.assert.isTrue(

test/webdriverio/test/delete_test.ts

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
testFileLocations,
1616
PAUSE_TIME,
1717
tabNavigateToWorkspace,
18+
sendKeyAndWait,
1819
keyRight,
1920
focusOnBlockField,
2021
} from './test_setup.js';
@@ -40,8 +41,7 @@ suite('Deleting Blocks', function () {
4041
.expect(await blockIsPresent(this.browser, 'controls_if_2'))
4142
.equal(true);
4243

43-
await this.browser.keys(Key.Backspace);
44-
await this.browser.pause(PAUSE_TIME);
44+
await sendKeyAndWait(this.browser, Key.Backspace);
4545

4646
chai
4747
.expect(await blockIsPresent(this.browser, 'controls_if_2'))
@@ -62,8 +62,7 @@ suite('Deleting Blocks', function () {
6262
.expect(await blockIsPresent(this.browser, 'controls_if_2'))
6363
.equal(true);
6464

65-
await this.browser.keys([Key.Ctrl, 'x']);
66-
await this.browser.pause(PAUSE_TIME);
65+
await sendKeyAndWait(this.browser, [Key.Ctrl, 'x']);
6766

6867
chai
6968
.expect(await blockIsPresent(this.browser, 'controls_if_2'))
@@ -85,8 +84,7 @@ suite('Deleting Blocks', function () {
8584
.equal(true);
8685
chai.expect(await blockIsPresent(this.browser, 'text_print_1')).equal(true);
8786

88-
await this.browser.keys(Key.Backspace);
89-
await this.browser.pause(PAUSE_TIME);
87+
await sendKeyAndWait(this.browser, Key.Backspace);
9088

9189
chai
9290
.expect(await blockIsPresent(this.browser, 'logic_boolean_1'))
@@ -107,8 +105,7 @@ suite('Deleting Blocks', function () {
107105
.equal(true);
108106
chai.expect(await blockIsPresent(this.browser, 'text_print_1')).equal(true);
109107

110-
await this.browser.keys([Key.Ctrl, 'x']);
111-
await this.browser.pause(PAUSE_TIME);
108+
await sendKeyAndWait(this.browser, [Key.Ctrl, 'x']);
112109

113110
chai
114111
.expect(await blockIsPresent(this.browser, 'logic_boolean_1'))
@@ -128,8 +125,7 @@ suite('Deleting Blocks', function () {
128125
.expect(await blockIsPresent(this.browser, 'logic_boolean_1'))
129126
.equal(true);
130127

131-
await this.browser.keys(Key.Backspace);
132-
await this.browser.pause(PAUSE_TIME);
128+
await sendKeyAndWait(this.browser, Key.Backspace);
133129

134130
chai
135131
.expect(await blockIsPresent(this.browser, 'logic_boolean_1'))
@@ -150,8 +146,7 @@ suite('Deleting Blocks', function () {
150146
.expect(await blockIsPresent(this.browser, 'logic_boolean_1'))
151147
.equal(true);
152148

153-
await this.browser.keys([Key.Ctrl, 'x']);
154-
await this.browser.pause(PAUSE_TIME);
149+
await sendKeyAndWait(this.browser, [Key.Ctrl, 'x']);
155150

156151
chai
157152
.expect(await blockIsPresent(this.browser, 'logic_boolean_1'))
@@ -177,16 +172,13 @@ suite('Deleting Blocks', function () {
177172
// Move to flyout.
178173
await keyRight(this.browser);
179174
// Select number block.
180-
await this.browser.keys(Key.Enter);
181-
await this.browser.pause(PAUSE_TIME);
175+
await sendKeyAndWait(this.browser, Key.Enter);
182176
// Confirm move.
183-
await this.browser.keys(Key.Enter);
184-
await this.browser.pause(PAUSE_TIME);
177+
await sendKeyAndWait(this.browser, Key.Enter);
185178

186179
chai.assert.equal('math_number', await getFocusedBlockType(this.browser));
187180

188-
await this.browser.keys(Key.Backspace);
189-
await this.browser.pause(PAUSE_TIME);
181+
await sendKeyAndWait(this.browser, Key.Backspace);
190182

191183
chai.assert.equal(
192184
await getCurrentFocusedBlockId(this.browser),
@@ -204,16 +196,13 @@ suite('Deleting Blocks', function () {
204196
// Move to flyout.
205197
await keyRight(this.browser);
206198
// Select number block.
207-
await this.browser.keys(Key.Enter);
208-
await this.browser.pause(PAUSE_TIME);
199+
await sendKeyAndWait(this.browser, Key.Enter);
209200
// Confirm move.
210-
await this.browser.keys(Key.Enter);
211-
await this.browser.pause(PAUSE_TIME);
201+
await sendKeyAndWait(this.browser, Key.Enter);
212202

213203
chai.assert.equal('math_number', await getFocusedBlockType(this.browser));
214204

215-
await this.browser.keys([Key.Ctrl, 'x']);
216-
await this.browser.pause(PAUSE_TIME);
205+
await sendKeyAndWait(this.browser, [Key.Ctrl, 'x']);
217206

218207
chai.assert.equal(
219208
await getCurrentFocusedBlockId(this.browser),
@@ -225,11 +214,10 @@ suite('Deleting Blocks', function () {
225214
// Open a field editor
226215
await focusOnBlockField(this.browser, 'colour_picker_1', 'COLOUR');
227216
await this.browser.pause(PAUSE_TIME);
228-
await this.browser.keys(Key.Enter);
229-
await this.browser.pause(PAUSE_TIME);
217+
await sendKeyAndWait(this.browser, Key.Enter);
230218

231219
// Try to delete block while field editor is open
232-
await this.browser.keys(Key.Backspace);
220+
await sendKeyAndWait(this.browser, Key.Backspace);
233221

234222
// Block is not deleted
235223
chai.assert.isTrue(await blockIsPresent(this.browser, 'colour_picker_1'));

test/webdriverio/test/duplicate_test.ts

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

1920
suite('Duplicate test', function () {
@@ -32,8 +33,7 @@ suite('Duplicate test', function () {
3233
await focusOnBlock(this.browser, 'draw_circle_1');
3334

3435
// Duplicate
35-
await this.browser.keys('d');
36-
await this.browser.pause(PAUSE_TIME);
36+
await sendKeyAndWait(this.browser, 'd');
3737

3838
// Check a different block of the same type has focus.
3939
chai.assert.notEqual(
@@ -65,7 +65,7 @@ suite('Duplicate test', function () {
6565
await this.browser.pause(PAUSE_TIME);
6666

6767
// Duplicate.
68-
await this.browser.keys('d');
68+
await sendKeyAndWait(this.browser, 'd');
6969

7070
// Assert we have two comments with the same text.
7171
const commentTexts = await this.browser.execute(() =>

test/webdriverio/test/flyout_test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
keyDown,
1515
tabNavigateBackward,
1616
tabNavigateToWorkspace,
17+
sendKeyAndWait,
1718
keyRight,
1819
getCurrentFocusNodeId,
1920
getCurrentFocusedBlockId,
@@ -167,7 +168,7 @@ suite('Toolbox and flyout test', function () {
167168
test('Tabbing to the workspace after selecting flyout block via workspace toolbox shortcut should close the flyout', async function () {
168169
await tabNavigateToWorkspace(this.browser);
169170

170-
await this.browser.keys('t');
171+
await sendKeyAndWait(this.browser, 't');
171172
await keyRight(this.browser);
172173
await tabNavigateForward(this.browser);
173174

test/webdriverio/test/insert_test.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
tabNavigateToWorkspace,
1515
testFileLocations,
1616
testSetup,
17+
sendKeyAndWait,
1718
keyRight,
1819
getCurrentFocusedBlockId,
1920
blockIsPresent,
@@ -36,33 +37,33 @@ suite('Insert test', function () {
3637
await tabNavigateToWorkspace(this.browser);
3738
await focusOnBlock(this.browser, 'draw_circle_1');
3839
// Insert 'if' block
39-
await this.browser.keys('t');
40+
await sendKeyAndWait(this.browser, 't');
4041
await keyRight(this.browser);
41-
await this.browser.keys(Key.Enter);
42+
await sendKeyAndWait(this.browser, Key.Enter);
4243
chai.assert.equal('controls_if', await getFocusedBlockType(this.browser));
4344
const ifId = await getCurrentFocusedBlockId(this.browser);
4445
chai.assert.ok(ifId);
4546

4647
// Cancel
47-
await this.browser.keys(Key.Escape);
48+
await sendKeyAndWait(this.browser, Key.Escape);
4849

4950
chai.assert.isFalse(await blockIsPresent(this.browser, ifId));
5051
});
5152

5253
test('Insert and cancel with workspace selection', async function () {
5354
// Navigate to workspace.
5455
await tabNavigateToWorkspace(this.browser);
55-
await this.browser.keys('w');
56+
await sendKeyAndWait(this.browser, 'w');
5657
// Insert 'if' block
57-
await this.browser.keys('t');
58+
await sendKeyAndWait(this.browser, 't');
5859
await keyRight(this.browser);
59-
await this.browser.keys(Key.Enter);
60+
await sendKeyAndWait(this.browser, Key.Enter);
6061
chai.assert.equal('controls_if', await getFocusedBlockType(this.browser));
6162
const ifId = await getCurrentFocusedBlockId(this.browser);
6263
chai.assert.ok(ifId);
6364

6465
// Cancel
65-
await this.browser.keys(Key.Escape);
66+
await sendKeyAndWait(this.browser, Key.Escape);
6667

6768
chai.assert.isFalse(await blockIsPresent(this.browser, ifId));
6869
});
@@ -76,9 +77,9 @@ suite('Insert test', function () {
7677
// Move to flyout.
7778
await keyRight(this.browser);
7879
// Select Function block.
79-
await this.browser.keys(Key.Enter);
80+
await sendKeyAndWait(this.browser, Key.Enter);
8081
// Confirm move.
81-
await this.browser.keys(Key.Enter);
82+
await sendKeyAndWait(this.browser, Key.Enter);
8283

8384
chai.assert.equal(
8485
'procedures_defnoreturn',
@@ -92,9 +93,9 @@ suite('Insert test', function () {
9293
// Insert 'if' block
9394
await keyRight(this.browser);
9495
// Choose.
95-
await this.browser.keys(Key.Enter);
96+
await sendKeyAndWait(this.browser, Key.Enter);
9697
// Confirm position.
97-
await this.browser.keys(Key.Enter);
98+
await sendKeyAndWait(this.browser, Key.Enter);
9899

99100
// Assert inserted inside first block p5_setup not at top-level.
100101
chai.assert.equal('controls_if', await getFocusedBlockType(this.browser));

0 commit comments

Comments
 (0)