New test; cookies for account login

This commit is contained in:
Kira 2023-09-15 16:55:52 -07:00
parent a8946581b0
commit f29f0c980b
6 changed files with 78 additions and 1 deletions

View File

@ -0,0 +1,11 @@
import * as nodeFetch from "node-fetch"
export const getLoginToken = async () => {
const response = await nodeFetch("http://localhost:2221/api/login", {
method: "POST",
body: { "username": "admin", "password":"Admin123" }
})
const body = await response.json()
return body.token
}

39
package-lock.json generated
View File

@ -9,6 +9,7 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"node-fetch": "^2.6.7",
"uuid": "^9.0.0"
},
"devDependencies": {
@ -54,6 +55,25 @@
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/node-fetch": {
"version": "2.6.7",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
"integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
"dependencies": {
"whatwg-url": "^5.0.0"
},
"engines": {
"node": "4.x || >=6.0.0"
},
"peerDependencies": {
"encoding": "^0.1.0"
},
"peerDependenciesMeta": {
"encoding": {
"optional": true
}
}
},
"node_modules/playwright-core": {
"version": "1.37.1",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.37.1.tgz",
@ -66,6 +86,11 @@
"node": ">=16"
}
},
"node_modules/tr46": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
},
"node_modules/uuid": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz",
@ -73,6 +98,20 @@
"bin": {
"uuid": "dist/bin/uuid"
}
},
"node_modules/webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
},
"node_modules/whatwg-url": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
"integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
"dependencies": {
"tr46": "~0.0.3",
"webidl-conversions": "^3.0.0"
}
}
}
}

View File

@ -13,6 +13,7 @@
"@playwright/test": "^1.37.1"
},
"dependencies": {
"node-fetch": "^2.6.7",
"uuid": "^9.0.0"
}
}

View File

@ -0,0 +1,10 @@
export class MyAccountPage {
constructor(page) {
this.page = page
}
visit = async () => {
await this.page.goto("/my-account")
await this.page.pause()
}
}

14
tests/my_account.spec.js Normal file
View File

@ -0,0 +1,14 @@
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}) => {
//const loginToken = await getLoginToken()
//console.warn({loginToken})
const myAccount = new MyAccountPage(page)
await myAccount.visit()
await page.pause()
})

View File

@ -12,7 +12,7 @@ import { PaymentPage } from "../page-objects/PaymentPage.js"
import { paymentDetails } from "../data/paymentDetails.js";
test.only("New user full end-to-end test journey", async ({page}) => {
test("New user full end-to-end test journey", async ({page}) => {
// init
const productsPage = new ProductsPage(page)
@ -23,6 +23,8 @@ test.only("New user full end-to-end test journey", async ({page}) => {
const deliveryPage = new DeliveryPage(page)
const paymentPage = new PaymentPage(page)
await page.pause()
// 1. Visit
await productsPage.visit()
await productsPage.sortByCheapest()