-
Notifications
You must be signed in to change notification settings - Fork 989
/
test_swag_labs.py
81 lines (70 loc) · 3.58 KB
/
test_swag_labs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from seleniumbase import BaseCase
BaseCase.main(__name__, __file__)
class SwagLabsTests(BaseCase):
def login_to_swag_labs(self, username="standard_user"):
"""Login to Swag Labs and verify success."""
self.open("https://www.saucedemo.com")
if username not in self.get_text("#login_credentials"):
self.fail("Invalid user for login: %s" % username)
self.type("#user-name", username)
self.type("#password", "secret_sauce")
self.click('input[type="submit"]')
self.assert_element("div.inventory_list")
self.assert_element('.inventory_item:contains("Sauce Labs Backpack")')
def test_swag_labs_basic_flow(self):
"""This test checks functional flow of the Swag Labs store."""
self.login_to_swag_labs(username="standard_user")
# Verify that the "Test.allTheThings() T-Shirt" appears on the page
item_name = "Test.allTheThings() T-Shirt"
self.assert_text(item_name)
# Verify that a reverse-alphabetical sort works as expected
self.select_option_by_value("select.product_sort_container", "za")
if item_name not in self.get_text("div.inventory_item"):
self.fail('Sort Failed! Expecting "%s" on top!' % item_name)
# Add the "Test.allTheThings() T-Shirt" to the cart
self.assert_exact_text("Add to cart", "button.btn_inventory")
item_price = self.get_text("div.inventory_item_price")
self.click("button.btn_inventory")
self.assert_exact_text("Remove", "button.btn_inventory")
self.assert_exact_text("1", "span.shopping_cart_badge")
# Verify your cart
self.click("#shopping_cart_container a")
self.assert_element('span:contains("Your Cart")')
self.assert_text(item_name, "div.inventory_item_name")
self.assert_exact_text("1", "div.cart_quantity")
self.assert_exact_text("Remove", "button.cart_button")
self.assert_element("button#continue-shopping")
# Checkout - Add info
self.click("button#checkout")
self.assert_element('span:contains("Checkout: Your Information")')
self.assert_element("button#cancel")
self.type("#first-name", "SeleniumBase")
self.type("#last-name", "Rocks")
self.type("#postal-code", "01720")
# Checkout - Overview
self.click("input#continue")
self.assert_element('span:contains("Checkout: Overview")')
self.assert_element("button#cancel")
self.assert_text(item_name, "div.inventory_item_name")
self.assert_text(item_price, "div.inventory_item_price")
self.assert_exact_text("1", "div.cart_quantity")
# Finish Checkout and verify that the cart is now empty
self.click("button#finish")
self.assert_exact_text("Thank you for your order!", "h2")
self.click("#shopping_cart_container a")
self.assert_element_absent("div.inventory_item_name")
self.click("button#continue-shopping")
self.assert_element_absent("span.shopping_cart_badge")
def tearDown(self):
self.save_teardown_screenshot() # Only if a test fails
# Reset App State and Logout if the controls are present
try:
self.wait_for_ready_state_complete()
if self.is_element_visible("#react-burger-menu-btn"):
self.click("#react-burger-menu-btn")
self.wait_for_element("a#reset_sidebar_link")
self.js_click_if_present("a#reset_sidebar_link")
self.js_click_if_present("a#logout_sidebar_link")
except Exception:
pass
super().tearDown()