Browse Source

fix(playwright): waitForResponse

pull/5903/head
Wing-Kam Wong 1 year ago
parent
commit
716b319d32
  1. 13
      tests/playwright/pages/Base.ts

13
tests/playwright/pages/Base.ts

@ -28,20 +28,21 @@ export default abstract class BasePage {
httpMethodsToMatch?: string[]; httpMethodsToMatch?: string[];
responseJsonMatcher?: ResponseSelector; responseJsonMatcher?: ResponseSelector;
}) { }) {
// trigger UI action first const [res] = await Promise.all([
await uiAction(); this.rootPage.waitForResponse(
// wait for response
const res = await this.rootPage.waitForResponse(
res => res =>
res.url().includes(requestUrlPathToMatch) && res.url().includes(requestUrlPathToMatch) &&
res.status() === 200 && res.status() === 200 &&
httpMethodsToMatch.includes(res.request().method()) httpMethodsToMatch.includes(res.request().method())
); ),
uiAction(),
]);
// handle JSON matcher if provided // handle JSON matcher if provided
let isResJsonMatched = true; let isResJsonMatched = true;
if (responseJsonMatcher) { if (responseJsonMatcher) {
try { try {
isResJsonMatched = responseJsonMatcher(await res.json()); isResJsonMatched = responseJsonMatcher(res.json());
} catch { } catch {
isResJsonMatched = false; isResJsonMatched = false;
} }

Loading…
Cancel
Save