GREYCondition

@interface GREYCondition : NSObject

A class for creating boolean conditions that can be waited on until the condition is satisfied or a timeout elapses.

Conditions are specified in the form of a block that returns a @c BOOL value indicating whether the condition is met.

  • Creates a condition with a block that should return @c YES when the condition is met.

    Declaration

    Objective-C

    + (instancetype)conditionWithName:(NSString *)name
                                block:(BOOL (^)(void))conditionBlock;

    Parameters

    name

    A descriptive name for the condition

    conditionBlock

    The block that will be used to evaluate the condition.

    Return Value

    A new initialized GREYCondition instance.

  • @remark init is not an available initializer. Use the other initializers.

    Declaration

    Objective-C

    - (instancetype)init;
  • Initializes a condition with a block that should return @c YES when the condition is met.

    Declaration

    Objective-C

    - (instancetype)initWithName:(NSString *)name
                           block:(BOOL (^)(void))conditionBlock;

    Swift

    init!(name: String!, block conditionBlock: (() -> Bool)!)

    Parameters

    name

    A descriptive name for the condition

    conditionBlock

    The block that will be used to evaluate the condition.

    Return Value

    The initialized instance.

  • Waits for the condition to be met until the specified @c seconds have elapsed.

    Will poll the condition as often as possible on the main thread while still giving a fair chance for other sources and handlers to be serviced.

    @remark Waiting on conditions with this method is very CPU intensive on the main thread. If you do not need to return immediately after the condition is met, the consider using GREYCondition::waitWithTimeout:pollInterval:

    Declaration

    Objective-C

    - (BOOL)waitWithTimeout:(CFTimeInterval)seconds;

    Swift

    func wait(withTimeout seconds: CFTimeInterval) -> Bool

    Parameters

    seconds

    Amount of time to wait for the condition to be met, in seconds.

    Return Value

    @c YES if the condition was met before the timeout, @c NO otherwise.

  • Waits for the condition to be met until the specified @c seconds have elapsed. Will poll the condition immediately and then no more than once every @c interval seconds. Will attempt to poll the condition as close as possible to every @c interval seconds.

    @remark Will allow the main thread to sleep instead of busily checking the condition.

    Declaration

    Objective-C

    - (BOOL)waitWithTimeout:(CFTimeInterval)seconds
               pollInterval:(CFTimeInterval)interval;

    Swift

    func wait(withTimeout seconds: CFTimeInterval, pollInterval interval: CFTimeInterval) -> Bool

    Parameters

    seconds

    Amount of time to wait for the condition to be met, in seconds.

    interval

    The minimum time that should elapse between checking the condition.

    Return Value

    @c YES if the condition was met before the timeout, @c NO otherwise.

  • Declaration

    Objective-C

    - (NSString *)name;

    Swift

    func name() -> String!

    Return Value

    Name of the condition.