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[]; httpMethodsToMatch?: string[];
responseJsonMatcher?: ResponseSelector; responseJsonMatcher?: ResponseSelector;
}) { }) {
// trigger UI action first const [res] = await Promise.all([
await uiAction(); this.rootPage.waitForResponse(
// wait for response res =>
const res = await this.rootPage.waitForResponse( res.url().includes(requestUrlPathToMatch) &&
res => res.status() === 200 &&
res.url().includes(requestUrlPathToMatch) && httpMethodsToMatch.includes(res.request().method())
res.status() === 200 && ),
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