nextjs-starter-medusa
582 строки · 26.3 Кб
1import { test, expect } from "../../index"
2import { compareFloats, getFloatValue } from "../../utils"
3
4test.describe("Checkout flow tests", async () => {
5test("Default checkout flow", async ({
6cartPage,
7checkoutPage,
8orderPage,
9productPage,
10storePage,
11}) => {
12await test.step("Navigate to a product page", async () => {
13await storePage.goto()
14const product = await storePage.getProduct("Sweatshirt")
15await product.locator.highlight()
16await product.locator.click()
17await productPage.container.waitFor({ state: "visible" })
18})
19
20await test.step("Add the product to the cart and goto checkout", async () => {
21await productPage.selectOption("M")
22await productPage.clickAddProduct()
23await productPage.cartDropdown.navCartLink.click()
24await productPage.cartDropdown.goToCartButton.click()
25await cartPage.container.waitFor({ state: "visible" })
26await cartPage.checkoutButton.click()
27await checkoutPage.container.waitFor({ state: "visible" })
28})
29
30await test.step("Enter in the first step of the checkout process", async () => {
31await test.step("Enter in the shipping address info", async () => {
32await checkoutPage.shippingFirstNameInput.fill("First")
33await checkoutPage.shippingLastNameInput.fill("Last")
34await checkoutPage.shippingCompanyInput.fill("MyCorp")
35await checkoutPage.shippingAddressInput.fill("123 Fake street")
36await checkoutPage.shippingPostalCodeInput.fill("80010")
37await checkoutPage.shippingCityInput.fill("Denver")
38await checkoutPage.shippingProvinceInput.fill("Colorado")
39await checkoutPage.shippingCountrySelect.selectOption("United States")
40})
41
42await test.step("Enter in the contact info and open the billing info form", async () => {
43await checkoutPage.shippingEmailInput.fill("test@example.com")
44await checkoutPage.shippingPhoneInput.fill("3031112222")
45await checkoutPage.billingAddressCheckbox.uncheck()
46})
47
48await test.step("Enter in the billing address info", async () => {
49await checkoutPage.billingFirstNameInput.fill("First")
50await checkoutPage.billingLastNameInput.fill("Last")
51await checkoutPage.billingCompanyInput.fill("MyCorp")
52await checkoutPage.billingAddressInput.fill("123 Fake street")
53await checkoutPage.billingPostalInput.fill("80010")
54await checkoutPage.billingCityInput.fill("Denver")
55await checkoutPage.billingProvinceInput.fill("Colorado")
56await checkoutPage.billingCountrySelect.selectOption("United States")
57await checkoutPage.submitAddressButton.click()
58})
59})
60
61await test.step("Complete the rest of the payment process", async () => {
62await checkoutPage.selectDeliveryOption("FakeEx Standard")
63await checkoutPage.submitDeliveryOptionButton.click()
64await checkoutPage.submitPaymentButton.click()
65await checkoutPage.submitOrderButton.click()
66await orderPage.container.waitFor({ state: "visible" })
67})
68
69await test.step("Verify the products ordered are correct", async () => {
70const product = await orderPage.getProduct("Sweatshirt", "M")
71await expect(product.name).toContainText("Sweatshirt")
72await expect(product.variant).toContainText("M")
73await expect(product.quantity).toContainText("1")
74})
75
76await test.step("Verify the shipping info is correct", async () => {
77const address = orderPage.shippingAddressSummary
78await expect(address).toContainText("First")
79await expect(address).toContainText("Last")
80await expect(address).toContainText("123 Fake street")
81await expect(address).toContainText("80010")
82await expect(address).toContainText("Denver")
83await expect(address).toContainText("US")
84
85const contact = orderPage.shippingContactSummary
86await expect(contact).toContainText("test@example.com")
87await expect(contact).toContainText("3031112222")
88
89const method = orderPage.shippingMethodSummary
90await expect(method).toContainText("FakeEx Standard")
91})
92})
93
94test("Editing checkout steps works as expected", async ({
95cartPage,
96checkoutPage,
97productPage,
98storePage,
99}) => {
100await test.step("Navigate to a product page", async () => {
101await storePage.goto()
102const product = await storePage.getProduct("Sweatshirt")
103await product.locator.highlight()
104await product.locator.click()
105await productPage.container.waitFor({ state: "visible" })
106})
107
108await test.step("Add the product to the cart and goto checkout", async () => {
109await productPage.selectOption("M")
110await productPage.clickAddProduct()
111await productPage.cartDropdown.navCartLink.click()
112await productPage.cartDropdown.goToCartButton.click()
113await cartPage.container.waitFor({ state: "visible" })
114await cartPage.checkoutButton.click()
115await checkoutPage.container.waitFor({ state: "visible" })
116})
117
118await test.step("Enter in the first step of the checkout process", async () => {
119await test.step("Enter in the shipping address info", async () => {
120await checkoutPage.shippingFirstNameInput.fill("First")
121await checkoutPage.shippingLastNameInput.fill("Last")
122await checkoutPage.shippingCompanyInput.fill("MyCorp")
123await checkoutPage.shippingAddressInput.fill("123 Fake street")
124await checkoutPage.shippingPostalCodeInput.fill("80010")
125await checkoutPage.shippingCityInput.fill("Denver")
126await checkoutPage.shippingProvinceInput.fill("Colorado")
127await checkoutPage.shippingCountrySelect.selectOption("United States")
128})
129
130await test.step("Enter in the contact info and open the billing info form", async () => {
131await checkoutPage.shippingEmailInput.fill("test@example.com")
132await checkoutPage.shippingPhoneInput.fill("3031112222")
133await checkoutPage.billingAddressCheckbox.uncheck()
134})
135
136await test.step("Enter in the billing address info", async () => {
137await checkoutPage.billingFirstNameInput.fill("First")
138await checkoutPage.billingLastNameInput.fill("Last")
139await checkoutPage.billingCompanyInput.fill("MyCorp")
140await checkoutPage.billingAddressInput.fill("123 Fake street")
141await checkoutPage.billingPostalInput.fill("80010")
142await checkoutPage.billingCityInput.fill("Denver")
143await checkoutPage.billingProvinceInput.fill("Colorado")
144await checkoutPage.billingCountrySelect.selectOption("United States")
145await checkoutPage.submitAddressButton.click()
146})
147})
148
149await test.step("Submit the delivery and payment options", async () => {
150await checkoutPage.selectDeliveryOption("FakeEx Standard")
151await checkoutPage.submitDeliveryOptionButton.click()
152await checkoutPage.submitPaymentButton.click()
153})
154
155await test.step("Edit the shipping info", async () => {
156await checkoutPage.editAddressButton.click()
157await test.step("Edit the shipping address", async () => {
158await checkoutPage.shippingFirstNameInput.fill("First1")
159await checkoutPage.shippingLastNameInput.fill("Last1")
160await checkoutPage.shippingCompanyInput.fill("MeCorp")
161await checkoutPage.shippingAddressInput.fill("123 Fake Road")
162await checkoutPage.shippingPostalCodeInput.fill("80011")
163await checkoutPage.shippingCityInput.fill("Donver")
164await checkoutPage.shippingProvinceInput.fill("CO")
165await checkoutPage.shippingCountrySelect.selectOption("Canada")
166})
167
168await test.step("Edit the shipping contact info", async () => {
169await checkoutPage.shippingEmailInput.fill("tester@example.com")
170await checkoutPage.shippingPhoneInput.fill("3231112222")
171})
172
173await test.step("Edit the billing info", async () => {
174await checkoutPage.billingFirstNameInput.fill("Farst")
175await checkoutPage.billingLastNameInput.fill("List")
176await checkoutPage.billingCompanyInput.fill("MistCorp")
177await checkoutPage.billingAddressInput.fill("321 Fake street")
178await checkoutPage.billingPostalInput.fill("80110")
179await checkoutPage.billingCityInput.fill("Denvur")
180await checkoutPage.billingProvinceInput.fill("AB")
181await checkoutPage.billingCountrySelect.selectOption("Canada")
182})
183await checkoutPage.submitAddressButton.click()
184})
185
186await test.step("Make sure the edits are reflected in the container", async () => {
187await test.step("Check shipping address summary", async () => {
188const shippingColumn = checkoutPage.shippingAddressSummary
189await expect(shippingColumn).toContainText("First1")
190await expect(shippingColumn).toContainText("Last1")
191await expect(shippingColumn).toContainText("123 Fake Road")
192await expect(shippingColumn).toContainText("80011")
193await expect(shippingColumn).toContainText("Donver")
194await expect(shippingColumn).toContainText("CA")
195})
196
197await test.step("Check shipping contact summary", async () => {
198const contactColumn = checkoutPage.shippingContactSummary
199await expect(contactColumn).toContainText("tester@example.com")
200await expect(contactColumn).toContainText("3231112222")
201})
202
203await test.step("Check billing summary", async () => {
204const billingColumn = checkoutPage.billingAddressSummary
205await expect(billingColumn).toContainText("Farst")
206await expect(billingColumn).toContainText("List")
207await expect(billingColumn).toContainText("321 Fake street")
208await expect(billingColumn).toContainText("Denvur")
209await expect(billingColumn).toContainText("CA")
210})
211})
212})
213
214test("Shipping info saved is filled back into the forms after clicking edit", async ({
215cartPage,
216checkoutPage,
217productPage,
218storePage,
219}) => {
220await test.step("Navigate to a product page", async () => {
221await storePage.goto()
222const product = await storePage.getProduct("Sweatshirt")
223await product.locator.highlight()
224await product.locator.click()
225await productPage.container.waitFor({ state: "visible" })
226})
227
228await test.step("Add the product to the cart and goto checkout", async () => {
229await productPage.selectOption("M")
230await productPage.clickAddProduct()
231await productPage.cartDropdown.navCartLink.click()
232await productPage.cartDropdown.goToCartButton.click()
233await cartPage.container.waitFor({ state: "visible" })
234await cartPage.checkoutButton.click()
235await checkoutPage.container.waitFor({ state: "visible" })
236})
237
238await test.step("Enter in the first step of the checkout process", async () => {
239await test.step("Enter in the shipping address info", async () => {
240await checkoutPage.shippingFirstNameInput.fill("First")
241await checkoutPage.shippingLastNameInput.fill("Last")
242await checkoutPage.shippingCompanyInput.fill("MyCorp")
243await checkoutPage.shippingAddressInput.fill("123 Fake street")
244await checkoutPage.shippingPostalCodeInput.fill("80010")
245await checkoutPage.shippingCityInput.fill("Denver")
246await checkoutPage.shippingProvinceInput.fill("Colorado")
247await checkoutPage.shippingCountrySelect.selectOption("United States")
248})
249
250await test.step("Enter in the contact info and open the billing info form", async () => {
251await checkoutPage.shippingEmailInput.fill("test@example.com")
252await checkoutPage.shippingPhoneInput.fill("3031112222")
253await checkoutPage.billingAddressCheckbox.uncheck()
254})
255
256await test.step("Enter in the billing address info", async () => {
257await checkoutPage.billingFirstNameInput.fill("First")
258await checkoutPage.billingLastNameInput.fill("Last")
259await checkoutPage.billingCompanyInput.fill("MyCorp")
260await checkoutPage.billingAddressInput.fill("123 Fake street")
261await checkoutPage.billingPostalInput.fill("80010")
262await checkoutPage.billingCityInput.fill("Denver")
263await checkoutPage.billingProvinceInput.fill("Colorado")
264await checkoutPage.billingCountrySelect.selectOption("United States")
265await checkoutPage.submitAddressButton.click()
266})
267})
268
269await test.step("Click the edit address form and ensure the fields are filled correctly", async () => {
270await checkoutPage.editAddressButton.click()
271await test.step("Check the shipping address", async () => {
272await expect(checkoutPage.shippingFirstNameInput).toHaveValue("First")
273await expect(checkoutPage.shippingLastNameInput).toHaveValue("Last")
274await expect(checkoutPage.shippingCompanyInput).toHaveValue("MyCorp")
275await expect(checkoutPage.shippingAddressInput).toHaveValue(
276"123 Fake street"
277)
278await expect(checkoutPage.shippingPostalCodeInput).toHaveValue("80010")
279await expect(checkoutPage.shippingCityInput).toHaveValue("Denver")
280await expect(checkoutPage.shippingProvinceInput).toHaveValue("Colorado")
281await expect(checkoutPage.shippingCountrySelect).toHaveValue("us")
282})
283
284await test.step("Check the shipping contact", async () => {
285await expect(checkoutPage.shippingEmailInput).toHaveValue(
286"test@example.com"
287)
288await expect(checkoutPage.shippingPhoneInput).toHaveValue("3031112222")
289})
290
291await test.step("Check the billing address", async () => {
292await expect(checkoutPage.billingFirstNameInput).toHaveValue("First")
293await expect(checkoutPage.billingLastNameInput).toHaveValue("Last")
294await expect(checkoutPage.billingCompanyInput).toHaveValue("MyCorp")
295await expect(checkoutPage.billingAddressInput).toHaveValue(
296"123 Fake street"
297)
298await expect(checkoutPage.billingPostalInput).toHaveValue("80010")
299await expect(checkoutPage.billingCityInput).toHaveValue("Denver")
300await expect(checkoutPage.billingProvinceInput).toHaveValue("Colorado")
301await expect(checkoutPage.billingCountrySelect).toHaveValue("us")
302})
303})
304
305await test.step("Set the billing info to the same as checked and perform checks", async () => {
306await checkoutPage.billingAddressCheckbox.check()
307await checkoutPage.submitAddressButton.click()
308await checkoutPage.editAddressButton.click()
309await expect(checkoutPage.billingAddressCheckbox).toBeChecked()
310})
311})
312
313test("Shipping info in the checkout page is correctly reflected in the summary", async ({
314cartPage,
315checkoutPage,
316productPage,
317storePage,
318}) => {
319await test.step("Navigate to a product page", async () => {
320await storePage.goto()
321const product = await storePage.getProduct("Sweatshirt")
322await product.locator.highlight()
323await product.locator.click()
324await productPage.container.waitFor({ state: "visible" })
325})
326
327await test.step("Add the product to the cart and goto checkout", async () => {
328await productPage.selectOption("M")
329await productPage.clickAddProduct()
330await productPage.cartDropdown.navCartLink.click()
331await productPage.cartDropdown.goToCartButton.click()
332await cartPage.container.waitFor({ state: "visible" })
333await cartPage.checkoutButton.click()
334await checkoutPage.container.waitFor({ state: "visible" })
335})
336
337await test.step("Enter in the first step of the checkout process", async () => {
338await test.step("Enter in the shipping address info", async () => {
339await checkoutPage.shippingFirstNameInput.fill("First")
340await checkoutPage.shippingLastNameInput.fill("Last")
341await checkoutPage.shippingCompanyInput.fill("MyCorp")
342await checkoutPage.shippingAddressInput.fill("123 Fake street")
343await checkoutPage.shippingPostalCodeInput.fill("80010")
344await checkoutPage.shippingCityInput.fill("Denver")
345await checkoutPage.shippingProvinceInput.fill("Colorado")
346await checkoutPage.shippingCountrySelect.selectOption("United States")
347})
348
349await test.step("Enter in the contact info and open the billing info form", async () => {
350await checkoutPage.shippingEmailInput.fill("test@example.com")
351await checkoutPage.shippingPhoneInput.fill("3031112222")
352await checkoutPage.billingAddressCheckbox.uncheck()
353})
354
355await test.step("Enter in the billing address info", async () => {
356await checkoutPage.billingFirstNameInput.fill("First")
357await checkoutPage.billingLastNameInput.fill("Last")
358await checkoutPage.billingCompanyInput.fill("MyCorp")
359await checkoutPage.billingAddressInput.fill("123 Fake street")
360await checkoutPage.billingPostalInput.fill("80010")
361await checkoutPage.billingCityInput.fill("Denver")
362await checkoutPage.billingProvinceInput.fill("Colorado")
363await checkoutPage.billingCountrySelect.selectOption("United States")
364await checkoutPage.submitAddressButton.click()
365})
366})
367
368await test.step("Ensure the shipping column reflects the entered data", async () => {
369const shippingColumn = checkoutPage.shippingAddressSummary
370await expect(shippingColumn).toContainText("First")
371await expect(shippingColumn).toContainText("Last")
372await expect(shippingColumn).toContainText("123 Fake street")
373await expect(shippingColumn).toContainText("80010")
374await expect(shippingColumn).toContainText("Denver")
375await expect(shippingColumn).toContainText("US")
376})
377
378await test.step("Ensure the contact column reflects the entered data", async () => {
379const contactColumn = checkoutPage.shippingContactSummary
380await expect(contactColumn).toContainText("test@example.com")
381await expect(contactColumn).toContainText("3031112222")
382})
383
384await test.step("Ensure the billing column reflects the entered data", async () => {
385const billingColumn = checkoutPage.billingAddressSummary
386await expect(billingColumn).toContainText("First")
387await expect(billingColumn).toContainText("Last")
388await expect(billingColumn).toContainText("123 Fake street")
389await expect(billingColumn).toContainText("Denver")
390await expect(billingColumn).toContainText("US")
391})
392
393await test.step("Edit the billing info so it is the same as the billing address", async () => {
394await checkoutPage.editAddressButton.click()
395await checkoutPage.billingAddressCheckbox.check()
396await checkoutPage.submitAddressButton.click()
397const billingColumn = checkoutPage.billingAddressSummary
398await expect(billingColumn).toContainText("are the same.")
399})
400})
401
402test("Entering checkout, leaving, then returning takes you back to the correct checkout spot", async ({
403cartPage,
404checkoutPage,
405productPage,
406storePage,
407}) => {
408await test.step("Navigate to a product page", async () => {
409await storePage.goto()
410const product = await storePage.getProduct("Sweatshirt")
411await product.locator.highlight()
412await product.locator.click()
413await productPage.container.waitFor({ state: "visible" })
414})
415
416await test.step("Add the product to the cart and goto checkout", async () => {
417await productPage.selectOption("M")
418await productPage.clickAddProduct()
419await productPage.cartDropdown.navCartLink.click()
420await productPage.cartDropdown.goToCartButton.click()
421await cartPage.container.waitFor({ state: "visible" })
422await cartPage.checkoutButton.click()
423await checkoutPage.container.waitFor({ state: "visible" })
424})
425
426await test.step("Navigate away and back to the checkout page", async () => {
427await checkoutPage.backToCartLink.click()
428await cartPage.checkoutButton.click()
429await checkoutPage.container.waitFor({ state: "visible" })
430await expect(checkoutPage.submitAddressButton).toBeVisible()
431})
432
433await test.step("Enter in the first step of the checkout process", async () => {
434await test.step("Enter in the shipping address info", async () => {
435await checkoutPage.shippingFirstNameInput.fill("First")
436await checkoutPage.shippingLastNameInput.fill("Last")
437await checkoutPage.shippingCompanyInput.fill("MyCorp")
438await checkoutPage.shippingAddressInput.fill("123 Fake street")
439await checkoutPage.shippingPostalCodeInput.fill("80010")
440await checkoutPage.shippingCityInput.fill("Denver")
441await checkoutPage.shippingProvinceInput.fill("Colorado")
442await checkoutPage.shippingCountrySelect.selectOption("United States")
443})
444
445await test.step("Enter in the contact info and open the billing info form", async () => {
446await checkoutPage.shippingEmailInput.fill("test@example.com")
447await checkoutPage.shippingPhoneInput.fill("3031112222")
448await checkoutPage.billingAddressCheckbox.uncheck()
449})
450
451await test.step("Enter in the billing address info", async () => {
452await checkoutPage.billingFirstNameInput.fill("First")
453await checkoutPage.billingLastNameInput.fill("Last")
454await checkoutPage.billingCompanyInput.fill("MyCorp")
455await checkoutPage.billingAddressInput.fill("123 Fake street")
456await checkoutPage.billingPostalInput.fill("80010")
457await checkoutPage.billingCityInput.fill("Denver")
458await checkoutPage.billingProvinceInput.fill("Colorado")
459await checkoutPage.billingCountrySelect.selectOption("United States")
460})
461await checkoutPage.submitAddressButton.click()
462await checkoutPage.deliveryOptionRadio
463.first()
464.waitFor({ state: "visible" })
465})
466
467await test.step("Navigate away and back to the checkout page", async () => {
468await checkoutPage.backToCartLink.click()
469await cartPage.checkoutButton.click()
470await checkoutPage.container.waitFor({ state: "visible" })
471await expect(checkoutPage.submitDeliveryOptionButton).toBeVisible()
472})
473
474await test.step("Submit the delivery choice and navigate back and forth", async () => {
475await checkoutPage.selectDeliveryOption("FakeEx Standard")
476await checkoutPage.submitDeliveryOptionButton.click()
477await checkoutPage.submitPaymentButton.waitFor({ state: "visible" })
478await checkoutPage.backToCartLink.click()
479await cartPage.checkoutButton.click()
480await checkoutPage.container.waitFor({ state: "visible" })
481await expect(checkoutPage.submitPaymentButton).toBeVisible()
482})
483
484await test.step("Submit the payment info and navigate back and forth", async () => {
485await checkoutPage.submitPaymentButton.click()
486await checkoutPage.submitOrderButton.waitFor({ state: "visible" })
487await checkoutPage.backToCartLink.click()
488await cartPage.checkoutButton.click()
489await checkoutPage.container.waitFor({ state: "visible" })
490await expect(checkoutPage.submitPaymentButton).toBeVisible()
491})
492
493await test.step("Click edit on the shipping info and navigate back and forth", async () => {
494await checkoutPage.editAddressButton.click()
495await checkoutPage.backToCartLink.click()
496await cartPage.checkoutButton.click()
497await checkoutPage.container.waitFor({ state: "visible" })
498await expect(checkoutPage.submitPaymentButton).toBeVisible()
499})
500
501await test.step("Click edit on the shipping choice and navigate back and forth", async () => {
502await checkoutPage.editDeliveryButton.click()
503await checkoutPage.backToCartLink.click()
504await cartPage.checkoutButton.click()
505await checkoutPage.container.waitFor({ state: "visible" })
506await expect(checkoutPage.submitPaymentButton).toBeVisible()
507})
508})
509
510test("Verify the prices carries over to checkout", async ({
511cartPage,
512checkoutPage,
513productPage,
514storePage,
515}) => {
516await test.step("Navigate to the product page - go to the store page and click on the Sweatshirt product", async () => {
517await storePage.goto()
518const product = await storePage.getProduct("Sweatshirt")
519await product.locator.click()
520await productPage.container.waitFor({ state: "visible" })
521})
522
523let sweatshirtSmallPrice = 0
524let sweatshirtMediumPrice = 0
525await test.step("Add the sweatshirts to the cart", async () => {
526await productPage.selectOption("S")
527sweatshirtSmallPrice = getFloatValue(
528(await productPage.productPrice.getAttribute("data-value")) || "0"
529)
530await productPage.clickAddProduct()
531await productPage.cartDropdown.close()
532await productPage.selectOption("M")
533sweatshirtMediumPrice = getFloatValue(
534(await productPage.productPrice.getAttribute("data-value")) || "0"
535)
536await productPage.clickAddProduct()
537await productPage.cartDropdown.close()
538})
539
540await test.step("Navigate to another product - Sweatpants", async () => {
541await storePage.goto()
542const product = await storePage.getProduct("Sweatpants")
543await product.locator.click()
544await productPage.container.waitFor({ state: "visible" })
545})
546
547let sweatpantsSmallPrice = 0
548await test.step("Add the small sweatpants to the cart", async () => {
549await productPage.selectOption("S")
550sweatpantsSmallPrice = getFloatValue(
551(await productPage.productPrice.getAttribute("data-value")) || "0"
552)
553await productPage.clickAddProduct()
554await productPage.cartDropdown.close()
555await productPage.selectOption("S")
556await productPage.clickAddProduct()
557await productPage.cartDropdown.goToCartButton.click()
558await productPage.cartDropdown.close()
559await cartPage.container.waitFor({ state: "visible" })
560})
561
562await test.step("Verify the price in the cart is the expected value", async () => {
563const total = getFloatValue(
564(await cartPage.cartSubtotal.getAttribute("data-value")) || "0"
565)
566const calculatedTotal =
5672 * sweatpantsSmallPrice + sweatshirtSmallPrice + sweatshirtMediumPrice
568expect(compareFloats(total, calculatedTotal)).toBe(0)
569await cartPage.checkoutButton.click()
570await checkoutPage.container.waitFor({ state: "visible" })
571})
572
573await test.step("Go to checkout and verify the price in the checkout is the expected value", async () => {
574const total = getFloatValue(
575(await checkoutPage.cartSubtotal.getAttribute("data-value")) || "0"
576)
577const calculatedTotal =
5782 * sweatpantsSmallPrice + sweatshirtSmallPrice + sweatpantsSmallPrice
579expect(compareFloats(total, calculatedTotal)).toBe(0)
580})
581})
582})
583