class MainPage: website = "http://www.amazon.com.tr/" MAIN_PAGE_LOADED = (By.ID, "gw-layout") SELECT_COMPUTER = (By.LINK_TEXT, "Bilgisayar") COMPUTER_SELECTED = (By.XPATH, "//h1[contains(text(),'Bilgisayar')]") text = "Bilgisayar" def __init__(self, driver): self.driver = driver self.functions = BaseClass(self.driver) def load_website(self): """ Navigates to the homepage and checks it """ self.driver.get(self.website) main_page_loaded = self.functions.wait_for_element( self.MAIN_PAGE_LOADED) assert main_page_loaded.is_displayed(), "didn't loaded website!" def click_computer(self): """ Navigates to computer category page and checks it """ self.functions.wait_for_element(self.SELECT_COMPUTER).click() computer_selected = self.functions.wait_for_element( self.COMPUTER_SELECTED) assert computer_selected.text == self.text, "didn't selected computer!"
class CartPage: DROPDOWN = (By.ID, "a-autoid-0") QUANTITY_SELECT = (By.ID, "dropdown1_2") CART_MESSAGE = (By.CLASS_NAME, "sc-quantity-update-message") DELETE_BTN = (By.CLASS_NAME, "a-color-link") PRODUCT_DELETED = (By.XPATH, "//h2[contains(text(),'Amazon Sepetiniz boş')]") text = "Amazon Sepetiniz boş" def __init__(self, driver): self.driver = driver self.functions = BaseClass(self.driver) def increase_to_quantity(self): """ Clicks dropdown and increase the quantity and checks it """ self.functions.wait_for_element(self.DROPDOWN).click() self.functions.wait_for_element(self.QUANTITY_SELECT).click() cart_message = self.functions.wait_for_element(self.CART_MESSAGE) assert cart_message.is_displayed( ), "the quantity couldn't be increased!" def delete_product(self): """ Delete the product that added to cart and checks it """ self.functions.wait_for_element(self.DELETE_BTN).click() product_deleted = self.functions.wait_for_element(self.PRODUCT_DELETED) assert product_deleted.text == self.text, "didn't deleted product!"
def setUp(self): self.driver = webdriver.Chrome() self.driver.maximize_window() self.base_class = BaseClass(self.driver) self.main_page = MainPage(self.driver) self.category_page = CategoryPage(self.driver) self.product_page = ProductPage(self.driver) self.cart_page = CartPage(self.driver)
class CategoryPage: SELECT_LAPTOP = (By.CLASS_NAME, "octopus-pc-category-card-v2-item") LAPTOP_SELECTED = (By.XPATH, "//h1[contains(text(),'Dizüstü Bilgisayarlar')]") text = "Dizüstü Bilgisayarlar" SELECT_PRODUCT = (By.CLASS_NAME, "octopus-pc-item") PRODUCT_SELECTED = (By.ID, "add-to-cart-button") def __init__(self, driver): self.driver = driver self.functions = BaseClass(self.driver) def click_laptop(self): """ Navigates to the laptop category page and checks it """ self.functions.wait_for_element(self.SELECT_LAPTOP).click() laptop_selected = self.functions.wait_for_element(self.LAPTOP_SELECTED) assert laptop_selected.text == self.text, "didn't selected laptop!" def click_first_product(self): """ Navigates to the first product in laptop category page and checks it """ self.functions.wait_for_element(self.SELECT_PRODUCT).click() product_selected = self.functions.wait_for_element( self.PRODUCT_SELECTED) assert product_selected.is_displayed(), "didn't selected product!"
class ProductPage: ADD_TO_CART_BTN = (By.ID, "add-to-cart-button") PRODUCT_ADDED_TO_CART = (By.XPATH, "//h1[contains(text(),'Sepete Eklendi')]") text = "Sepete Eklendi" CART_BTN = (By.ID, "nav-cart") CART_PAGE = (By.XPATH, "//h1[contains(text(),'Alışveriş Sepeti')]") cart_text = "Alışveriş Sepeti" def __init__(self, driver): self.driver = driver self.functions = BaseClass(self.driver) def add_to_cart(self): """ Adds product to the cart and check is it added successfully """ self.functions.wait_for_element(self.ADD_TO_CART_BTN).click() product_added_to_cart = self.functions.wait_for_element( self.PRODUCT_ADDED_TO_CART) assert product_added_to_cart.text == self.text, "didn't added to cart product!" def go_to_cart(self): """ Navigate to cart page and check is it added successfully """ self.functions.wait_for_element(self.CART_BTN).click() cart_page = self.functions.wait_for_element(self.CART_PAGE) assert cart_page.text == self.cart_text, "didn't loaded cart page!"
def __init__(self, driver): self.driver = driver self.functions = BaseClass(self.driver)