Exemplo n.º 1
0
    def for_(self, fn: Callable[[E], R]) -> R:
        finish_time = time.time() + self._timeout

        while True:
            try:
                return fn(self._entity)
            except Exception as reason:
                if time.time() > finish_time:

                    reason_message = str(reason)

                    reason_string = '{name}: {message}'.format(
                        name=reason.__class__.__name__, message=reason_message
                    )
                    # todo: think on how can we improve logging failures in selene, e.g. reverse msg and stacktrace
                    # stacktrace = getattr(reason, 'stacktrace', None)
                    timeout = self._timeout
                    entity = self._entity

                    failure = TimeoutException(
                        f'''

Timed out after {timeout}s, while waiting for:
{entity}.{fn}

Reason: {reason_string}'''
                    )

                    raise self._hook_failure(failure)
Exemplo n.º 2
0
        def save_and_log_page_source(error: TimeoutException) -> Exception:
            filename = self.last_screenshot.replace('.png', '.html') if self.last_screenshot \
                else self.generate_filename(suffix='.html')
            path = Help(self.driver).save_page_source(filename)
            self.last_page_source = path
            return TimeoutException(error.msg + f'''
PageSource: file://{path}''')
Exemplo n.º 3
0
        def save_and_log_screenshot(error: TimeoutException) -> Exception:
            path = Help(self.driver).save_screenshot(
                self.generate_filename(suffix='.png')
            )
            self.last_screenshot = path
            return TimeoutException(
                error.msg
                + f'''
Screenshot: file://{path}'''
            )