Skip to content

Commit 00e8b3c

Browse files
committed
Add clickBlocksCategory helper
1 parent 9883e0e commit 00e8b3c

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

test/helpers/selenium-helper.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class SeleniumHelper {
1919
'clickText',
2020
'clickButton',
2121
'clickXpath',
22+
'clickBlocksCategory',
2223
'elementIsVisible',
2324
'findByText',
2425
'findByXpath',
@@ -124,6 +125,17 @@ class SeleniumHelper {
124125
return this.findByText(text, scope).then(el => el.click());
125126
}
126127

128+
async clickBlocksCategory (categoryText) {
129+
// The toolbox is destroyed and recreated several times, so avoid clicking on a nonexistent element and erroring
130+
// out. First we wait for the block pane itself to appear, then wait 100ms for the toolbox to finish refreshing,
131+
// then finally click the toolbox text.
132+
133+
await this.findByXpath('//div[contains(@class, "blocks_blocks")]');
134+
await this.driver.sleep(100);
135+
await this.clickText(categoryText, 'div[contains(@class, "blocks_blocks")]');
136+
await this.driver.sleep(500); // Wait for scroll to finish
137+
}
138+
127139
rightClickText (text, scope) {
128140
return this.findByText(text, scope).then(el => this.driver.actions()
129141
.click(el, Button.RIGHT)

test/integration/blocks.test.js

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SeleniumHelper from '../helpers/selenium-helper';
33

44
const {
55
clickText,
6+
clickBlocksCategory,
67
clickButton,
78
clickXpath,
89
findByText,
@@ -31,8 +32,7 @@ describe('Working with the blocks', () => {
3132
test('Blocks report when clicked in the toolbox', async () => {
3233
await loadUri(uri);
3334
await clickText('Code');
34-
await clickText('Operators', scope.blocksTab);
35-
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for scroll animation
35+
await clickBlocksCategory('Operators');
3636
await clickText('join', scope.blocksTab); // Click "join <hello> <world>" block
3737
await findByText('apple banana', scope.reportedValue); // Tooltip with result
3838
const logs = await getLogs();
@@ -41,14 +41,13 @@ describe('Working with the blocks', () => {
4141

4242
test('Switching sprites updates the block menus', async () => {
4343
await loadUri(uri);
44-
await clickText('Sound', scope.blocksTab);
45-
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for scroll animation
44+
await clickBlocksCategory('Sound');
4645
// "Meow" sound block should be visible
4746
await findByText('Meow', scope.blocksTab);
4847
await clickText('Backdrops'); // Switch to the backdrop
4948
// Now "pop" sound block should be visible and motion blocks hidden
5049
await findByText('pop', scope.blocksTab);
51-
await clickText('Motion', scope.blocksTab);
50+
await clickBlocksCategory('Motion');
5251
await findByText('Stage selected: no motion blocks');
5352

5453
const logs = await getLogs();
@@ -58,8 +57,7 @@ describe('Working with the blocks', () => {
5857
test('Creating variables', async () => {
5958
await loadUri(uri);
6059
await clickText('Code');
61-
await clickText('Variables', scope.blocksTab);
62-
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for scroll animation
60+
await clickBlocksCategory('Variables');
6361

6462
// Expect a default variable "my variable" to be visible
6563
await clickText('my\u00A0variable', scope.blocksTab);
@@ -75,8 +73,7 @@ describe('Working with the blocks', () => {
7573
await clickButton('OK');
7674

7775
// Make sure reporting works on a new variable
78-
await clickText('Variables', scope.blocksTab);
79-
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for scroll animation
76+
await clickBlocksCategory('Variables');
8077
await clickText('score', scope.blocksTab);
8178
await findByText('0', scope.reportedValue); // Tooltip with result
8279

@@ -100,8 +97,7 @@ describe('Working with the blocks', () => {
10097
test('Creating a list', async () => {
10198
await loadUri(uri);
10299
await clickText('Code');
103-
await clickText('Variables', scope.blocksTab);
104-
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for scroll animation
100+
await clickBlocksCategory('Variables');
105101

106102
await clickText('Make a List');
107103
let el = await findByXpath("//input[@name='New list name:']");
@@ -133,8 +129,7 @@ describe('Working with the blocks', () => {
133129

134130
test('Custom procedures', async () => {
135131
await loadUri(uri);
136-
await clickText('My Blocks');
137-
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for scroll animation
132+
await clickBlocksCategory('My Blocks');
138133
await clickText('Make a Block');
139134
// Click on the "add an input" buttons
140135
await clickText('number or text', scope.modal);
@@ -165,8 +160,7 @@ describe('Working with the blocks', () => {
165160
test('Record option from sound block menu opens sound recorder', async () => {
166161
await loadUri(uri);
167162
await clickText('Code');
168-
await clickText('Sound', scope.blocksTab);
169-
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for scroll animation
163+
await clickBlocksCategory('Sound');
170164
await clickText('Meow', scope.blocksTab); // Click "play sound <Meow> until done" block
171165
await clickText('record'); // Click "record..." option in the block's sound menu
172166
// Access has been force denied, so close the alert that comes up
@@ -193,8 +187,7 @@ describe('Working with the blocks', () => {
193187

194188
// Make sure it is updated in the block menu
195189
await clickText('Code');
196-
await clickText('Looks', scope.blocksTab);
197-
await driver.sleep(500); // Wait for scroll to finish
190+
await clickBlocksCategory('Looks');
198191
await clickText('newname', scope.blocksTab);
199192
});
200193

@@ -213,19 +206,17 @@ describe('Working with the blocks', () => {
213206

214207
// Make sure it is updated in the block menu
215208
await clickText('Code');
216-
await clickText('Looks', scope.blocksTab);
217-
await driver.sleep(500); // Wait for scroll to finish
209+
await clickBlocksCategory('Looks');
218210
await clickText('<NewCostume>', scope.blocksTab);
219211

220-
await clickText('Sound', scope.blocksTab);
212+
await clickBlocksCategory('Sound');
221213
});
222214

223215
test('Adding costumes DOES update the default costume name in the toolbox', async () => {
224216
await loadUri(uri);
225217

226218
// By default, costume2 is in the costume tab
227-
await clickText('Looks', scope.blocksTab);
228-
await driver.sleep(500); // Wait for scroll to finish
219+
await clickBlocksCategory('Looks');
229220
await clickText('costume2', scope.blocksTab);
230221

231222
// Also check that adding a new costume does update the list
@@ -254,8 +245,7 @@ describe('Working with the blocks', () => {
254245
await findByXpath("//div[contains(@class,'sprite-selector-item_is-selected_')]" +
255246
"//div[contains(text(), 'A Bass')]");
256247
await clickText('Code');
257-
await clickText('Sound', scope.blocksTab);
258-
await driver.sleep(500); // Wait for scroll to finish
248+
await clickBlocksCategory('Sound');
259249
await clickText('A\u00A0Bass', scope.blocksTab); // Need &nbsp; for block text
260250
});
261251

@@ -264,15 +254,13 @@ describe('Working with the blocks', () => {
264254
const playerUri = path.resolve(__dirname, '../../build/player.html');
265255
await loadUri(playerUri);
266256
await clickText('See inside');
267-
await clickText('Variables');
268-
await driver.sleep(500); // Wait for scroll to finish
257+
await clickBlocksCategory('Variables');
269258
await clickText('my\u00A0variable');
270259

271260
await clickText('See Project Page');
272261
await clickText('See inside');
273262

274-
await clickText('Variables');
275-
await driver.sleep(500); // Wait for scroll to finish
263+
await clickBlocksCategory('Variables');
276264
await clickText('my\u00A0variable');
277265
});
278266

@@ -281,8 +269,7 @@ describe('Working with the blocks', () => {
281269
await loadUri(uri);
282270
await clickText('Costumes');
283271
await clickText('Code');
284-
await clickText('Variables', scope.blocksTab);
285-
await driver.sleep(500); // Wait for scroll
272+
await clickBlocksCategory('Variables');
286273
await clickText('Make a List');
287274
const el = await findByXpath("//input[@name='New list name:']");
288275
await el.sendKeys('list1');

0 commit comments

Comments
 (0)