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