|
|
@ -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[] }) { |
|
|
|