def test_logout(self): """Test logout""" login = LoginPage(self.driver) login.open() inventory = login.login(_DEF_USER, _DEF_PASSWORD) inventory.display_menu() inventory.click_logout()
def test_adding_products_and_back(self): """Test adding 2 products to cart and going back to shopping""" login = LoginPage(self.driver) login.open() inventory_page = login.login(_DEF_USER, _DEF_PASSWORD) first_item = inventory_page.products[0] first_item: InventoryItem details_page = first_item.open_details() details_page.add_to_cart() details_page.back() inventory_page.products.reload() second_item = inventory_page.products[1] second_item: InventoryItem details_page = second_item.open_details() details_page.add_to_cart() details_page.back() inventory_page.products.reload() details_page.header.goto_cart() print('\n') print(f'Label: {inventory_page.get_label()}') assert inventory_page.get_label( ) == 'YOUR CART', 'Cart page label should be Your Cart' cart = inventory_page.open_cart() cart.back()
def test_invalid_user(self): page = LoginPage(self.driver) page.open() page.login('standard_user', 'invalid_password') error_msg = page.get_error_message() assert error_msg is not None, 'Error message should be displayed for invalid login' assert error_msg == ERROR_MSG, f'Error message should be {ERROR_MSG}'
def test_inventory_details(self): """Test inventory prices""" login = LoginPage(self.driver) login.open() inventory_page = login.login(_DEF_USER, _DEF_PASSWORD) first_item = inventory_page.products[0] first_item: InventoryItem details_page = first_item.open_details() print(f'Title: {details_page.get_title()}') print(f'Description: {details_page.get_description()}') print(f'Price: {details_page.get_price()}') details_page.add_to_cart() # print(f'Total elements in cart: {details_page.header.get_total_cart_items()}') # details_page.remove_from_cart() details_page.back() inventory_page.products.reload() second_item = inventory_page.products[1] second_item: InventoryItem details_page = second_item.open_details() print(f'Title: {details_page.get_title()}') print(f'Description: {details_page.get_description()}') print(f'Price: {details_page.get_price()}') details_page.add_to_cart() print( f'Total elements in cart: {details_page.header.get_total_cart_items()}' ) details_page.remove_from_cart() details_page.back() inventory_page.products.reload() assert len(inventory_page.products) == 6, 'Inventor len should be 6'
def test_label(self): """Test production label.""" login = LoginPage(self.driver) login.open() inventory = login.login(_DEF_USER, _DEF_PASSWORD) assert inventory.get_label( ) == 'PRODUCTS', 'Inventory page label should be Products' inventory.display_menu() inventory.click_logout()
def test_sort(self): """Test sort products""" login = LoginPage(self.driver) login.open() inventory = login.login(_DEF_USER, _DEF_PASSWORD) inventory.get_sort_value( ) == InventorySortOptions.A_TO_Z.value, 'Default sort should be A to Z' for option in InventorySortOptions: inventory.sort_by(option) inventory.get_sort_value( ) == option.value, f'Default sort should be {option.value}'
def test_error(self): login = LoginPage(self.driver) login.open() inventory_page = login.login(_DEF_USER, _DEF_PASSWORD) first_item = inventory_page.products[0] first_item: InventoryItem details_page = first_item.open_details() details_page.add_to_cart() cart_page = inventory_page.open_cart() cart_page.checkout() contact_info_page = CheckoutFirstStep(self.driver) contact_info_page.checkout() contact_info_page.get_error_msg()
def test_go_back(self): login = LoginPage(self.driver) login.open() inventory_page = login.login(_DEF_USER, _DEF_PASSWORD) first_item = inventory_page.products[0] first_item: InventoryItem details_page = first_item.open_details() details_page.add_to_cart() cart_page = inventory_page.open_cart() cart_page.checkout() contact_info_page = CheckoutFirstStep(self.driver) contact_info_page.fill_info("Angie", "Garcia", "44540") contact_info_page.back_to_cart()
def test_remove_product(self): login = LoginPage(self.driver) login.open() inventory_page = login.login(_DEF_USER, _DEF_PASSWORD) # Adding 1 product to cart first_item = inventory_page.products[0] first_item: InventoryItem details_page = first_item.open_details() details_page.add_to_cart() details_page.back() inventory_page.products.reload() cart = inventory_page.open_cart() cart.remove_from_cart()
def test_prices(self): """Test inventory prices""" login = LoginPage(self.driver) login.open() inventory = login.login(_DEF_USER, _DEF_PASSWORD) for index, item in enumerate(inventory.products): item: InventoryItem assert item.get_price() == VALID_PRICES[ index], f'Price for item {index} should be {VALID_PRICES[index]}' print('\n') print(item.get_title()) print(item.get_description()) print(item.get_price()) print('*' * 80)
def test_validation_prices(self): login = LoginPage(self.driver) login.open() inventory_page = login.login(_DEF_USER, _DEF_PASSWORD) first_item = inventory_page.products[0] first_item: InventoryItem details_page = first_item.open_details() details_page.add_to_cart() cart_page = inventory_page.open_cart() cart_page.checkout() contact_info_page = CheckoutFirstStep(self.driver) contact_info_page.fill_info("Angie", "Garcia", "44540") contact_info_page.checkout() checkout_page = CheckoutPage(self.driver) assert checkout_page.get_subtotal_text() == "Item total: $29.99" assert checkout_page.get_tax_text() == "Tax: $2.40" assert checkout_page.get_total_text() == "Total: $32.39"
def test_cancel_checkout(self): login = LoginPage(self.driver) login.open() inventory_page = login.login(_DEF_USER, _DEF_PASSWORD) first_item = inventory_page.products[0] first_item: InventoryItem details_page = first_item.open_details() details_page.add_to_cart() cart_page = inventory_page.open_cart() cart_page.checkout() contact_info_page = CheckoutFirstStep(self.driver) contact_info_page.fill_info("Angie", "Garcia", "44540") contact_info_page.checkout() checkout_page = CheckoutPage(self.driver) checkout_page.cancel_checkout() assert inventory_page.get_label( ) == 'PRODUCTS', 'Inventory page label should be Products'
def test_filling_info_checkout(self): """Test adding 1 product to cart and continue with checkout""" login = LoginPage(self.driver) login.open() inventory_page = login.login(_DEF_USER, _DEF_PASSWORD) first_item = inventory_page.products[0] first_item: InventoryItem details_page = first_item.open_details() details_page.add_to_cart() cart_page = inventory_page.open_cart() cart_page.checkout() contact_info_page = CheckoutFirstStep(self.driver) contact_info_page.fill_info("Angie", "Garcia", "44540") print('\n') print(f'Label: {inventory_page.get_label()}') assert inventory_page.get_label( ) == 'CHECKOUT: YOUR INFORMATION', 'Checkout page label should be Checkout' contact_info_page.checkout()
def test_completing_checkout(self): login = LoginPage(self.driver) login.open() inventory_page = login.login(_DEF_USER, _DEF_PASSWORD) first_item = inventory_page.products[0] first_item: InventoryItem details_page = first_item.open_details() details_page.add_to_cart() cart_page = inventory_page.open_cart() cart_page.checkout() contact_info_page = CheckoutFirstStep(self.driver) contact_info_page.fill_info("Angie", "Garcia", "44540") contact_info_page.checkout() checkout_page = CheckoutPage(self.driver) print('\n') print(f'Label: {checkout_page.get_title_text()}') assert checkout_page.get_title_text( ) == 'CHECKOUT: OVERVIEW', 'Checkout page title should be CHECKOUT: OVERVIEW' checkout_page.finish_buy() assert checkout_page.get_thanks_text( ) == 'THANK YOU FOR YOUR ORDER', 'Success page label should be THANK YOU FOR YOUR ORDER' assert checkout_page.get_img() != 'False', 'Image Pony OK'
def test_adding_products_and_checking(self): """Test adding 1 product and checking the quantity""" login = LoginPage(self.driver) login.open() inventory_page = login.login(_DEF_USER, _DEF_PASSWORD) # Adding 1 product to cart first_item = inventory_page.products[0] first_item: InventoryItem details_page = first_item.open_details() details_page.add_to_cart() details_page.back() inventory_page.products.reload() cart = inventory_page.open_cart() print('\n') print(f'Quantity of Products:{cart.get_quantity()}') print('\n') print(f'Product Name:{cart.get_title()}') print('\n') print(f'Product description:{cart.get_description()}') print('\n') print(f'Product Price:{cart.get_price()}') cart.checkout()
def test_sauce_lab_login(): driver = get_driver('chrome') page = LoginPage(driver) page.open() page.login('standard_user', 'secret_sauce') page.close()
def test_valid_user(self, user: str, password: str): page = LoginPage(self.driver) page.open() page.login(user, password)