diff --git a/page-objects/MyAccountPage.js b/page-objects/MyAccountPage.js index d729722..e3dd56e 100644 --- a/page-objects/MyAccountPage.js +++ b/page-objects/MyAccountPage.js @@ -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() + } } \ No newline at end of file diff --git a/tests/my_account.spec.js b/tests/my_account.spec.js index 53e2e0d..640c86b 100644 --- a/tests/my_account.spec.js +++ b/tests/my_account.spec.js @@ -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() }) \ No newline at end of file