Ejemplo n.º 1
0
class DecathlonsgCategoryPage:
    """DecathlonsgCategory is selecting random product from category page ."""

    PRODUCT_CONTAINER = (By.ID, 'products')
    PRODUCT_LIST = (By.CSS_SELECTOR, '.thumbnail.product-thumbnail')

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

    def selects_random_product(self):
        """
        Select random products from product list.

        """
        sleep(2)
        self.methods.wait_for_element(self.PRODUCT_CONTAINER)
        self.methods.exist_element(self.PRODUCT_LIST, multiple=True)
        products = self.driver.find_elements(*self.PRODUCT_LIST)
        if len(products) > 7:
            random_int = self.methods.random_number(1, 6)
            random_product_url = products[random_int].get_attribute('href')
            random_product_url = random_product_url.split('html')
            random_product_url = random_product_url[0] + 'html'
            self.driver.get(random_product_url)

        else:
            random_int = self.methods.random_number(1, len(products) - 1)
            random_product_url = products[random_int].get_attribute('href')
            random_product_url = random_product_url.split('html')
            random_product_url = random_product_url[0] + 'html'
            self.driver.get(random_product_url)
Ejemplo n.º 2
0
class RoyalQueenSeedsMain:
    """RoyalQueenSeedsMain class lands in the website and it has all the navigation functions."""

    website = 'https://www.royalqueenseeds.com/'
    AGE_CONTROL = (By.CSS_SELECTOR, '.button.enter-btn')
    HEADER_LOGIN = (By.XPATH, '//a[@title="Your Account"]')
    LOGIN_BUTTON = (By.XPATH, '//a[@title="Log in"]')
    HOMEPAGE_CONTROL = (By.ID, 'slide-holder')
    HEADER_CATS_CONTAINER = (By.XPATH, '//a[contains(@class, "cat_")]')
    CART_PAGE = (By.XPATH, '//a[contains(@class, "top-cart-checkout")]'
                 )  # '//*[@title="Check out"]'

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

    def navigate_to_home_page(self):
        """
        Navigates to the homepage and checks it

        """
        self.driver.get(self.website)
        self.methods.wait_for_element(self.AGE_CONTROL).click()
        home_page_loaded = self.methods.element_exists(self.HOMEPAGE_CONTROL)
        assert home_page_loaded, True

    def navigate_to_login_page(self):
        """
        Navigates to the login page

        """
        try:
            self.methods.wait_for_element(self.HEADER_LOGIN)
            self.methods.hover(self.HEADER_LOGIN)
            self.methods.wait_for_element(self.LOGIN_BUTTON).click()
        except TimeoutException:
            self.methods.hover(self.HEADER_LOGIN)
            self.methods.wait_for_element(self.LOGIN_BUTTON).click()
        sleep(2)

    def navigate_to_random_category_page(self):
        """
        Navigates to a random category page

        """
        sleep(2)
        categories = self.driver.find_elements(*self.HEADER_CATS_CONTAINER)
        random_value = self.methods.random_number(0, len(categories) - 1)
        random_category = categories[random_value]
        random_category.click()

    def navigate_to_cart_page(self):
        """
        Navigates to the cart page

        """
        self.methods.wait_for_element(self.CART_PAGE).click()