class ShoppingCart(object): subtotal_amount_xpath = '//form[@id="activeCartViewForm"]//span[contains(., "Subtotal")]' def __init__(self, driver): self.driver = driver self.general_function = ElementFinder(self.driver) self.subtotal_amount = self.driver.find_element_by_xpath(self.subtotal_amount_xpath) def get_subtotal_details(self): self.general_function.is_clickable(By.XPATH, self.subtotal_amount_xpath) return self.subtotal_amount.text def is_item_added(self, name): item_xpath = '//span[contains(@class, "medium sc-product-title")][contains(.,"' + name + '")]' return self.general_function.is_visible(By.XPATH, item_xpath)
class ProductDetails(object): cart_button_id = 'add-to-cart-button' product_title_id = 'productTitle' def __init__(self, driver): self.driver = driver self.general_function = ElementFinder(self.driver) self.cart_button = self.driver.find_element_by_id(self.cart_button_id) self.product_title = self.driver.find_element_by_id(self.product_title_id) def click_add_to_cart(self): self.general_function.is_clickable(By.ID, self.cart_button_id) self.cart_button.click() def get_product_title(self): self.general_function.is_visible(By.ID, self.product_title_id) return self.product_title.text
class ShoppingCart(object): subtotal_amount_xpath = '//form[@id="activeCartViewForm"]//span[contains(., "Subtotal")]' def __init__(self, driver): self.driver = driver self.general_function = ElementFinder(self.driver) self.subtotal_amount = self.driver.find_element_by_xpath( self.subtotal_amount_xpath) def get_subtotal_details(self): self.general_function.is_clickable(By.XPATH, self.subtotal_amount_xpath) return self.subtotal_amount.text def is_item_added(self, name): item_xpath = '//span[contains(@class, "medium sc-product-title")][contains(.,"' + name + '")]' return self.general_function.is_visible(By.XPATH, item_xpath)
class ProductDetails(object): cart_button_id = 'add-to-cart-button' product_title_id = 'productTitle' def __init__(self, driver): self.driver = driver self.general_function = ElementFinder(self.driver) self.cart_button = self.driver.find_element_by_id(self.cart_button_id) self.product_title = self.driver.find_element_by_id( self.product_title_id) def click_add_to_cart(self): self.general_function.is_clickable(By.ID, self.cart_button_id) self.cart_button.click() def get_product_title(self): self.general_function.is_visible(By.ID, self.product_title_id) return self.product_title.text
class SearchResult(object): def __init__(self, driver): self.driver = driver self.general_function = ElementFinder(self.driver) # number - number of link on page to be returned (starts from 0 to 17) def get_link_text(self, number): link_xpath = '//li[@id="result_' + number + '"]//h2' self.link = self.driver.find_element_by_xpath(link_xpath) self.general_function.is_clickable(By.XPATH, link_xpath) return self.link.text def open_link(self, number): link_xpath = '//li[@id="result_' + number + '"]//h2' self.link = self.driver.find_element_by_xpath(link_xpath) self.general_function.is_clickable(By.XPATH, link_xpath) self.link.click() window_manager = WindowManager(self.driver) window_manager.switch_to_last_opened_window()
class MainMenu(object): search_input_id = 'twotabsearchtextbox' search_button_css = 'input[value="Go"]' cart_button_id = 'nav-cart' cart_counter_id = 'nav-cart-count' def __init__(self, driver): self.driver = driver self.general_function = ElementFinder(self.driver) self.search_input = self.driver.find_element_by_id(self.search_input_id) self.search_button = self.driver.find_element_by_css_selector(self.search_button_css) self.cart_button = self.driver.find_element_by_id(self.cart_button_id) self.cart_counter = self.driver.find_element_by_id(self.cart_counter_id) def open_cart(self): self.general_function.is_clickable(By.ID, self.cart_button_id) self.cart_button.click() def search(self, text): self.general_function.is_clickable(By.ID, self.search_input_id) self.search_input.clear() self.search_input.send_keys(text) self.click_search() def click_search(self): self.general_function.is_clickable(By.CLASS_NAME, self.search_button_css) self.search_button.click() def get_items_amount(self): self.general_function.is_visible(By.ID, self.cart_counter_id) return self.cart_counter.text
class MainMenu(object): search_input_id = 'twotabsearchtextbox' search_button_css = 'input[value="Go"]' cart_button_id = 'nav-cart' cart_counter_id = 'nav-cart-count' def __init__(self, driver): self.driver = driver self.general_function = ElementFinder(self.driver) self.search_input = self.driver.find_element_by_id( self.search_input_id) self.search_button = self.driver.find_element_by_css_selector( self.search_button_css) self.cart_button = self.driver.find_element_by_id(self.cart_button_id) self.cart_counter = self.driver.find_element_by_id( self.cart_counter_id) def open_cart(self): self.general_function.is_clickable(By.ID, self.cart_button_id) self.cart_button.click() def search(self, text): self.general_function.is_clickable(By.ID, self.search_input_id) self.search_input.clear() self.search_input.send_keys(text) self.click_search() def click_search(self): self.general_function.is_clickable(By.CLASS_NAME, self.search_button_css) self.search_button.click() def get_items_amount(self): self.general_function.is_visible(By.ID, self.cart_counter_id) return self.cart_counter.text