nextjs-starter-medusa
295 строк · 9.8 Кб
1import { ElementHandle, Locator, Page } from "@playwright/test"
2import { BasePage } from "./base/base-page"
3
4export class CheckoutPage extends BasePage {
5backToCartLink: Locator
6storeLink: Locator
7container: Locator
8editAddressButton: Locator
9editDeliveryButton: Locator
10editPaymentButton: Locator
11
12shippingAddressSelect: Locator
13shippingAddressOptions: Locator
14shippingAddressOption: Locator
15
16billingAddressCheckbox: Locator
17billingAddressInput: Locator
18billingCityInput: Locator
19billingCompanyInput: Locator
20billingFirstNameInput: Locator
21billingLastNameInput: Locator
22billingPhoneInput: Locator
23billingPostalInput: Locator
24billingProvinceInput: Locator
25shippingAddressInput: Locator
26shippingCityInput: Locator
27shippingCompanyInput: Locator
28shippingEmailInput: Locator
29shippingFirstNameInput: Locator
30shippingLastNameInput: Locator
31shippingPhoneInput: Locator
32shippingPostalCodeInput: Locator
33shippingProvinceInput: Locator
34
35billingCountrySelect: Locator
36shippingCountrySelect: Locator
37
38shippingAddressSummary: Locator
39shippingContactSummary: Locator
40billingAddressSummary: Locator
41
42submitAddressButton: Locator
43addressErrorMessage: Locator
44
45deliveryOptionsContainer: Locator
46deliveryOptionRadio: Locator
47deliveryOptionErrorMessage: Locator
48submitDeliveryOptionButton: Locator
49deliveryOptionSummary: Locator
50
51paymentMethodSummary: Locator
52paymentDetailsSummary: Locator
53paymentMethodErrorMessage: Locator
54stripePaymentErrorMessage: Locator
55paypalPaymentErrorMessage: Locator
56manualPaymentErrorMessage: Locator
57submitPaymentButton: Locator
58submitOrderButton: Locator
59
60discountButton: Locator
61discountInput: Locator
62discountApplyButton: Locator
63discountErrorMessage: Locator
64discountRow: Locator
65giftCardRow: Locator
66giftCardCode: Locator
67giftCardAmount: Locator
68giftCardRemoveButton: Locator
69cartSubtotal: Locator
70cartDiscount: Locator
71cartGiftCardAmount: Locator
72cartShipping: Locator
73cartTaxes: Locator
74cartTotal: Locator
75itemsTable: Locator
76itemRow: Locator
77itemTitle: Locator
78itemVariant: Locator
79itemQuantity: Locator
80itemOriginalPrice: Locator
81itemReducedPrice: Locator
82itemUnitOriginalPrice: Locator
83itemUnitReducedPrice: Locator
84
85constructor(page: Page) {
86super(page)
87this.backToCartLink = page.getByTestId("back-to-cart-link")
88this.storeLink = page.getByTestId("store-link")
89this.container = page.getByTestId("checkout-container")
90
91this.editAddressButton = this.container.getByTestId("edit-address-button")
92this.editDeliveryButton = this.container.getByTestId("edit-delivery-button")
93this.editPaymentButton = this.container.getByTestId("edit-payment-button")
94
95this.shippingAddressSelect = this.container.getByTestId(
96"shipping-address-select"
97)
98this.shippingAddressOptions = this.container.getByTestId(
99"shipping-address-options"
100)
101this.shippingAddressOption = this.container.getByTestId(
102"shipping-address-option"
103)
104this.billingAddressCheckbox = this.container.getByTestId(
105"billing-address-checkbox"
106)
107this.billingAddressInput = this.container.getByTestId(
108"billing-address-input"
109)
110this.billingCityInput = this.container.getByTestId("billing-city-input")
111this.billingCompanyInput = this.container.getByTestId(
112"billing-company-input"
113)
114this.billingFirstNameInput = this.container.getByTestId(
115"billing-first-name-input"
116)
117this.billingLastNameInput = this.container.getByTestId(
118"billing-last-name-input"
119)
120this.billingPhoneInput = this.container.getByTestId("billing-phone-input")
121this.billingPostalInput = this.container.getByTestId("billing-postal-input")
122this.billingProvinceInput = this.container.getByTestId(
123"billing-province-input"
124)
125this.shippingAddressInput = this.container.getByTestId(
126"shipping-address-input"
127)
128this.shippingCityInput = this.container.getByTestId("shipping-city-input")
129this.shippingCompanyInput = this.container.getByTestId(
130"shipping-company-input"
131)
132this.shippingEmailInput = this.container.getByTestId("shipping-email-input")
133this.shippingFirstNameInput = this.container.getByTestId(
134"shipping-first-name-input"
135)
136this.shippingLastNameInput = this.container.getByTestId(
137"shipping-last-name-input"
138)
139this.shippingPhoneInput = this.container.getByTestId("shipping-phone-input")
140this.shippingPostalCodeInput = this.container.getByTestId(
141"shipping-postal-code-input"
142)
143this.shippingProvinceInput = this.container.getByTestId(
144"shipping-province-input"
145)
146
147this.billingCountrySelect = this.container.getByTestId(
148"billing-country-select"
149)
150this.shippingCountrySelect = this.container.getByTestId(
151"shipping-country-select"
152)
153
154this.shippingAddressSummary = this.container.getByTestId(
155"shipping-address-summary"
156)
157this.shippingContactSummary = this.container.getByTestId(
158"shipping-contact-summary"
159)
160this.billingAddressSummary = this.container.getByTestId(
161"billing-address-summary"
162)
163
164this.submitAddressButton = this.container.getByTestId(
165"submit-address-button"
166)
167this.addressErrorMessage = this.container.getByTestId(
168"address-error-message"
169)
170
171this.deliveryOptionsContainer = this.container.getByTestId(
172"delivery-options-container"
173)
174this.deliveryOptionRadio = this.container.getByTestId(
175"delivery-option-radio"
176)
177this.deliveryOptionErrorMessage = this.container.getByTestId(
178"delivery-option-error-message"
179)
180this.submitDeliveryOptionButton = this.container.getByTestId(
181"submit-delivery-option-button"
182)
183this.deliveryOptionSummary = this.container.getByTestId(
184"delivery-option-summary"
185)
186
187this.paymentMethodSummary = this.container.getByTestId(
188"payment-method-summary"
189)
190this.paymentDetailsSummary = this.container.getByTestId(
191"payment-details-summary"
192)
193this.paymentMethodErrorMessage = this.container.getByTestId(
194"payment-method-error-message"
195)
196this.submitPaymentButton = this.container.getByTestId(
197"submit-payment-button"
198)
199this.stripePaymentErrorMessage = this.container.getByTestId(
200"stripe-payment-error-message"
201)
202this.paypalPaymentErrorMessage = this.container.getByTestId(
203"paypal-payment-error-message"
204)
205this.manualPaymentErrorMessage = this.container.getByTestId(
206"manual-payment-error-message"
207)
208this.submitOrderButton = this.container.getByTestId("submit-order-button")
209
210this.discountButton = this.container.getByTestId("add-discount-button")
211this.discountInput = this.container.getByTestId("discount-input")
212this.discountApplyButton = this.container.getByTestId(
213"discount-apply-button"
214)
215this.discountErrorMessage = this.container.getByTestId(
216"discount-error-message"
217)
218this.discountRow = this.container.getByTestId("discount-row")
219this.giftCardRow = this.container.getByTestId("gift-card")
220this.giftCardCode = this.container.getByTestId("gift-card-code")
221this.giftCardAmount = this.container.getByTestId("gift-card-amount")
222this.giftCardRemoveButton = this.container.getByTestId(
223"remove-gift-card-button"
224)
225this.cartSubtotal = this.container.getByTestId("cart-subtotal")
226this.cartDiscount = this.container.getByTestId("cart-discount")
227this.cartGiftCardAmount = this.container.getByTestId(
228"cart-gift-card-amount"
229)
230this.cartShipping = this.container.getByTestId("cart-shipping")
231this.cartTaxes = this.container.getByTestId("cart-taxes")
232this.cartTotal = this.container.getByTestId("cart-total")
233this.itemsTable = this.container.getByTestId("items-table")
234this.itemRow = this.container.getByTestId("item-row")
235this.itemTitle = this.container.getByTestId("item-title")
236this.itemVariant = this.container.getByTestId("item-variant")
237this.itemQuantity = this.container.getByTestId("item-quantity")
238this.itemOriginalPrice = this.container.getByTestId("item-original-price")
239this.itemReducedPrice = this.container.getByTestId("item-reduced-price")
240this.itemUnitOriginalPrice = this.container.getByTestId(
241"item-unit-original-price"
242)
243this.itemUnitReducedPrice = this.container.getByTestId(
244"item-unit-reduced-price"
245)
246}
247
248async selectSavedAddress(address: string) {
249await this.shippingAddressSelect.click()
250const addressOption = this.shippingAddressOption.filter({
251hasText: address,
252})
253await addressOption.getByTestId("shipping-address-radio").click()
254
255const selectHandle = await this.shippingAddressSelect.elementHandle()
256await this.page.waitForFunction(
257(opts) => {
258const select = opts[0]
259const choice = opts[1]
260return (select.textContent || "").includes(choice)
261},
262[selectHandle, address] as [ElementHandle, string]
263)
264}
265
266async selectDeliveryOption(option: string) {
267await this.deliveryOptionRadio.filter({ hasText: option }).click()
268}
269
270async getGiftCard(code: string) {
271const giftCardRow = this.giftCardRow.filter({
272hasText: code,
273})
274const amount = giftCardRow.getByTestId("gift-card-amount")
275return {
276locator: giftCardRow,
277code: giftCardRow.getByTestId("gift-card-code"),
278amount,
279amountValue: await amount.getAttribute("data-value"),
280removeButton: giftCardRow.getByTestId("remove-gift-card-button"),
281}
282}
283
284async getDiscount(code: string) {
285const discount = this.discountRow
286const amount = discount.getByTestId("discount-amount")
287return {
288locator: discount,
289code: discount.getByTestId("discount-code"),
290amount,
291amountValue: await amount.getAttribute("data-value"),
292removeButton: discount.getByTestId("remove-discount-button"),
293}
294}
295}
296