Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

feat(waitForResponse): print regex pattern when waiting for request/response (#5485)

Dmitry Gozmandc51536bca99
diff --git a/src/client/page.ts b/src/client/page.ts
index 4660827105..1d4f41fd04 100644
--- a/src/client/page.ts
+++ b/src/client/page.ts
@@ -368,7 +368,7 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia
return urlOrPredicate(request);
};
const trimmedUrl = trimUrl(urlOrPredicate);
- const logLine = trimmedUrl ? `waiting for request "${trimmedUrl}"` : undefined;
+ const logLine = trimmedUrl ? `waiting for request ${trimmedUrl}` : undefined;
return this._waitForEvent(Events.Page.Request, { predicate, timeout: options.timeout }, logLine);
});
}
@@ -381,7 +381,7 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia
return urlOrPredicate(response);
};
const trimmedUrl = trimUrl(urlOrPredicate);
- const logLine = trimmedUrl ? `waiting for response "${trimmedUrl}"` : undefined;
+ const logLine = trimmedUrl ? `waiting for response ${trimmedUrl}` : undefined;
return this._waitForEvent(Events.Page.Response, { predicate, timeout: options.timeout }, logLine);
});
}
@@ -699,10 +699,15 @@ export class BindingCall extends ChannelOwner<channels.BindingCallChannel, chann
}
}
+function trimEnd(s: string): string {
+ if (s.length > 50)
+ s = s.substring(0, 50) + '\u2026';
+ return s;
+}
+
function trimUrl(param: any): string | undefined {
- if (isString(param)) {
- if (param.length > 50)
- param = param.substring(0, 50) + '\u2026';
- return param;
- }
+ if (isRegExp(param))
+ return `/${trimEnd(param.source)}/${param.flags}`;
+ if (isString(param))
+ return `"${trimEnd(param)}"`;
}
diff --git a/test/page-wait-for-response.spec.ts b/test/page-wait-for-response.spec.ts
index efa17d2738..ab75f75e35 100644
--- a/test/page-wait-for-response.spec.ts
+++ b/test/page-wait-for-response.spec.ts
@@ -44,8 +44,10 @@ it('should respect default timeout', async ({page, playwright}) => {
});
it('should log the url', async ({page}) => {
- const error = await page.waitForResponse('foo.css', { timeout: 100 }).catch(e => e);
- expect(error.message).toContain('waiting for response "foo.css"');
+ const error1 = await page.waitForResponse('foo.css', { timeout: 100 }).catch(e => e);
+ expect(error1.message).toContain('waiting for response "foo.css"');
+ const error2 = await page.waitForResponse(/foo.css/i, { timeout: 100 }).catch(e => e);
+ expect(error2.message).toContain('waiting for response /foo.css/i');
});
it('should work with predicate', async ({page, server}) => {