Browse Source

fix(playwright): waitForResponse

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

21
tests/playwright/pages/Base.ts

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

Loading…
Cancel
Save