예제 #1
0
파일: browser.py 프로젝트: kieras/parakeet
    def click(self):
        try:
            self.parakeet.retry(method=self.click_once)
        except Exception as ex:
            LOG.error('Attempts exceeded')

        return self
예제 #2
0
    def retry(self, method=None, **kwargs):
        """
        Method retry the execution
        :param method:
        :param kwargs:
        :return:
        """
        _next = 'next_iterator'
        _retry = self.retry_get_element
        _next_iterator = kwargs.get(_next, 1)

        try:
            LOG.debug('Trying {}/{} to perform method {}'.format(
                _next_iterator, _retry, method.__name__))

            kwargs.pop(_next, None)
            result = method(**kwargs)

            if isinstance(result, bool) and \
                    not result and \
                    _next_iterator < _retry:
                return self._perform_method(_next, _next_iterator, kwargs,
                                            method)

            return result
        except Exception as ex:
            LOG.error('Exception: {}'.format(ex.message))
            if _next_iterator < _retry:
                return self._perform_method(_next, _next_iterator, kwargs,
                                            method)
            self.selenium.save_screenshot(
                'parakeet_error_{:05d}_{}.png'.format(next_image(),
                                                      method.__name__))
            raise ex
예제 #3
0
 def _type_handle(self, _type_pause, value):
     if _type_pause > 0:
         self._type_slowly(value, _type_pause)
     else:
         LOG.debug('type_normal {}'.format(value.encode('utf-8',
                                                        'replace')))
         self.element.send_keys(value)
예제 #4
0
 def redirect_to_home(self):
     LOG.debug('redirect_to_home')
     WebDriverWait(self.browser.selenium, self.browser.waiting_time, self.browser.poll_frequency)\
         .until(ec.title_contains(self.home_title))
     WebDriverWait(self.browser.selenium, self.browser.waiting_time, self.browser.poll_frequency)\
         .until(ec.invisibility_of_element_located((By.CLASS_NAME, 'main-loading')))
     return self
예제 #5
0
 def get_element_waiting_for_its_presence(self, locator, waiting_time=None):
     _waiting_time = waiting_time if waiting_time else self.waiting_time
     LOG.debug('get_element_waiting_for_its_presence({}, {}, {})'.format(
         locator, _waiting_time, self.poll_frequency))
     element = WebDriverWait(self.selenium, _waiting_time,
                             self.poll_frequency).until(
                                 ec.presence_of_element_located(locator))
     return element
예제 #6
0
 def get_element_waiting_for_its_presence_by_xpath(self,
                                                   xpath,
                                                   waiting_time=None):
     _waiting_time = waiting_time if waiting_time else self.waiting_time
     LOG.debug(
         'get_element_waiting_for_its_presence_by_xpath({}, {}, {})'.format(
             xpath, _waiting_time, self.poll_frequency))
     return self.get_element_waiting_for_its_presence((By.XPATH, xpath),
                                                      _waiting_time)
예제 #7
0
    def type(self, value, type_pause=0):
        _type_pause = type_pause if type_pause > 0 else self.parakeet.type_pause
        LOG.debug('type {} {}'.format(value.encode('utf-8', 'replace'),
                                      _type_pause))
        self.element = self.wait_visibility_of_element_located()
        self._type_handle(_type_pause, value)

        self.debounce()

        return self
예제 #8
0
    def fill_email(self, email):
        LOG.debug('fill_email')
        try:
            self.browser.find_element_by_id('identifierId').type(email)
        except TimeoutException:
            LOG.debug('click_on_identifier_before_fill_email')
            self.browser.find_element_by_id('identifierLink').click()
            self.browser.find_element_by_id('identifierId').type(email)

        return self
예제 #9
0
    def fill_email(self, email):
        LOG.debug('fill_email')
        try:
            self.browser.find_element_by_id('identifierId').type(email)
        except TimeoutException:
            LOG.debug('click_on_identifier_before_fill_email')
            self.browser.find_element_by_xpath(
                '//ul/li[last()]/div[@role="link"]').click()
            self.browser.find_element_by_id('identifierId').type(email)

        return self
예제 #10
0
def login(step, user_name):
    """
    If it is already logged do not attempt to login
    :param step:
    :param user_name:
    :return:
    """
    if world.cfg['system_page_title'] not in world.browser.selenium.title:
        LOG.debug(world.cfg.get('login_provider','missing login provider'))
        if world.cfg['login_provider'] == 'google_oauth':
            google_oauth(user_name)
        elif world.cfg['login_provider'] == 'google_oauth_gapi2':
            google_oauth_gapi2(user_name)
        LoginPage(world.browser, world.cfg['system_page_title']).redirect_to_home()
