Skip to content

Commit b2c6a9b

Browse files
committed
Update the Swag Labs tests
1 parent f031600 commit b2c6a9b

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

examples/swag_labs_suite.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
class SwagLabsTests(BaseCase):
77

8-
def login(self, user="standard_user"):
8+
def login(self, username="standard_user"):
99
""" Login to Swag Labs and verify that login was successful. """
1010
self.open("https://www.saucedemo.com/")
11-
if user not in self.get_text("#login_credentials"):
12-
self.fail("Invalid user for login: %s" % user)
13-
self.update_text("#user-name", user)
11+
if username not in self.get_text("#login_credentials"):
12+
self.fail("Invalid user for login: %s" % username)
13+
self.update_text("#user-name", username)
1414
self.update_text("#password", "secret_sauce")
1515
self.click('input[type="submit"]')
1616
self.assert_element("#inventory_container")
@@ -21,10 +21,10 @@ def login(self, user="standard_user"):
2121
["problem_user"],
2222
])
2323
@pytest.mark.run(order=1)
24-
def test_swag_labs_basic_functional_flow(self, user):
24+
def test_swag_labs_basic_functional_flow(self, username):
2525
""" This test checks functional flow of the Swag Labs store.
2626
This test is parameterized, and receives the user for login. """
27-
self.login(user=user)
27+
self.login(username=username)
2828

2929
# Verify that the "Test.allTheThings() T-Shirt" appears on the page
3030
item_name = "Test.allTheThings() T-Shirt"
@@ -48,7 +48,11 @@ def test_swag_labs_basic_functional_flow(self, user):
4848
self.assert_text(item_name, "div.inventory_item_name")
4949
self.assert_exact_text("1", "div.cart_quantity")
5050
self.assert_exact_text("REMOVE", "button.cart_button")
51-
self.assert_element("link=CONTINUE SHOPPING")
51+
continue_shopping_button = "link=CONTINUE SHOPPING"
52+
if self.browser == "safari":
53+
# Safari sees this element differently
54+
continue_shopping_button = "link=Continue Shopping"
55+
self.assert_element(continue_shopping_button)
5256

5357
# Checkout - Add info
5458
self.click("link=CHECKOUT")
@@ -72,16 +76,16 @@ def test_swag_labs_basic_functional_flow(self, user):
7276
self.assert_element("div.pony_express")
7377
self.click("#shopping_cart_container path")
7478
self.assert_element_absent("div.inventory_item_name")
75-
self.click("link=CONTINUE SHOPPING")
79+
self.click(continue_shopping_button)
7680
self.assert_element_absent("span.shopping_cart_badge")
7781

7882
@parameterized.expand([
7983
["standard_user"],
8084
["problem_user"],
8185
])
8286
@pytest.mark.run(order=2)
83-
def test_swag_labs_products_page_resource_verification(self, user):
87+
def test_swag_labs_products_page_resource_verification(self, username):
8488
""" This test checks for 404 errors on the Swag Labs products page.
8589
This test is parameterized, and receives the user for login. """
86-
self.login(user=user)
90+
self.login(username=username)
8791
self.assert_no_404_errors()

examples/test_swag_labs.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33

44
class SwagLabsTests(BaseCase):
55

6-
def login(self, user="standard_user"):
6+
def login(self, username="standard_user"):
77
""" Login to Swag Labs and verify that login was successful. """
88
self.open("https://www.saucedemo.com/")
9-
if user not in self.get_text("#login_credentials"):
10-
self.fail("Invalid user for login: %s" % user)
11-
self.update_text("#user-name", user)
9+
if username not in self.get_text("#login_credentials"):
10+
self.fail("Invalid user for login: %s" % username)
11+
self.update_text("#user-name", username)
1212
self.update_text("#password", "secret_sauce")
1313
self.click('input[type="submit"]')
1414
self.assert_element("#inventory_container")
1515
self.assert_text("Products", "div.product_label")
1616

1717
def test_swag_labs_basic_flow(self):
1818
""" This test checks functional flow of the Swag Labs store. """
19-
self.login(user="standard_user")
19+
self.login(username="standard_user")
2020

2121
# Verify that the "Test.allTheThings() T-Shirt" appears on the page
2222
item_name = "Test.allTheThings() T-Shirt"
@@ -40,7 +40,12 @@ def test_swag_labs_basic_flow(self):
4040
self.assert_text(item_name, "div.inventory_item_name")
4141
self.assert_exact_text("1", "div.cart_quantity")
4242
self.assert_exact_text("REMOVE", "button.cart_button")
43-
self.assert_element("link=CONTINUE SHOPPING")
43+
continue_shopping_button = "link=CONTINUE SHOPPING"
44+
if self.browser == "safari":
45+
# Safari sees this element differently
46+
continue_shopping_button = "link=Continue Shopping"
47+
self.assert_element(continue_shopping_button)
48+
4449

4550
# Checkout - Add info
4651
self.click("link=CHECKOUT")
@@ -64,5 +69,5 @@ def test_swag_labs_basic_flow(self):
6469
self.assert_element("div.pony_express")
6570
self.click("#shopping_cart_container path")
6671
self.assert_element_absent("div.inventory_item_name")
67-
self.click("link=CONTINUE SHOPPING")
72+
self.click(continue_shopping_button)
6873
self.assert_element_absent("span.shopping_cart_badge")

0 commit comments

Comments
 (0)