Skip to content

Commit 91ac99d

Browse files
author
Gianni Fezza
committed
Initialise playwright course
0 parents  commit 91ac99d

23 files changed

+727
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
/test-results/
3+
/playwright-report/
4+
/playwright/.cache/
5+
shopping-store-mac-arm64
6+
.env

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"editor.formatOnType": true,
3+
"workbench.preferredDarkColorTheme": "Default Dark+",
4+
"workbench.preferredLightColorTheme": "Default Dark+",
5+
"window.autoDetectColorScheme": true,
6+
"workbench.colorTheme": "Default Dark+",
7+
"workbench.colorCustomizations": {
8+
9+
},
10+
"workbench.preferredHighContrastLightColorTheme": "Default Dark+",
11+
"workbench.preferredHighContrastColorTheme": "Default Dark+",
12+
"workbench.iconTheme": "material-icon-theme"
13+
}

api-calls/getLoginToken.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as nodeFetch from "node-fetch"
2+
export const getLoginToken = async (username, password) => {
3+
const response = await nodeFetch( process.env.URL, {
4+
method: "POST",
5+
body: JSON.stringify({"username": username, "password": password})
6+
} )
7+
8+
if ( response.status !== 200 ) {
9+
throw new Error("An error occured trying to retrieve the login token")
10+
}
11+
const body = await response.json()
12+
return body.token
13+
}

data/deliveryDetails.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const deliveryDetails = {
2+
firstName: "Mario",
3+
lastName: "Biondi",
4+
street: "Via Venezia 18",
5+
postCode: "75100",
6+
city: "Palermo",
7+
country: "Italy"
8+
}

data/paymentDetails.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const paymentDetails = {
2+
creditOwner: 'Mario Biondi',
3+
creditNumeber: '1234123412341234',
4+
creditValidUntil: '12/35',
5+
creditCVC: '123'
6+
}

data/userDetails.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const userDetails = {
2+
username: process.env.ADMIN_USER,
3+
password: process.env.ADMIN_PASSWORD,
4+
}

globalSetup.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as dotenv from "dotenv"
2+
export default () => {
3+
dotenv.config()
4+
}

package-lock.json

Lines changed: 150 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "playwright-course",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "playwright test --headed",
8+
"test_without_browser": "playwright test"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"@playwright/test": "^1.47.1",
15+
"@types/node": "^22.7.3"
16+
},
17+
"dependencies": {
18+
"dotenv": "^16.0.3",
19+
"node-fetch": "^2.6.7",
20+
"uuid": "^9.0.0"
21+
}
22+
}

page-objects/CheckOutPage.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect } from "@playwright/test"
2+
3+
export class CheckoutPage{
4+
constructor(page){
5+
this.page = page
6+
this.basketCards = page.locator('[data-qa="basket-card"]')
7+
this.basketItemPrices = page.locator('[data-qa="basket-item-price"]')
8+
this.basketItemRemoveButtons = page.locator('[data-qa="basket-card-remove-item"]')
9+
this.continueToCheckoutButton = page.locator('[data-qa="continue-to-checkout"]')
10+
}
11+
12+
removeCheapsetProduct = async () => {
13+
await this.basketCards.first().waitFor()
14+
const bascketCardsBeforeRemove = await this.basketCards.count()
15+
await this.basketItemPrices.first().waitFor()
16+
const allPriceTexts = await this.basketItemPrices.allInnerTexts()
17+
const cheapsetProduct = allPriceTexts.map((element) => {return parseInt(element.replace('$', ''),10)})
18+
await this.basketItemRemoveButtons.nth(cheapsetProduct.indexOf(Math.min(...cheapsetProduct))).click()
19+
await expect(this.basketCards).toHaveCount(bascketCardsBeforeRemove-1)
20+
}
21+
22+
continueToCheckout = async () => {
23+
await this.continueToCheckoutButton.waitFor()
24+
await this.continueToCheckoutButton.click()
25+
await this.page.waitForURL(/\/login/, { timeout: 3000})
26+
}
27+
}

0 commit comments

Comments
 (0)