Refactored to store user details elsewhere

This commit is contained in:
Kira 2023-09-18 11:34:39 -07:00
parent 31e1f119e7
commit d70effc7a4
3 changed files with 11 additions and 5 deletions

View File

@ -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) {

4
data/userDetails.js Normal file
View File

@ -0,0 +1,4 @@
export const adminDetails = {
username: "kira",
password: "secret"
}

View File

@ -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()
})