|
2 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
|
5 | | -import { Page } from '@playwright/test'; |
| 5 | +import { Page, expect } from '@playwright/test'; |
6 | 6 | import { BaseTarget } from '../lib/targets/base'; |
7 | 7 |
|
8 | 8 | import { |
@@ -74,36 +74,17 @@ export abstract class BaseLayout { |
74 | 74 | } |
75 | 75 |
|
76 | 76 | async checkWebChannelMessage(command: FirefoxCommand) { |
77 | | - await this.page.evaluate(async (command) => { |
78 | | - const noNotificationError = new Error( |
79 | | - `NoSuchBrowserNotification - ${command}` |
| 77 | + // Retry across navigations — a client-side redirect after page.goto |
| 78 | + // can destroy the execution context mid-evaluate. |
| 79 | + await expect(async () => { |
| 80 | + const messages = await this.page.evaluate(() => |
| 81 | + JSON.parse(sessionStorage.getItem('webChannelEvents') || '[]') |
80 | 82 | ); |
81 | | - |
82 | | - await new Promise((resolve, reject) => { |
83 | | - const timeoutHandle = setTimeout( |
84 | | - () => reject(noNotificationError), |
85 | | - 5000 |
86 | | - ); |
87 | | - |
88 | | - function findMessage() { |
89 | | - const messages = JSON.parse( |
90 | | - sessionStorage.getItem('webChannelEvents') || '[]' |
91 | | - ); |
92 | | - const m = messages.find( |
93 | | - (x: { command: string }) => x.command === command |
94 | | - ); |
95 | | - |
96 | | - if (m) { |
97 | | - clearTimeout(timeoutHandle); |
98 | | - resolve(m); |
99 | | - } else { |
100 | | - setTimeout(findMessage, 50); |
101 | | - } |
102 | | - } |
103 | | - |
104 | | - findMessage(); |
105 | | - }); |
106 | | - }, command); |
| 83 | + const found = messages.find( |
| 84 | + (x: { command: string }) => x.command === command |
| 85 | + ); |
| 86 | + expect(found).toBeTruthy(); |
| 87 | + }).toPass({ timeout: 5000 }); |
107 | 88 | } |
108 | 89 |
|
109 | 90 | async getWebChannelEvents(): Promise< |
|
0 commit comments