1- import pytest
21from parameterized import parameterized
32from seleniumbase import BaseCase
43
54
65class SwagLabsTests (BaseCase ):
76
8- def login_to_swag_labs (self , username = "standard_user" , v1 = False ):
7+ def login_to_swag_labs (self , username = "standard_user" ):
98 """ Login to Swag Labs and verify success. """
109 url = "https://www.saucedemo.com"
11- if v1 :
12- url += "/v1"
1310 self .open (url )
1411 if username not in self .get_text ("#login_credentials" ):
1512 self .fail ("Invalid user for login: %s" % username )
1613 self .type ("#user-name" , username )
1714 self .type ("#password" , "secret_sauce" )
1815 self .click ('input[type="submit"]' )
1916 self .assert_element ("#inventory_container" )
20- if v1 :
21- self .assert_text ("Products" , "div.product_label" )
17+ self .assert_element ('div:contains("Sauce Labs Backpack")' )
2218
2319 @parameterized .expand ([
2420 ["standard_user" ],
2521 ["problem_user" ],
2622 ])
27- @pytest .mark .run (order = 1 )
2823 def test_swag_labs_basic_flow (self , username ):
2924 """ This test checks functional flow of the Swag Labs store.
3025 This test is parameterized on the login user. """
31- self .login_to_swag_labs (username = username , v1 = True )
26+ self .login_to_swag_labs (username = username )
3227 if username == "problem_user" :
3328 print ("\n (This test should fail)" )
3429
@@ -49,60 +44,42 @@ def test_swag_labs_basic_flow(self, username):
4944 self .assert_exact_text ("1" , "span.shopping_cart_badge" )
5045
5146 # Verify your cart
52- self .click ("#shopping_cart_container path " )
53- self .assert_exact_text ( "Your Cart" , "div.subheader" )
47+ self .click ("#shopping_cart_container" )
48+ self .assert_element ( 'span:contains( "Your Cart")' )
5449 self .assert_text (item_name , "div.inventory_item_name" )
5550 self .assert_exact_text ("1" , "div.cart_quantity" )
5651 self .assert_exact_text ("REMOVE" , "button.cart_button" )
57- continue_shopping_button = "link=CONTINUE SHOPPING"
58- if self .browser == "safari" :
59- # Safari sees this element differently
60- continue_shopping_button = "link=Continue Shopping"
61- self .assert_element (continue_shopping_button )
52+ self .assert_element ("button#continue-shopping" )
6253
6354 # Checkout - Add info
64- self .click ("link=CHECKOUT " )
65- self .assert_text ( "Checkout: Your Information" , "div.subheader" )
66- self .assert_element ("a.cart_cancel_link " )
55+ self .click ("button#checkout " )
56+ self .assert_element ( 'span:contains( "Checkout: Your Information")' )
57+ self .assert_element ("button#cancel " )
6758 self .type ("#first-name" , "SeleniumBase" )
6859 self .type ("#last-name" , "Rocks" )
6960 self .type ("#postal-code" , "01720" )
7061
7162 # Checkout - Overview
72- self .click ("input.btn_primary " )
73- self .assert_text ( "Checkout: Overview" , "div.subheader" )
74- self .assert_element ("link=CANCEL " )
63+ self .click ("input#continue " )
64+ self .assert_element ( 'span:contains( "Checkout: Overview")' )
65+ self .assert_element ("button#cancel " )
7566 self .assert_text (item_name , "div.inventory_item_name" )
7667 self .assert_text (item_price , "div.inventory_item_price" )
77- self .assert_exact_text ("1" , "div.summary_quantity " )
68+ self .assert_exact_text ("1" , "div.cart_quantity " )
7869
79- # Finish Checkout and verify the item was removed from the cart
80- self .click ("link=FINISH " )
70+ # Finish Checkout and verify that the cart is now empty
71+ self .click ("button#finish " )
8172 self .assert_exact_text ("THANK YOU FOR YOUR ORDER" , "h2" )
8273 self .assert_element ("img.pony_express" )
83- self .click ("#shopping_cart_container path " )
74+ self .click ("#shopping_cart_container" )
8475 self .assert_element_absent ("div.inventory_item_name" )
85- self .click (continue_shopping_button )
76+ self .click ("button#continue-shopping" )
8677 self .assert_element_absent ("span.shopping_cart_badge" )
8778
8879 @parameterized .expand ([
8980 ["standard_user" ],
9081 ["problem_user" ],
9182 ])
92- @pytest .mark .run (order = 2 )
93- def test_swag_labs_products_page_links (self , username ):
94- """ This test checks for 404s on the Swag Labs products page.
95- This test is parameterized on the login user. """
96- self .login_to_swag_labs (username = username , v1 = True )
97- if username == "problem_user" :
98- print ("\n (This test should fail)" )
99- self .assert_no_404_errors ()
100-
101- @parameterized .expand ([
102- ["standard_user" ],
103- ["problem_user" ],
104- ])
105- @pytest .mark .run (order = 3 )
10683 def test_swag_labs_visual_regressions (self , username ):
10784 """ This test checks for visual regressions on the Swag Labs page.
10885 This test is parameterized on the login user. """
0 commit comments