|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|