From d70effc7a474823b08427f884acae10618fe220f Mon Sep 17 00:00:00 2001 From: Kira Date: Mon, 18 Sep 2023 11:34:39 -0700 Subject: [PATCH] Refactored to store user details elsewhere --- api-calls/getLoginToken.js | 4 ++-- data/userDetails.js | 4 ++++ tests/my_account.spec.js | 8 +++++--- 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 data/userDetails.js diff --git a/api-calls/getLoginToken.js b/api-calls/getLoginToken.js index 4f1ef37..37fd311 100644 --- a/api-calls/getLoginToken.js +++ b/api-calls/getLoginToken.js @@ -1,9 +1,9 @@ import * as nodeFetch from "node-fetch" -export const getLoginToken = async () => { +export const getLoginToken = async (username, password) => { const response = await nodeFetch("http://localhost:2221/api/login", { method: "POST", - body: JSON.stringify({ "username": "admin", "password":"Admin123" }) + body: JSON.stringify({ "username": username, "password":password }) }) if(response.status !== 200) { diff --git a/data/userDetails.js b/data/userDetails.js new file mode 100644 index 0000000..4e5fbec --- /dev/null +++ b/data/userDetails.js @@ -0,0 +1,4 @@ +export const adminDetails = { + username: "kira", + password: "secret" +} \ No newline at end of file diff --git a/tests/my_account.spec.js b/tests/my_account.spec.js index ef86421..5b42993 100644 --- a/tests/my_account.spec.js +++ b/tests/my_account.spec.js @@ -3,10 +3,11 @@ import { test } from "@playwright/test" import { MyAccountPage } from "../page-objects/MyAccountPage.js" import { getLoginToken } from "../api-calls/getLoginToken.js" -test.only("My Account using cookie injection", async ({page}) => { +import { adminDetails } from "../data/userDetails.js" - const loginToken = await getLoginToken() - console.warn({loginToken}) +test.only("My Account using cookie injection", async ({page}) => { + const loginToken = await getLoginToken(adminDetails.username, + adminDetails.password) const myAccount = new MyAccountPage(page) await myAccount.visit() @@ -16,4 +17,5 @@ test.only("My Account using cookie injection", async ({page}) => { }, [loginToken]) await myAccount.visit() await myAccount.checkForLogin() + await page.pause() }) \ No newline at end of file