mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(errors): waitForEvent/Request/Response should point to the api call (#11229)
This commit is contained in:
parent
d629fe57ab
commit
8e75dbffaa
@ -382,19 +382,21 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Page
|
||||
}
|
||||
|
||||
private async _waitForEvent(event: string, optionsOrPredicate: WaitForEventOptions, logLine?: string): Promise<any> {
|
||||
const timeout = this._timeoutSettings.timeout(typeof optionsOrPredicate === 'function' ? {} : optionsOrPredicate);
|
||||
const predicate = typeof optionsOrPredicate === 'function' ? optionsOrPredicate : optionsOrPredicate.predicate;
|
||||
const waiter = Waiter.createForEvent(this, event);
|
||||
if (logLine)
|
||||
waiter.log(logLine);
|
||||
waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded while waiting for event "${event}"`);
|
||||
if (event !== Events.Page.Crash)
|
||||
waiter.rejectOnEvent(this, Events.Page.Crash, new Error('Page crashed'));
|
||||
if (event !== Events.Page.Close)
|
||||
waiter.rejectOnEvent(this, Events.Page.Close, new Error('Page closed'));
|
||||
const result = await waiter.waitForEvent(this, event, predicate as any);
|
||||
waiter.dispose();
|
||||
return result;
|
||||
return this._wrapApiCall(async () => {
|
||||
const timeout = this._timeoutSettings.timeout(typeof optionsOrPredicate === 'function' ? {} : optionsOrPredicate);
|
||||
const predicate = typeof optionsOrPredicate === 'function' ? optionsOrPredicate : optionsOrPredicate.predicate;
|
||||
const waiter = Waiter.createForEvent(this, event);
|
||||
if (logLine)
|
||||
waiter.log(logLine);
|
||||
waiter.rejectOnTimeout(timeout, `Timeout ${timeout}ms exceeded while waiting for event "${event}"`);
|
||||
if (event !== Events.Page.Crash)
|
||||
waiter.rejectOnEvent(this, Events.Page.Crash, new Error('Page crashed'));
|
||||
if (event !== Events.Page.Close)
|
||||
waiter.rejectOnEvent(this, Events.Page.Close, new Error('Page closed'));
|
||||
const result = await waiter.waitForEvent(this, event, predicate as any);
|
||||
waiter.dispose();
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
async goBack(options: channels.PageGoBackOptions = {}): Promise<Response | null> {
|
||||
|
@ -49,6 +49,9 @@ it('should respect timeout', async ({ page, playwright }) => {
|
||||
await page.waitForEvent('request', { predicate: () => false, timeout: 1 }).catch(e => error = e);
|
||||
expect(error).toBeInstanceOf(playwright.errors.TimeoutError);
|
||||
expect(error.message).toContain('Timeout 1ms exceeded while waiting for event "request"');
|
||||
// Error stack should point to the api call.
|
||||
const firstFrame = error.stack.split('\n').find(line => line.startsWith(' at '));
|
||||
expect(firstFrame).toContain(__filename);
|
||||
});
|
||||
|
||||
it('should respect default timeout', async ({ page, playwright }) => {
|
||||
|
@ -39,8 +39,11 @@ it('should respect timeout', async ({ page, playwright }) => {
|
||||
it('should respect default timeout', async ({ page, playwright }) => {
|
||||
let error = null;
|
||||
page.setDefaultTimeout(1);
|
||||
await page.waitForEvent('response', () => false).catch(e => error = e);
|
||||
await page.waitForResponse(() => false).catch(e => error = e);
|
||||
expect(error).toBeInstanceOf(playwright.errors.TimeoutError);
|
||||
// Error stack should point to the api call.
|
||||
const firstFrame = error.stack.split('\n').find(line => line.startsWith(' at '));
|
||||
expect(firstFrame).toContain(__filename);
|
||||
});
|
||||
|
||||
it('should log the url', async ({ page }) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user