Package 

Class FlakySafetyProviderGlobalImpl

  • All Implemented Interfaces:
    com.kaspersky.kaspresso.flakysafety.FlakySafetyProvider

    
    public final class FlakySafetyProviderGlobalImpl
     implements FlakySafetyProvider
                        

    The implementation of the FlakySafetyProvider interface.

    By default, this implementation is using in tests (not inside a View).

    Why? Have a glance at the example:

    someView {
        flakySafety(timeout = 20.sec) {
            isVisible()
        }
    }

    In this case, Kaspresso tries to execute someView.isVisible() for 10 seconds (default timeout for FlakySafety interceptors). After 10 seconds someView.isVisible() fails, throws an exception and writes info in logs. This exception is catching by extra ``flakySafety`` that tries to repeat.

    But such log messages make logs dirty and confuse a developer or tester.

    Besides, extra ``flakySafety`` can contain more actions, that's why there is probability of not having time to execute entire block. Honestly, we don't recommend to put into flakySafety block more than one concrete action.

    All of this pushed us to write special implementation of FlakySafetyProvider.

    The algorithm:

    Such behavior allows us to observe more predictable log information (a developer will see only one and correct error message in described above example) and avoids potentially inconsistent execution.

    • Method Summary

      Modifier and Type Method Description
      <T extends Any> T flakySafely(Function0<T> action) Invokes the given action flaky safely.
      <T extends Any> T flakySafely(Long timeoutMs, Long intervalMs, Set<Class<Out Throwable>> allowedExceptions, String failureMessage, Function0<T> action) Invokes the given action flaky safely.
      • Methods inherited from class com.kaspersky.kaspresso.flakysafety.FlakySafetyProvider

        equals, hashCode, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FlakySafetyProviderGlobalImpl

        FlakySafetyProviderGlobalImpl(Kaspresso kaspresso)
    • Method Detail

      • flakySafely

         <T extends Any> T flakySafely(Function0<T> action)

        Invokes the given action flaky safely.

        Parameters:
        action - the action to invoke.
      • flakySafely

         <T extends Any> T flakySafely(Long timeoutMs, Long intervalMs, Set<Class<Out Throwable>> allowedExceptions, String failureMessage, Function0<T> action)

        Invokes the given action flaky safely.

        Parameters:
        timeoutMs - the timeout during which attempts will be made.
        intervalMs - the interval at which attempts will be made.
        allowedExceptions - the set of exceptions, if caught, attempt will continue.
        failureMessage - the message to log on failure.
        action - the action to invoke.