Exemple #1
0
class BasePage:
    locators = BaseLocators()

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

    def find(self, locator, timeout=None) -> WebElement:
        return self.wait(timeout).until(EC.presence_of_element_located(locator))

    def alert(self, msg):
        script = "alert('{}')".format(msg)
        self.driver.execute_script(script)

    def click(self, locator, timeout=None):
        for i in range(RETRY_COUNT):
            try:
                self.find(locator)
                element = self.wait(timeout).until(EC.element_to_be_clickable(locator))
                element.click()
                return element

            except StaleElementReferenceException:
                if i < RETRY_COUNT - 1:
                    pass
        raise

    def scroll_to_element(self, element):
        self.driver.execute_script('arguments[0].scrollIntoView(true);', element)

    def wait(self, timeout=None):
        if timeout is None:
            timeout = 5
        return WebDriverWait(self.driver, timeout=timeout)
Exemple #2
0
class BasePage:
    locators = BaseLocators()

    def __init__(self, driver, config):
        self.driver = driver
        self.config = config

    def find(self, locator, timeout=None) -> WebElement:
        return self.wait(timeout).until(
            EC.presence_of_element_located(locator))

    def click(self, locator, timeout=None):
        for i in range(RETRY_COUNT):
            try:
                self.find(locator)
                element = self.wait(timeout).until(
                    EC.element_to_be_clickable(locator))
                element.click()
                return

            except StaleElementReferenceException:
                if i < RETRY_COUNT - 1:
                    pass
        raise

    def wait(self, timeout=None):
        if timeout is None:
            timeout = 5
        return WebDriverWait(self.driver, timeout=timeout)

    def move_to_element(self, locator):
        element = self.find(locator)
        ActionChains(self.driver).move_to_element(element).perform()
Exemple #3
0
class BasePage:
    locators = BaseLocators()

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

    def find(self, locator, timeout=None) -> WebElement:
        return self.wait(timeout).until(EC.presence_of_element_located(locator))

    def alert(self, msg):
        script = "alert('{}')".format(msg)
        self.driver.execute_script(script)

    @allure.step('Clicking on {locator}...')
    def click(self, locator, timeout=None):
        for i in range(RETRY_COUNT):
            try:
                self.find(locator)
                element = self.wait(timeout).until(EC.element_to_be_clickable(locator))
                element.click()
                return

            except StaleElementReferenceException:
                if i < RETRY_COUNT - 1:
                    pass
        raise

    def scroll_to_element(self, element):
        self.driver.execute_script('arguments[0].scrollIntoView(true);', element)

    def wait(self, timeout=None):
        if timeout is None:
            timeout = 5
        return WebDriverWait(self.driver, timeout=timeout)

    def count_elements(self, locator, count, timeout=1):
        self.wait(timeout).until(lambda browser: len(browser.find_elements(*locator)) == count)

    def search(self, query):
        search_field = self.find(self.locators.QUERY_LOCATOR)
        search_field.clear()
        search_field.send_keys(query)
        self.find(self.locators.GO_BUTTON).click()
Exemple #4
0
class BasePage:
    locators = BaseLocators()

    def __init__(self, driver, config):
        self.driver = driver
        self.config = config

    def find(self, locator, timeout=None) -> WebElement:
        return self.wait(timeout).until(
            EC.presence_of_element_located(locator))

    def click(self, locator, timeout=None):
        for i in range(RETRY_COUNT):
            try:
                self.find(locator)
                element = self.wait(timeout).until(
                    EC.element_to_be_clickable(locator))
                element.click()
                return

            except StaleElementReferenceException:
                if i < RETRY_COUNT - 1:
                    pass
        raise

    def wait(self, timeout=None):
        if timeout is None:
            timeout = 5
        return WebDriverWait(self.driver, timeout=timeout)

    def count_elements(self, locator):
        return len(self.driver.find_elements(*locator))

    def go_to_segments(self):
        from ui.pages.segments import SegmentsPage

        self.click(self.locators.SEGMENTS, 20)
        return SegmentsPage(self.driver, self.config)
Exemple #5
0
class BasePage:
    locators = BaseLocators()

    def __init__(self, driver):
        self.driver = driver
        self.user = '******'
        self.password = '******'

    def get_create_account_page(self):
        self.find(self.locators.CREATE_ACCOUNT_BUTTON).click()

    def find(self, locator, timeout=None):
        try:
            s = self.wait(timeout).until(
                EC.presence_of_all_elements_located(locator))
            if len(s) == 1:
                return self.wait(timeout).until(
                    EC.presence_of_element_located(locator))
            return self.wait(timeout).until(
                EC.presence_of_all_elements_located(locator))
        except:
            assert False, f'Элемента {locator} на странице не обнаружено '

    def click(self, locator, timeout=1):
        for i in range(RETRY_COUNT):
            try:
                self.find(locator)
                element = self.wait(timeout).until(
                    EC.element_to_be_clickable(locator))
                element.click()
                return
            except StaleElementReferenceException:
                if i < RETRY_COUNT - 1:
                    pass
        raise

    def scroll_to_element(self, element):
        self.driver.execute_script('arguments[0].scrollIntoView(true);',
                                   element)

    def wait(self, timeout=None):
        if timeout is None:
            timeout = 3
        return WebDriverWait(self.driver, timeout=timeout)

    def authorization(self, user, password):
        user_field = self.find(self.locators.INPUT_NAME)
        user_field.clear()
        password_field = self.find(self.locators.INPUT_PASSWORD)
        password_field.clear()
        password_field.send_keys(password)
        user_field.send_keys(user)
        self.find(self.locators.AUTHORIZATION_BUTTON).click()

    def form_valid_user_data(self):
        username = fake.last_name()
        while len(username) not in range(7, 16):
            username = fake.last_name()

        password = fake.password()
        email = fake.email()

        return {"username": username, "password": password, "email": email}
class BasePage:
    locators = BaseLocators()

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

    def find(self, locator, timeout=None) -> WebElement:
        return self.wait(timeout).until(EC.presence_of_element_located(locator))

    def alert(self, msg):
        script = "alert('{}')".format(msg)
        self.driver.execute_script(script)

    def click(self, locator, timeout=None):
        for i in range(RETRY_COUNT):
            try:
                self.find(locator)
                element = self.wait(timeout).until(EC.element_to_be_clickable(locator))
                element.click()
                return

            except StaleElementReferenceException:
                if i < RETRY_COUNT - 1:
                    pass
        raise

    def scroll_to_element(self, element):
        self.driver.execute_script('arguments[0].scrollIntoView(true);', element)

    def wait(self, timeout=None):
        if timeout is None:
            timeout = 5
        return WebDriverWait(self.driver, timeout=timeout)

    def count_elements(self, locator, count, timeout=1):
        self.wait(timeout).until(lambda browser: len(browser.find_elements(*locator)) == count)

    def inputting(self, smth, locator):
        input_element = self.find(locator)
        input_element.clear()
        input_element.send_keys(smth)

    def input_object(self, name, locator):
        current_file_dir = os.path.dirname(__file__)
        abs_file_path = os.path.abspath(os.path.join(current_file_dir, os.path.pardir, os.path.pardir, name))
        input_element = self.find(locator)
        input_element.send_keys(abs_file_path)

        def search(self, name, locator, suggestion):
        input_element = self.find(locator)
        started = time.time()
        timeout = 0.1
        interval = 1
        while time.time() - started < timeout:
            try:
                input_element.clear()
                break
            except InvalidElementStateException:
                time.sleep(interval)
        input_element.send_keys(name)
        self.find(suggestion).click()