fix(trace): show waitForLoadState when event has already fired (#17826)

Fixes https://github.com/microsoft/playwright/issues/17807
This commit is contained in:
Yury Semikhatsky 2022-10-07 11:27:56 -07:00 committed by GitHub
parent b140b29df0
commit 1b5c2f9aba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View file

@ -148,14 +148,16 @@ export class Frame extends ChannelOwner<channels.FrameChannel> implements api.Fr
async waitForLoadState(state: LifecycleEvent = 'load', options: { timeout?: number } = {}): Promise<void> {
state = verifyLoadState('state', state);
if (this._loadStates.has(state))
return;
return this._page!._wrapApiCall(async () => {
const waiter = this._setupNavigationWaiter(options);
if (this._loadStates.has(state)) {
waiter.log(` not waiting, "${state}" event already fired`);
} else {
await waiter.waitForEvent<LifecycleEvent>(this._eventEmitter, 'loadstate', s => {
waiter.log(` "${s}" event fired`);
return s === state;
});
}
waiter.dispose();
});
}

View file

@ -717,3 +717,15 @@ test('should serve overridden request', async ({ page, runAndTrace, server }) =>
expect(color).toBe('rgb(255, 0, 0)');
});
test('should display waitForLoadState even if did not wait for it', async ({ runAndTrace, server, page }) => {
const traceViewer = await runAndTrace(async () => {
await page.goto(server.EMPTY_PAGE);
await page.waitForLoadState('load');
await page.waitForLoadState('load');
});
await expect(traceViewer.actionTitles).toHaveText([
/page.goto/,
/page.waitForLoadState/,
/page.waitForLoadState/,
]);
});