Skip to content

Commit b9f9571

Browse files
prushforthAliyanH
authored andcommitted
- Fix chronically flaky scale tests using locators.
1 parent 08f806d commit b9f9571

File tree

2 files changed

+42
-37
lines changed

2 files changed

+42
-37
lines changed

test/e2e/mapml-viewer/mapml-viewerScale.test.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,46 @@ test.describe('Announce movement test', () => {
1616
});
1717

1818
test('Output values are correct during zoom in', async () => {
19+
// focus the map
1920
await page.keyboard.press('Tab');
21+
// focus the zoom in control
2022
await page.keyboard.press('Tab');
23+
// activate zoom in -> zoom = 1
2124
await page.keyboard.press('Enter');
25+
await page.waitForTimeout(1000);
26+
// activate zoom in -> zoom = 2
2227
await page.keyboard.press('Enter');
2328
await page.waitForTimeout(1000);
2429

25-
const movedUp = await page.$eval(
26-
'body > mapml-viewer div > output:nth-child(7)',
27-
(output) => output.innerHTML
28-
);
29-
expect(movedUp).toEqual('2.6 centimeters to 2000 kilometers');
30+
// screen reader output is slow...
31+
const output = page.locator('.mapml-screen-reader-output-scale');
32+
const movedUp = await output.evaluate((output) => output.innerHTML);
33+
expect(movedUp).toEqual('2.1 centimeters to 1000 kilometers');
3034

35+
// go to zoom = 3
3136
await page.keyboard.press('Enter');
3237
await page.waitForTimeout(1000);
3338

34-
const movedUpAgain = await page.$eval(
35-
'body > mapml-viewer div > output:nth-child(7)',
36-
(output) => output.innerHTML
37-
);
38-
expect(movedUpAgain).toEqual('2.1 centimeters to 1000 kilometers');
39+
const movedUpAgain = await output.evaluate((output) => output.innerHTML);
40+
// zoom = 3
41+
expect(movedUpAgain).toEqual('1.7 centimeters to 500 kilometers');
3942
});
4043

4144
test('Output values are correct during zoom out', async () => {
4245
await page.keyboard.press('Tab');
4346
await page.keyboard.press('Enter');
4447
await page.waitForTimeout(1000);
4548

46-
const movedUp = await page.$eval(
47-
'body > mapml-viewer div > output:nth-child(7)',
48-
(output) => output.innerHTML
49-
);
50-
expect(movedUp).toEqual('2.6 centimeters to 2000 kilometers');
49+
// screen reader output is slow...
50+
const output = page.locator('.mapml-screen-reader-output-scale');
51+
const movedUp = await output.evaluate((output) => output.innerHTML);
52+
expect(movedUp).toEqual('2.1 centimeters to 1000 kilometers');
5153

5254
await page.keyboard.press('Enter');
5355
await page.waitForTimeout(1000);
5456

55-
const movedUpAgain = await page.$eval(
56-
'body > mapml-viewer div > output:nth-child(7)',
57-
(output) => output.innerHTML
58-
);
59-
expect(movedUpAgain).toEqual('1.8 centimeters to 2000 kilometers');
57+
const movedUpAgain = await output.evaluate((output) => output.innerHTML);
58+
// zoom is now = 0
59+
expect(movedUpAgain).toEqual('2.6 centimeters to 2000 kilometers');
6060
});
6161
});

test/e2e/web-map/mapScale.test.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,51 @@ test.describe('Announce movement test', () => {
1616
});
1717

1818
test('Output values are correct during zoom in', async () => {
19+
// focus the map
1920
await page.keyboard.press('Tab');
21+
// focus the zoom in control
2022
await page.keyboard.press('Tab');
23+
// activate zoom in -> zoom = 3
2124
await page.keyboard.press('Enter');
25+
await page.waitForTimeout(1000);
26+
// activate zoom in -> zoom = 4
2227
await page.keyboard.press('Enter');
2328
await page.waitForTimeout(1000);
2429

25-
const movedUp = await page.$eval(
26-
'body > map div > output:nth-child(7)',
27-
(output) => output.innerHTML
28-
);
29-
expect(movedUp).toEqual('1.7 centimeters to 500 kilometers');
30+
// screen reader output is slow...
31+
const output = page.locator('.mapml-screen-reader-output-scale');
32+
const movedUp = await output.evaluate((output) => output.innerHTML);
33+
// zoom = 4 here (different start conditions that mapml-viewer.html)
34+
expect(movedUp).toEqual('1.7 centimeters to 300 kilometers');
3035

36+
// nothing happens here because the zoom in is disabled...
3137
await page.keyboard.press('Enter');
3238
await page.waitForTimeout(1000);
3339

34-
const movedUpAgain = await page.$eval(
35-
'body > map div > output:nth-child(7)',
36-
(output) => output.innerHTML
37-
);
40+
const movedUpAgain = await output.evaluate((output) => output.innerHTML);
41+
// zoom = 4 still
3842
expect(movedUpAgain).toEqual('1.7 centimeters to 300 kilometers');
3943
});
4044

4145
test('Output values are correct during zoom out', async () => {
46+
await page.pause();
47+
// focus the zoom out control
4248
await page.keyboard.press('Tab');
49+
// go back to zoom = 3
4350
await page.keyboard.press('Enter');
4451
await page.waitForTimeout(1000);
4552

46-
const movedUp = await page.$eval(
47-
'body > map div > output:nth-child(7)',
48-
(output) => output.innerHTML
49-
);
53+
// screen reader output is slow...
54+
const output = page.locator('.mapml-screen-reader-output-scale');
55+
const movedUp = await output.evaluate((output) => output.innerHTML);
5056
expect(movedUp).toEqual('1.7 centimeters to 500 kilometers');
5157

58+
// go to zoom = 2
5259
await page.keyboard.press('Enter');
5360
await page.waitForTimeout(1000);
5461

55-
const movedUpAgain = await page.$eval(
56-
'body > map div > output:nth-child(7)',
57-
(output) => output.innerHTML
58-
);
62+
const movedUpAgain = await output.evaluate((output) => output.innerHTML);
63+
// zoom is now = 2
5964
expect(movedUpAgain).toEqual('2 centimeters to 1000 kilometers');
6065
});
6166
});

0 commit comments

Comments
 (0)