Browse Source

fix(playwright): waitForResponse logic

pull/5903/head
Wing-Kam Wong 1 year ago
parent
commit
0b9edd2805
  1. 40
      tests/playwright/pages/Base.ts

40
tests/playwright/pages/Base.ts

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

Loading…
Cancel
Save