Skip to content

Commit d3831a3

Browse files
committed
Complete cart tests with verify, remove single/all, and checkout start
1 parent c27c578 commit d3831a3

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

pages/checkout_page.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from selenium.webdriver import Keys
2+
from selenium.webdriver.common.by import By
3+
from selenium.webdriver.support import expected_conditions as EC
4+
from selenium.webdriver.support.ui import WebDriverWait
5+
from selenium.common.exceptions import TimeoutException
6+
7+
class CheckoutPage:
8+
FIRST_NAME = (By.ID, "first-name")
9+
LAST_NAME = (By.ID, "last-name")
10+
POSTAL_CODE = (By.ID, "postal-code")
11+
CONTINUE_BUTTON = (By.ID, "continue")
12+
FINISH_BUTTON = (By.ID, "finish")
13+
COMPLETE_HEADER = (By.CLASS_NAME, "complete-header")
14+
15+
def __init__(self, driver):
16+
self.driver = driver
17+
self.wait = WebDriverWait(self.driver, 15)
18+
19+
def fill_info(self, first_name, last_name, postal_code):
20+
self.wait.until(EC.url_contains("checkout-step-one"))
21+
self.wait.until(EC.presence_of_element_located(self.FIRST_NAME))
22+
self.driver.find_element(*self.FIRST_NAME).send_keys(first_name)
23+
self.driver.find_element(*self.LAST_NAME).send_keys(last_name)
24+
self.driver.find_element(*self.POSTAL_CODE).send_keys(postal_code)
25+
return True
26+
27+
def continue_to_overview(self):
28+
try:
29+
continue_btn = self.wait.until(EC.element_to_be_clickable(self.CONTINUE_BUTTON))
30+
continue_btn.click()
31+
self.wait.until(EC.url_contains("checkout-step-two"))
32+
return True
33+
except TimeoutException:
34+
return False
35+
36+
def complete_checkout(self):
37+
try:
38+
finish_btn = self.wait.until(EC.element_to_be_clickable(self.FINISH_BUTTON))
39+
finish_btn.click()
40+
self.wait.until(EC.url_contains("checkout-complete"))
41+
return True
42+
except TimeoutException:
43+
return False

test/test_cart.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
from pages.inventory_page import InventoryPage
66
from pages.login_page import LoginPage
77
from pages.cart_page import CartPage
8+
from pages.checkout_page import CheckoutPage
89
from webdriver_manager.firefox import GeckoDriverManager
910
from config import config_for_login_page
1011
from config.config_for_cart_page import PRODUCTS
12+
import time
1113

1214
@pytest.fixture(scope="function")
1315
def cart_page_with_items(request):
@@ -65,3 +67,20 @@ def test_start_checkout(cart_page_with_items):
6567
assert "checkout-step-one.html" in cart_page_with_items.driver.current_url
6668
print(f"Current URL after checkout: {cart_page_with_items.driver.current_url}")
6769

70+
@pytest.mark.parametrize("first_name, last_name, postal_code", [("Juanito", "Alimana", "1969"), ("Procura", "Peralta", "1997")])
71+
72+
def test_full_e2e_checkout(cart_page_with_items, first_name, last_name, postal_code):
73+
cart_page_with_items.start_checkout()
74+
print(f"URL after start: {cart_page_with_items.driver.current_url}")
75+
time.sleep(2)
76+
assert "checkout-step-one.html" in cart_page_with_items.driver.current_url
77+
time.sleep(1) # Extra buffer for DOM
78+
checkout = CheckoutPage(cart_page_with_items.driver)
79+
checkout.fill_info(first_name, last_name, postal_code)
80+
assert checkout.continue_to_overview() == True
81+
assert "checkout-step-two.html" in checkout.driver.current_url
82+
assert checkout.complete_checkout() == True
83+
assert "checkout-complete.html" in checkout.driver.current_url
84+
assert "Thank you for your order!" in checkout.driver.page_source
85+
print(f"E2E complete with user {first_name} {last_name}, final URL: {checkout.driver.current_url}")
86+

0 commit comments

Comments
 (0)