|
| 1 | + |
| 2 | +from selenium.webdriver.common.by import By |
| 3 | + |
| 4 | +from tests.pages.BasePageObject import BasePageObject |
| 5 | + |
| 6 | + |
| 7 | +class CheckoutOverviewPage(BasePageObject): |
| 8 | + |
| 9 | + URL = "https://www.saucedemo.com/checkout-step-two.html" |
| 10 | + |
| 11 | + loc_page_title_selector = ".header_secondary_container span.title" |
| 12 | + loc_checkout_list_selector = "#checkout_summary_container .cart_list" |
| 13 | + loc_checkout_item_class = "cart_item" |
| 14 | + loc_checkout_item_quantity_class = "cart_quantity" |
| 15 | + loc_checkout_item_name_class = "inventory_item_name" |
| 16 | + loc_checkout_item_price_class = "inventory_item_price" |
| 17 | + loc_finish_checkout_button_selector = '[data-test="finish"]' |
| 18 | + |
| 19 | + |
| 20 | + def verify_page_title_is(self, expected_value: str = ""): |
| 21 | + page_title = self.driver.find_element(By.CSS_SELECTOR, self.loc_page_title_selector).text |
| 22 | + return page_title.lower() == expected_value.lower() |
| 23 | + |
| 24 | + |
| 25 | + def get_checkout_items(self) -> list: |
| 26 | + """ |
| 27 | + Retrieve a list of Products and its information from the Checkout Overview page |
| 28 | +
|
| 29 | + @return list[ (element: WebElement, element_name: str, element_price: str, element_quantity: str) ] |
| 30 | + """ |
| 31 | + checkout_items = self.driver.find_elements(By.CSS_SELECTOR, self.loc_checkout_list_selector) |
| 32 | + checkout_item_list = [] |
| 33 | + |
| 34 | + for item in checkout_items: |
| 35 | + item_name = item.find_element(By.CLASS_NAME, self.loc_checkout_item_name_class).text |
| 36 | + item_price = item.find_element(By.CLASS_NAME, self.loc_checkout_item_price_class).text |
| 37 | + item_quantity = item.find_element(By.CLASS_NAME, self.loc_checkout_item_quantity_class).text |
| 38 | + checkout_item_list.append((item, item_name, item_price, item_quantity)) |
| 39 | + |
| 40 | + return checkout_item_list |
| 41 | + |
| 42 | + |
| 43 | + def verify_if_item_is_part_of_checkout_list(self, item) -> bool: |
| 44 | + """Compare a given item with the ones present on the Checkout Summary items list and return if its part or not the checkout list""" |
| 45 | + |
| 46 | + is_item_part_of_checkout_list = False |
| 47 | + _, expected_name, expected_price, expected_quantity = item |
| 48 | + |
| 49 | + checkout_list = self.get_checkout_items() |
| 50 | + for checkout_item in checkout_list: |
| 51 | + _, checkout_item_name, checkout_item_price, checkout_item_quantity = checkout_item |
| 52 | + if expected_name == checkout_item_name and expected_price == checkout_item_price and expected_quantity == checkout_item_quantity: |
| 53 | + is_item_part_of_checkout_list = True |
| 54 | + print("[ debug ] Checkout Item comparison - Name: {} - Price: {} - Quantity: {}" |
| 55 | + .format(expected_name, expected_price, expected_quantity)) |
| 56 | + |
| 57 | + return is_item_part_of_checkout_list |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + def click_finish_checkout(self): |
| 62 | + self.driver.find_element(By.CSS_SELECTOR, self.loc_finish_checkout_button_selector).click() |
| 63 | + |
0 commit comments