class RoyalQueenSeedsProduct:
    """Product page to select size and add to cart."""

    NUMBER_SEEDS_CONTAINER = (By.CSS_SELECTOR, '.attributes-block')
    ADD_TO_CART = (By.CSS_SELECTOR, '#add_to_cart')
    ADDED_TO_CART = (By.ID, 'cart_block_total')
    PRODUCT_STOCK = (By.ID, 'availability_value')
    POPUP_CLOSE_BUTTON = (By.XPATH, '')
    OUT_OF_STOCK = (By.CSS_SELECTOR, '#availability_value')

    def __init__(self, driver):
        self.driver = driver
        self.methods = BaseClass(self.driver)

    # def select_size(self):
    #     """
    #     Selects product size
    #
    #     """
    #     if self.methods.element_exists(self.NONE_SIZE):
    #         self.methods.wait_for_element(self.AVAILABLE_SIZE).click()

    def check_stock_info(self):
        """
         Search for stock info if the product is not in stock returns False

         """
        availability = self.methods.presence_of_element_located(self.OUT_OF_STOCK).text
        if availability.lower() != 'no stock':
            return True
        else:
            return False

    def add_product_to_cart(self):
        """
        Adds product to the cart page and check is it added successfully

        """
        sleep(1)
        cart_total = self.methods.presence_of_element_located(self.ADDED_TO_CART).text
        self.methods.wait_for_element(self.ADD_TO_CART).click()
        if self.methods.element_exists(self.ADDED_TO_CART):
            try:
                sleep(1)
                successfully_added = self.methods.presence_of_element_located(self.ADDED_TO_CART).text
                assert cart_total != successfully_added  # change assertion if any bug appears
            except AssertionError:
                self.add_product_to_cart()
        else:
            self.add_product_to_cart()
Ejemplo n.º 2
0
class DecathlonsgProductPage:
    """DecathlonsgProduct is select exits size, check stock info and add product to cart."""

    ADD_TO_CART_EXISTS = (By.CLASS_NAME, "add")
    NONE_SIZE = (By.CSS_SELECTOR, '//*[@style="display:none"]')
    AVAILABLE_SIZE = (By.CLASS_NAME, 'radio-label')
    ADD_TO_CART = (By.CSS_SELECTOR, '.btn.btn-primary.btn-lg')
    ADD_TO_CART_ICON = (By.CSS_SELECTOR, '.bag-icon')
    CLOSE_POPUP_BTN = (By.ID, 'logo')
    MINIFY_POPUP_BTN = (By.CSS_SELECTOR, '[aria-label="close"]')
    ADDED_TO_CART = (By.CSS_SELECTOR, '.sc-cart-summary-line')
    OUT_OF_STOCK = (By.XPATH,
                    './/*[text()=" There are not enough products in stock "]')
    IFRAME_IS_OPENED = (By.CSS_SELECTOR,
                        '.anchor_right.fb_customer_chat_bounce_in_v2')
    IFRAME = (By.CSS_SELECTOR, '[data-testid="dialog_iframe"]')

    def __init__(self, driver):
        self.driver = driver
        self.methods = BaseClass(self.driver)

    def select_size(self):
        """
        Selects product size

        """
        if self.methods.exist_element(self.NONE_SIZE):
            self.methods.wait_for_element(self.AVAILABLE_SIZE).click()

    def check_stock_info(self):
        """
        Search for stock info if the product is not in stock returns False

        """
        if self.methods.exist_element(self.OUT_OF_STOCK):
            return False
        else:
            return True

    def add_product_to_cart(self):
        """
        Adds product to the cart page and check is it added successfully.

        """
        if self.methods.exist_element(self.ADD_TO_CART_EXISTS):
            try:
                if self.methods.exist_element(self.IFRAME_IS_OPENED):
                    iframe_name = self.methods.presence_of_element_located(
                        self.IFRAME).get_attribute('name')
                    self.driver.switch_to.frame(iframe_name)
                    self.methods.wait_for_element(
                        DecathlonsgProductPage.MINIFY_POPUP_BTN).click()
                    self.driver.switch_to.default_content()
                    self.methods.wait_for_element(
                        self.ADD_TO_CART_ICON).click()
                self.methods.wait_for_element(self.ADD_TO_CART_ICON).click()
                assert self.methods.exist_element(
                    self.ADDED_TO_CART), "ADD_TO_CART is not clickable"
            except:
                self.driver.execute_script("window.scrollTo(0, 400)")
                self.methods.wait_for_element(self.ADD_TO_CART_ICON).click()
        else:
            assert self.methods.wait_for_element(
                self.ADD_TO_CART_EXISTS).is_displayed(
                ), "No add to cart button"