예제 #11
0
    def _type_slowly(self, value, type_pause):
        LOG.debug('type_slowly {}'.format(value.encode('utf-8', 'replace')))

        if not (type_pause and isinstance(type_pause, float)
                and 0.0 < type_pause < 1):
            raise ValueError(
                'The type_pause argument need to be an float valid number between 0.01 and 0.99'
            )

        for character in value:
            self.element.send_keys(character)
            time.sleep(type_pause)

        return self
예제 #12
0
파일: browser.py 프로젝트: kieras/parakeet
    def get_element_waiting_for_its_presence(self, locator, waiting_time=None):
        _waiting_time = waiting_time if waiting_time else self.waiting_time
        LOG.debug('get_element_waiting_for_its_presence({}, {}, {})'.format(
            locator, _waiting_time, self.poll_frequency))
        element = None

        try:
            element = WebDriverWait(
                self.selenium, _waiting_time, self.poll_frequency).until(
                    ec.presence_of_element_located(locator))
        except TimeoutException:
            LOG.error("Time is up! {}s".format(_waiting_time))
            self.selenium\
                .save_screenshot('parakeet_timeout_error_{:05d}.png'
                                 .format(next_image()))

        return element
예제 #13
0
 def login(self):
     LOG.debug('login')
     self.browser\
         .find_element_by_id('passwordNext')\
         .click()
     return self
예제 #14
0
 def fill_password(self, password):
     LOG.debug('fill_password')
     self.browser.splinter.\
         is_element_visible_by_css('#password input', self.browser.waiting_time)
     self.browser.splinter.type('password', decode(password))
     return self
예제 #15
0
 def click_next(self):
     LOG.debug('click_next')
     self.browser.find_element_by_id('identifierNext').click()
     return self
예제 #16
0
파일: browser.py 프로젝트: kieras/parakeet
 def _remove_scroll_back(self):
     LOG.info('---- Remove md-scroll-mask ---')
     self.splinter.execute_script(
         "document.getElementsByClassName('md-scroll-mask')[0]['style']['display'] = 'none'"
     )
예제 #17
0
 def quit(self):
     LOG.debug('quit')
     self.splinter.quit()
예제 #18
0
 def switch_windows_after(self):
     LOG.debug('switch_windows_after')
     popup = self.browser.selenium.window_handles[1]
     self.browser.selenium.switch_to_window(popup)
     return self
예제 #19
0
 def find_element_by_id(self, element_id, waiting_time=None):
     LOG.debug('find_element_by_id({})'.format(element_id))
     locator = (By.ID, element_id)
     element = self.get_element_waiting_for_its_presence(
         locator, waiting_time)
     return ParakeetElement(element, locator, self)
예제 #20
0
 def find_element_by_xpath(self, element_xpath):
     LOG.debug('find_element_by_xpath({})'.format(element_xpath))
     locator = (By.XPATH, element_xpath)
     element = self.get_element_waiting_for_its_presence(locator)
     return ParakeetElement(element, locator, self)
예제 #21
0
 def is_element_present_by_id(self, element_id):
     LOG.debug('is_element_present_by_id({})'.format(element_id))
     return self.splinter.is_element_present_by_id(element_id,
                                                   self.waiting_time)
예제 #22
0
파일: browser.py 프로젝트: kieras/parakeet
 def is_element_present_by_xpath(self, element_xpath, p_waiting_time=None):
     _waiting_time = p_waiting_time if p_waiting_time else self.waiting_time
     LOG.debug('is_element_present_by_xpath({}, {})'.format(
         element_xpath, _waiting_time))
     return self.splinter.is_element_present_by_xpath(
         element_xpath, _waiting_time)
예제 #23
0
 def is_element_present_by_xpath(self, element_xpath):
     LOG.debug('is_element_present_by_xpath({})'.format(element_xpath))
     return self.splinter.is_element_present_by_xpath(
         element_xpath, self.waiting_time)
예제 #24
0
 def visit_home(self):
     LOG.debug('visit_home')
     self.visit(self.config['home_url'])
예제 #25
0
 def visit(self, url):
     LOG.debug('visit')
     self.splinter.visit(url)
예제 #26
0
 def click_sign_in(self):
     LOG.debug('click_sign_in')
     self.browser.find_element_by_xpath('//md-card-actions/button').click()
     return self
예제 #27
0
 def switch_windows_before(self):
     LOG.debug('switch_windows_before')
     self.browser.selenium.switch_to_window(self.window)
     return self
예제 #28
0
파일: browser.py 프로젝트: kieras/parakeet
 def _remove_back_drop(self):
     LOG.info('---- Remove md-backdrop ---')
     self.splinter.execute_script(
         "document.getElementsByTagName('md-backdrop')[0].style.display = 'none'"
     )
예제 #29
0
 def set_window(self):
     LOG.debug('set_window')
     self.window = self.browser.selenium.window_handles[0]
     return self
예제 #30
0
 def is_text_present(self, text):
     LOG.debug('is_text_present({})'.format(text))
     return self.splinter.is_text_present(text)