2019-04-22 16:01:55 +08:00
|
|
|
from parameterized import parameterized
|
|
|
|
from seleniumbase import BaseCase
|
|
|
|
|
|
|
|
|
|
|
|
class SwagLabsTests(BaseCase):
|
2021-04-11 01:25:56 +08:00
|
|
|
def login_to_swag_labs(self, username="standard_user"):
|
2022-04-14 01:40:01 +08:00
|
|
|
"""Login to Swag Labs and verify success."""
|
2021-03-05 05:45:06 +08:00
|
|
|
url = "https://www.saucedemo.com"
|
|
|
|
self.open(url)
|
2020-05-08 07:14:44 +08:00
|
|
|
if username not in self.get_text("#login_credentials"):
|
|
|
|
self.fail("Invalid user for login: %s" % username)
|
2020-06-14 13:17:02 +08:00
|
|
|
self.type("#user-name", username)
|
|
|
|
self.type("#password", "secret_sauce")
|
2019-04-22 16:01:55 +08:00
|
|
|
self.click('input[type="submit"]')
|
2022-06-21 06:03:49 +08:00
|
|
|
self.assert_element("div.inventory_list")
|
2021-04-11 01:25:56 +08:00
|
|
|
self.assert_element('div:contains("Sauce Labs Backpack")')
|
2019-04-22 16:01:55 +08:00
|
|
|
|
2021-05-06 09:06:24 +08:00
|
|
|
@parameterized.expand(
|
|
|
|
[
|
|
|
|
["standard_user"],
|
|
|
|
["problem_user"],
|
|
|
|
]
|
|
|
|
)
|
2021-03-04 07:36:35 +08:00
|
|
|
def test_swag_labs_basic_flow(self, username):
|
2021-05-06 09:06:24 +08:00
|
|
|
"""This test checks functional flow of the Swag Labs store.
|
|
|
|
This test is parameterized on the login user."""
|
2021-04-11 01:25:56 +08:00
|
|
|
self.login_to_swag_labs(username=username)
|
2021-03-07 12:42:08 +08:00
|
|
|
if username == "problem_user":
|
|
|
|
print("\n(This test should fail)")
|
2019-04-22 16:01:55 +08:00
|
|
|
|
|
|
|
# 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"):
|
2020-05-08 00:37:59 +08:00
|
|
|
self.fail('Sort Failed! Expecting "%s" on top!' % item_name)
|
2019-04-22 16:01:55 +08:00
|
|
|
|
|
|
|
# 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
|
2022-02-01 13:59:15 +08:00
|
|
|
self.click("#shopping_cart_container a")
|
2021-04-11 01:25:56 +08:00
|
|
|
self.assert_element('span:contains("Your Cart")')
|
2019-04-22 16:01:55 +08:00
|
|
|
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")
|
2021-04-11 01:25:56 +08:00
|
|
|
self.assert_element("button#continue-shopping")
|
2019-04-22 16:01:55 +08:00
|
|
|
|
|
|
|
# Checkout - Add info
|
2021-04-11 01:25:56 +08:00
|
|
|
self.click("button#checkout")
|
|
|
|
self.assert_element('span:contains("Checkout: Your Information")')
|
|
|
|
self.assert_element("button#cancel")
|
2020-06-14 13:17:02 +08:00
|
|
|
self.type("#first-name", "SeleniumBase")
|
|
|
|
self.type("#last-name", "Rocks")
|
|
|
|
self.type("#postal-code", "01720")
|
2019-04-22 16:01:55 +08:00
|
|
|
|
|
|
|
# Checkout - Overview
|
2021-04-11 01:25:56 +08:00
|
|
|
self.click("input#continue")
|
|
|
|
self.assert_element('span:contains("Checkout: Overview")')
|
|
|
|
self.assert_element("button#cancel")
|
2019-04-22 16:01:55 +08:00
|
|
|
self.assert_text(item_name, "div.inventory_item_name")
|
|
|
|
self.assert_text(item_price, "div.inventory_item_price")
|
2021-04-11 01:25:56 +08:00
|
|
|
self.assert_exact_text("1", "div.cart_quantity")
|
2019-04-22 16:01:55 +08:00
|
|
|
|
2021-04-11 01:25:56 +08:00
|
|
|
# Finish Checkout and verify that the cart is now empty
|
|
|
|
self.click("button#finish")
|
2019-04-22 16:01:55 +08:00
|
|
|
self.assert_exact_text("THANK YOU FOR YOUR ORDER", "h2")
|
2020-07-29 00:04:01 +08:00
|
|
|
self.assert_element("img.pony_express")
|
2022-02-02 03:56:26 +08:00
|
|
|
self.click("#shopping_cart_container a")
|
2019-04-22 16:01:55 +08:00
|
|
|
self.assert_element_absent("div.inventory_item_name")
|
2021-04-11 01:25:56 +08:00
|
|
|
self.click("button#continue-shopping")
|
2019-04-22 16:01:55 +08:00
|
|
|
self.assert_element_absent("span.shopping_cart_badge")
|
|
|
|
|
2021-04-17 23:56:14 +08:00
|
|
|
def tearDown(self):
|
|
|
|
self.save_teardown_screenshot()
|
|
|
|
# Reset App State and Logout if the controls are present
|
|
|
|
try:
|
|
|
|
if self.is_element_present("a#reset_sidebar_link"):
|
|
|
|
self.js_click("a#reset_sidebar_link")
|
|
|
|
if self.is_element_present("a#logout_sidebar_link"):
|
|
|
|
self.js_click("a#logout_sidebar_link")
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
super(SwagLabsTests, self).tearDown()
|