Mocking network request for 500 status code
This commit is contained in:
parent
786778c7cf
commit
9303b3b551
|
@ -2,6 +2,7 @@ export class MyAccountPage {
|
|||
constructor(page) {
|
||||
this.page = page
|
||||
this.myAccountHeader = page.getByRole('heading', { name: 'My Account' })
|
||||
this.errorMessage = page.locator('[data-qa="error-message"]')
|
||||
}
|
||||
|
||||
visit = async () => {
|
||||
|
@ -11,4 +12,8 @@ export class MyAccountPage {
|
|||
checkForLogin = async () => {
|
||||
await this.myAccountHeader.waitFor()
|
||||
}
|
||||
|
||||
waitForErrorMessage = async () => {
|
||||
await this.errorMessage.waitFor()
|
||||
}
|
||||
}
|
|
@ -7,10 +7,19 @@ import { getLoginToken } from "../api-calls/getLoginToken.js"
|
|||
|
||||
import { adminDetails } from "../data/userDetails.js"
|
||||
|
||||
test.only("My Account using cookie injection", async ({page}) => {
|
||||
test.only("My Account using cookie injection and mocking network request",
|
||||
async ({page}) => {
|
||||
const loginToken = await getLoginToken(adminDetails.username,
|
||||
adminDetails.password)
|
||||
|
||||
await page.route("**/api/user**", async (route, request) => {
|
||||
await route.fulfill({
|
||||
status: 500,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({ message: "PLAYWRIGHT ERROR FROM MOCKING" }),
|
||||
})
|
||||
})
|
||||
|
||||
const myAccount = new MyAccountPage(page)
|
||||
await myAccount.visit()
|
||||
|
||||
|
@ -19,5 +28,5 @@ test.only("My Account using cookie injection", async ({page}) => {
|
|||
}, [loginToken])
|
||||
await myAccount.visit()
|
||||
await myAccount.checkForLogin()
|
||||
await page.pause()
|
||||
await myAccount.waitForErrorMessage()
|
||||
})
|
Loading…
Reference in New Issue