Example #1
0
class ProductPage(BasePage):
    """
    Product page action methods come here
    """

    def __init__(self, driver):
        """
        Add cart button element to the page
        """
        super().__init__(driver)
        self.cart_btn = Button(driver, ProductPageLocators.BTN_CART)

    def add_to_cart(self):
        """
        Click on cart button
        """
        self.cart_btn.click()
        return self

    def go_to_cart(self):
        """
        Go to Cart Page
        """
        self.top_links.cart_click()
        return CartPage(self.driver)

    def add_to_cart_apple_cinema(self):
        """
        TODO
        """
        add_to_cart_button = self.driver.find_element(*ProductPageLocators.ADD_APPLE_CINEMA)
        add_to_cart_button.click()
        return self

    def add_mac_to_cart(self):
        """Make webdriver add Mac product to Cart."""
        get_to_imac = self.driver.find(*ProductPageLocators.GO_TO_IMAC)
        get_to_imac.click()
        add_mac_to_cart = self.driver.find_element(*ProductPageLocators.ADD_IMAC_TO_CART)
        add_mac_to_cart.click()
        return self
Example #2
0
 def clickLogIn(self):
     logInBtn = Button(driver=self.driver,
                       locator=LoginLocators.SIGN_UP_BTN)
     logInBtn.click()
Example #3
0
 def sendTweet(self):
     sendBtn = Button(driver=self.driver,
                      locator=MainPageLocators.SEND_TWIT)
     sendBtn.click()
Example #4
0
 def clickOnGlobalPageBtn(self):
     gpb = Button(self.driver, MainPageLocators.GLOBAL_HOME_BTN)
     gpb.click()
class CartPage(BasePage):
    """
    Cart Page Object Model
    """

    url = "http://127.0.0.1/opencart.com/index.php?route=checkout/cart"

    def __init__(self, driver):
        """
        Add checkout button element to the page
        """
        super().__init__(driver)
        self.checkout_btn = Button(driver, CartPageLocators.BTN_CHECKOUT)

    def edit_good_qty(self):
        """Make webdriver change qty of product in Cart"""
        edit_good_qty = self.driver.find_element(
            *CartPageLocators.GOOD_QTY_FIELD)
        edit_good_qty.clear()
        edit_good_qty.send_keys('2')
        update_good_qty = self.driver.find_element(
            *CartPageLocators.UPDATE_GOOD_QTY_BUTTON)
        update_good_qty.click()
        return self

    def delete_good_from_cart(self):
        """Make webdriver delete product from Cart."""
        delete_good = self.driver.find_element(
            *CartPageLocators.DELETE_GOOD_BUTTON)
        delete_good.click()
        return self

    def go_to_checkout(self):
        """
        TODO
        """
        self.checkout_btn.click()
        return CheckoutPage(self.driver)

    def is_on_cart_page(self: object) -> bool:
        """
        Check the stay on the Cart Page.
        """
        if self.driver.current_url == CartPage.url:
            logging.info("You are on the Cart page!")
            return True
        return False

    def is_cart_empty(self: object) -> bool:
        """
        Check whether cart is empty.
        """
        empty_cart_text = self.driver.find_element(
            *CartPageLocators.EMPTY_CART_TEXT)
        if empty_cart_text:
            logging.info("Your cart is empty!")
            return True
        return False

    def click_on_continue_button(self: object) -> object:
        """
        Click on continue button on Cart Page.
        """
        continue_button = self.driver.find_element(
            *CartPageLocators.CONTINUE_BUTTON)
        continue_button.click()
        return self
        return self

    def is_product_added(self: object) -> bool:
        """
        Check whether product is added to cart.
        """
        product_name = self.driver.find_element(
            *CartPageLocators.IPHONE_PRODUCT_NAME)
        wait = WebDriverWait(self.driver, 10)
        wait.until(
            expected_conditions.visibility_of_element_located(
                CartPageLocators.IPHONE_PRODUCT_NAME))
        if product_name.text == "iPhone":
            logging.info("You added iPhone!")
            return True
        print('Cart is empty!')
        return False

    def add_to_cart_apple_cinema(self: object) -> object:
        """
        Add Apple Cinema to cart.
        """
        add_to_cart_button = self.driver.find_element(
            *ProductPageLocators.ADD_APPLE_CINEMA)
        add_to_cart_button.click()
        return self

    def add_iphone_to_cart(self: object) -> object:
        """
        Add iPhone to cart.
        """
        add_to_cart_button = self.driver.find_element(
            *ProductPageLocators.ADD_IPHONE)
        add_to_cart_button.click()
        return self

    def delete_from_cart(self: object) -> object:
        """
        Delete product from cart.
        """
        delete_button = self.driver.find_element(
            *CartPageLocators.DELETE_GOOD_BUTTON)
        delete_button.click()
        return self