Skip to content

Commit 6872e11

Browse files
committed
Add Swag Labs test suite
1 parent f04a2f8 commit 6872e11

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

examples/swag_labs_suite.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import pytest
2+
from parameterized import parameterized
3+
from seleniumbase import BaseCase
4+
5+
6+
class SwagLabsTests(BaseCase):
7+
8+
def login(self, user="standard_user"):
9+
""" Login to Swag Labs and assert that the login was successful. """
10+
if user not in (["standard_user", "problem_user"]):
11+
raise Exception("Invalid user!")
12+
self.open("https://www.saucedemo.com/")
13+
self.update_text("#user-name", user)
14+
self.update_text("#password", "secret_sauce")
15+
self.click('input[type="submit"]')
16+
self.assert_text("Products", "div.product_label")
17+
self.assert_element("#inventory_container")
18+
19+
@parameterized.expand([
20+
["standard_user"],
21+
["problem_user"],
22+
])
23+
@pytest.mark.run(order=1)
24+
def test_swag_labs_basic_functional_flow(self, user):
25+
""" This test checks for basic functional flow in the Swag Labs store.
26+
The test is parameterized, and receives the user to use for login.
27+
"""
28+
self.login(user)
29+
30+
# Verify that the "Test.allTheThings() T-Shirt" appears on the page
31+
item_name = "Test.allTheThings() T-Shirt"
32+
self.assert_text(item_name)
33+
34+
# Verify that a reverse-alphabetical sort works as expected
35+
self.select_option_by_value("select.product_sort_container", "za")
36+
if item_name not in self.get_text("div.inventory_item"):
37+
raise Exception('Sort Failed! Expecting "%s" on top!' % item_name)
38+
39+
# Add the "Test.allTheThings() T-Shirt" to the cart
40+
self.assert_exact_text("ADD TO CART", "button.btn_inventory")
41+
item_price = self.get_text("div.inventory_item_price")
42+
self.click("button.btn_inventory")
43+
self.assert_exact_text("REMOVE", "button.btn_inventory")
44+
self.assert_exact_text("1", "span.shopping_cart_badge")
45+
46+
# Verify your cart
47+
self.click("#shopping_cart_container path")
48+
self.assert_exact_text("Your Cart", "div.subheader")
49+
self.assert_text(item_name, "div.inventory_item_name")
50+
self.assert_exact_text("1", "div.cart_quantity")
51+
self.assert_exact_text("REMOVE", "button.cart_button")
52+
self.assert_element("link=CONTINUE SHOPPING")
53+
54+
# Checkout - Add info
55+
self.click("link=CHECKOUT")
56+
self.assert_exact_text("Checkout: Your Information", "div.subheader")
57+
self.assert_element("a.cart_cancel_link")
58+
self.update_text("#first-name", "SeleniumBase")
59+
self.update_text("#last-name", "Rocks")
60+
self.update_text("#postal-code", "01720")
61+
62+
# Checkout - Overview
63+
self.click('input.btn_primary')
64+
self.assert_exact_text("Checkout: Overview", "div.subheader")
65+
self.assert_element("link=CANCEL")
66+
self.assert_text(item_name, "div.inventory_item_name")
67+
self.assert_text(item_price, "div.inventory_item_price")
68+
self.assert_exact_text("1", "div.summary_quantity")
69+
70+
# Finish Checkout and verify item is no longer in cart
71+
self.click("link=FINISH")
72+
self.assert_exact_text("THANK YOU FOR YOUR ORDER", "h2")
73+
self.assert_element("div.pony_express")
74+
self.click("#shopping_cart_container path")
75+
self.assert_element_absent("div.inventory_item_name")
76+
self.click("link=CONTINUE SHOPPING")
77+
self.assert_element_absent("span.shopping_cart_badge")
78+
79+
@parameterized.expand([
80+
["standard_user"],
81+
["problem_user"],
82+
])
83+
@pytest.mark.run(order=2)
84+
def test_swag_labs_products_page_resource_verification(self, user):
85+
""" This test checks for 404 errors on the Swag Labs products page.
86+
The test is parameterized, and receives the user to use for login.
87+
"""
88+
self.login(user)
89+
self.assert_no_404_errors()

0 commit comments

Comments
 (0)