capybara/node/base.py
def synchronize(self, func=None, wait=None, errors=()):
        """
        This method is Capybara's primary defense against asynchronicity problems. It works by
        attempting to run a given decorated function until it succeeds. The exact behavior of this
        method depends on a number of factors. Basically there are certain exceptions which, when
        raised from the decorated function, instead of bubbling up, are caught, and the function is
        re-run.

        Certain drivers have no support for asynchronous processes. These drivers run the function,
        and any error raised bubbles up immediately. This allows faster turn around in the case
        where an expectation fails.

        Only exceptions that are :exc:`ElementNotFound` or any subclass thereof cause the block to
        be rerun. Drivers may specify additional exceptions which also cause reruns. This usually
        occurs when a node is manipulated which no longer exists on the page. For example, the
        Selenium driver specifies ``selenium.common.exceptions.StateElementReferenceException``.

        As long as any of these exceptions are thrown, the function is re-run, until a certain
        amount of time passes. The amount of time defaults to :data:`capybara.default_max_wait_time`
        and can be overridden through the ``wait`` argument. This time is compared with the system
        time to see how much time has passed. If the return value of ``time.time()`` is stubbed
        out, Capybara will raise :exc:`FrozenInTime`.

        Args:
            func (Callable, optional): The function to decorate.
            wait (int, optional): Number of seconds to retry this function.
            errors (Tuple[Type[Exception]], optional): Exception types that cause the function to be
                rerun. Defaults to ``driver.invalid_element_errors`` + :exc:`ElementNotFound`.

        Returns:
            Callable: The decorated function, or a decorator function.

        Raises:
            FrozenInTime: If the return value of ``time.time()`` appears stuck.
        """

        def decorator(func):
            @wraps(func)
            def outer(*args, **kwargs):
                seconds = wait if wait is not None else capybara.default_max_wait_time

                def inner():
                    return func(*args, **kwargs)

                if self.session.synchronized:
                    return inner()
                else:
                    timer = Timer(seconds)
                    self.session.synchronized = True
                    try:
                        while True:
                            try:
                                return inner()
                            except Exception as e:
                                self.session.raise_server_error()

                                if not self._should_catch_error(e, errors):
                                    raise
                                if timer.expired:
                                    raise

                                sleep(0.05)

                                if timer.stalled:
                                    raise FrozenInTime(
                                        "time appears to be frozen, Capybara does not work with "
                                        "libraries which freeze time, consider using time "
                                        "traveling instead")
                                if capybara.automatic_reload:
                                    self.reload()
                    finally:
                        self.session.synchronized = False

            return outer

        if func:
            return decorator(func)
        else:
            return decorator
def synchronize(self, func=None, wait=None, errors=()):
        def decorator(func):
            @wraps(func)
            def outer(*args, **kwargs):
                seconds = wait if wait is not None else capybara.default_max_wait_time

                def inner():
                    return func(*args, **kwargs)

                if self.session.synchronized:
                    return inner()
                else:
                    timer = Timer(seconds)
                    self.session.synchronized = True
                    try:
                        while True:
                            try:
                                return inner()
                            except Exception as e:
                                self.session.raise_server_error()

                                if not self._should_catch_error(e, errors):
                                    raise
                                if timer.expired:
                                    raise

                                sleep(0.05)

                                if timer.stalled:
                                    raise FrozenInTime(
                                        "time appears to be frozen, Capybara does not work with "
                                        "libraries which freeze time, consider using time "
                                        "traveling instead")
                                if capybara.automatic_reload:
                                    self.reload()
                    finally:
                        self.session.synchronized = False

            return outer

        if func:
            return decorator(func)
        else:
            return decorator
def synchronize ( self , func = None , wait = None , errors = ( ) ) : def decorator ( func ) : @ wraps ( func ) def outer ( * args , * * kwargs ) : seconds = wait if wait is not None else capybara . default_max_wait_time def inner ( ) : return func ( * args , * * kwargs ) if self . session . synchronized : return inner ( ) else : timer = Timer ( seconds ) self . session . synchronized = True try : while True : try : return inner ( ) except Exception as e : self . session . raise_server_error ( ) if not self . _should_catch_error ( e , errors ) : raise if timer . expired : raise sleep ( 0.05 ) if timer . stalled : raise FrozenInTime ( "time appears to be frozen, Capybara does not work with " "libraries which freeze time, consider using time " "traveling instead" ) if capybara . automatic_reload : self . reload ( ) finally : self . session . synchronized = False return outer if func : return decorator ( func ) else : return decorator
This method is Capybara's primary defense against asynchronicity problems. It works by
        attempting to run a given decorated function until it succeeds. The exact behavior of this
        method depends on a number of factors. Basically there are certain exceptions which, when
        raised from the decorated function, instead of bubbling up, are caught, and the function is
        re-run.

        Certain drivers have no support for asynchronous processes. These drivers run the function,
        and any error raised bubbles up immediately. This allows faster turn around in the case
        where an expectation fails.

        Only exceptions that are :exc:`ElementNotFound` or any subclass thereof cause the block to
        be rerun. Drivers may specify additional exceptions which also cause reruns. This usually
        occurs when a node is manipulated which no longer exists on the page. For example, the
        Selenium driver specifies ``selenium.common.exceptions.StateElementReferenceException``.

        As long as any of these exceptions are thrown, the function is re-run, until a certain
        amount of time passes. The amount of time defaults to :data:`capybara.default_max_wait_time`
        and can be overridden through the ``wait`` argument. This time is compared with the system
        time to see how much time has passed. If the return value of ``time.time()`` is stubbed
        out, Capybara will raise :exc:`FrozenInTime`.

        Args:
            func (Callable, optional): The function to decorate.
            wait (int, optional): Number of seconds to retry this function.
            errors (Tuple[Type[Exception]], optional): Exception types that cause the function to be
                rerun. Defaults to ``driver.invalid_element_errors`` + :exc:`ElementNotFound`.

        Returns:
            Callable: The decorated function, or a decorator function.

        Raises:
            FrozenInTime: If the return value of ``time.time()`` appears stuck.
This method is Capybara s primary defense against asynchronicity problems . It works by attempting to run a given decorated function until it succeeds . The exact behavior of this method depends on a number of factors . Basically there are certain exceptions which when raised from the decorated function instead of bubbling up are caught and the function is re - run .