Skip to content

Commit 2be5564

Browse files
authored
Merge pull request #301 from QAComet/qacomet/addresses-tests
Add address tests
2 parents 1751908 + bce52d2 commit 2be5564

File tree

17 files changed

+357
-35
lines changed

17 files changed

+357
-35
lines changed
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import { Locator, Page } from "@playwright/test"
22
import { AccountPage } from "./account-page"
3-
import { AddAddressModal } from "./modals/add-address-modal"
3+
import { AddressModal } from "./modals/address-modal"
44

55
export class AddressesPage extends AccountPage {
6-
addAddressModal: AddAddressModal
6+
addAddressModal: AddressModal
7+
editAddressModal: AddressModal
8+
addressContainer: Locator
9+
addressesWrapper: Locator
10+
newAddressButton: Locator
11+
712
constructor(page: Page) {
813
super(page)
9-
this.addAddressModal = new AddAddressModal(page)
14+
this.addAddressModal = new AddressModal(page, "add")
15+
this.editAddressModal = new AddressModal(page, "edit")
16+
this.addressContainer = this.container.getByTestId("address-container")
17+
this.addressesWrapper = page.getByTestId("addresses-page-wrapper")
18+
this.newAddressButton = this.container.getByTestId("add-address-button")
1019
}
1120

1221
getAddressContainer(text: string) {
@@ -15,7 +24,7 @@ export class AddressesPage extends AccountPage {
1524
.filter({ hasText: text })
1625
return {
1726
container,
18-
editButton: container.getByTestId("address-edit-button"),
27+
editButton: container.getByTestId('address-edit-button'),
1928
deleteButton: container.getByTestId("address-delete-button"),
2029
name: container.getByTestId("address-name"),
2130
company: container.getByTestId("address-company"),
@@ -24,4 +33,10 @@ export class AddressesPage extends AccountPage {
2433
provinceCountry: container.getByTestId("address-province-country"),
2534
}
2635
}
36+
37+
async goto() {
38+
await super.goto()
39+
await this.addressesLink.click()
40+
await this.addressesWrapper.waitFor({ state: "visible" })
41+
}
2742
}

e2e/fixtures/account/modals/add-address-modal.ts renamed to e2e/fixtures/account/modals/address-modal.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Page, Locator } from "@playwright/test"
22
import { BaseModal } from "../../base/base-modal"
33

4-
export class AddAddressModal extends BaseModal {
5-
addAddressButton: Locator
4+
export class AddressModal extends BaseModal {
5+
saveButton: Locator
66
cancelButton: Locator
77

88
firstNameInput: Locator
@@ -16,10 +16,14 @@ export class AddAddressModal extends BaseModal {
1616
countrySelect: Locator
1717
phoneInput: Locator
1818

19-
constructor(page: Page) {
20-
super(page, page.getByTestId("add-address-modal"))
19+
constructor(page: Page, modalType: "add" | "edit") {
20+
if (modalType === "add") {
21+
super(page, page.getByTestId("add-address-modal"))
22+
} else {
23+
super(page, page.getByTestId("edit-address-modal"))
24+
}
2125

22-
this.addAddressButton = this.container.getByTestId("add-address-button")
26+
this.saveButton = this.container.getByTestId("save-button")
2327
this.cancelButton = this.container.getByTestId("cancel-button")
2428

2529
this.firstNameInput = this.container.getByTestId("first-name-input")

e2e/fixtures/base/nav-menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class NavMenu {
2323
this.storeLink = this.navMenu.getByTestId("store-link")
2424
this.searchLink = this.navMenu.getByTestId("search-link")
2525
this.accountLink = this.navMenu.getByTestId("account-link")
26-
this.cartLink = this.navMenu.getByTestId("cart-link")
26+
this.cartLink = this.navMenu.getByTestId("nav-cart-link")
2727
this.closeButton = this.navMenu.getByTestId("close-menu-button")
2828
this.shippingToLink = this.navMenu.getByTestId("shipping-to-button")
2929
this.shippingToMenu = this.navMenu.getByTestId("shipping-to-choices")

e2e/fixtures/category-page.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export class CategoryPage extends BasePage {
55
container: Locator
66
sortByContainer: Locator
77

8+
pageTitle: Locator
89
pagination: Locator
910
productsListLoader: Locator
1011
productsList: Locator
@@ -13,6 +14,7 @@ export class CategoryPage extends BasePage {
1314
constructor(page: Page) {
1415
super(page)
1516
this.container = page.getByTestId("category-container")
17+
this.pageTitle = page.getByTestId("category-page-title")
1618
this.sortByContainer = page.getByTestId("sort-by-container")
1719
this.productsListLoader = this.container.getByTestId("products-list-loader")
1820
this.productsList = this.container.getByTestId("products-list")
@@ -21,14 +23,9 @@ export class CategoryPage extends BasePage {
2123
}
2224

2325
async getProduct(name: string) {
24-
const productTitle = await this.container
25-
.getByTestId("product-title")
26-
.filter({
27-
hasText: name,
28-
})
29-
const product = this.productWrapper.filter({ has: productTitle })
26+
const product = this.productWrapper.filter({ hasText: name })
3027
return {
31-
product,
28+
locator: product,
3229
title: product.getByTestId("product-title"),
3330
price: product.getByTestId("price"),
3431
originalPrice: product.getByTestId("original-price"),

e2e/fixtures/checkout-page.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export class CheckoutPage extends BasePage {
2121
billingPhoneInput: Locator
2222
billingPostalInput: Locator
2323
billingProvinceInput: Locator
24-
shippingAddress2Input: Locator
2524
shippingAddressInput: Locator
2625
shippingCityInput: Locator
26+
shippingCompanyInput: Locator
2727
shippingFirstNameInput: Locator
2828
shippingLastNameInput: Locator
2929
shippingPhoneInput: Locator
@@ -114,13 +114,11 @@ export class CheckoutPage extends BasePage {
114114
this.billingProvinceInput = this.container.getByTestId(
115115
"billing-province-input"
116116
)
117-
this.shippingAddress2Input = this.container.getByTestId(
118-
"shipping-address-2-input"
119-
)
120117
this.shippingAddressInput = this.container.getByTestId(
121118
"shipping-address-input"
122119
)
123120
this.shippingCityInput = this.container.getByTestId("shipping-city-input")
121+
this.shippingCompanyInput = this.container.getByTestId("shipping-company-input")
124122
this.shippingFirstNameInput = this.container.getByTestId(
125123
"shipping-first-name-input"
126124
)
@@ -237,15 +235,15 @@ export class CheckoutPage extends BasePage {
237235
hasText: address,
238236
})
239237
await addressOption.getByTestId("shipping-address-radio").click()
240-
const addressText = (await addressOption.getAttribute("value")) || ""
238+
241239
const selectHandle = await this.shippingAddressSelect.elementHandle()
242240
await this.page.waitForFunction(
243241
(opts) => {
244242
const select = opts[0]
245243
const choice = opts[1]
246-
return select.textContent === choice
244+
return (select.textContent||"").includes(choice)
247245
},
248-
[selectHandle, addressText] as [ElementHandle, string]
246+
[selectHandle, address] as [ElementHandle, string]
249247
)
250248
}
251249

e2e/fixtures/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { CategoryPage } from "./category-page"
55
import { CheckoutPage } from "./checkout-page"
66
import { OrderPage } from "./order-page"
77
import { ProductPage } from "./product-page"
8+
import { StorePage } from "./store-page"
89

910
export const fixtures = base.extend<{
1011
resetDatabaseFixture: void
@@ -13,6 +14,7 @@ export const fixtures = base.extend<{
1314
checkoutPage: CheckoutPage
1415
orderPage: OrderPage
1516
productPage: ProductPage
17+
storePage: StorePage
1618
}>({
1719
page: async ({ page }, use) => {
1820
await page.goto("/")
@@ -45,4 +47,8 @@ export const fixtures = base.extend<{
4547
const productPage = new ProductPage(page)
4648
await use(productPage)
4749
},
50+
storePage: async ({ page }, use) => {
51+
const storePage = new StorePage(page)
52+
await use(storePage)
53+
},
4854
})

e2e/fixtures/store-page.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Locator, Page } from "@playwright/test"
2+
import { CategoryPage } from "./category-page"
3+
4+
export class StorePage extends CategoryPage {
5+
pageTitle: Locator
6+
7+
constructor(page: Page) {
8+
super(page)
9+
this.pageTitle = page.getByTestId("store-page-title")
10+
}
11+
12+
async goto() {
13+
await this.navMenu.open()
14+
await this.navMenu.storeLink.click()
15+
await this.pageTitle.waitFor({ state: "visible" })
16+
await this.productsListLoader.waitFor({ state: "hidden" })
17+
}
18+
}

0 commit comments

Comments
 (0)