GREYUIThreadExecutor
@interface GREYUIThreadExecutor : NSObject
Executor that syncs execution with the UI events on the main thread. Before executing a block or operation, it waits for any pending UI events to complete.
-
Declaration
Objective-C
+ (instancetype)sharedInstance;
Swift
class func sharedInstance() -> Self!
Return Value
The unique shared instance of the GREYUIThreadExecutor.
-
@remark init is not an available initializer. Use the other initializers.
Declaration
Objective-C
- (instancetype)init;
-
Blocking call that drains the main runloop enough times to make each source gets a fair chance of service. No guarantee is made on whether the app is in kGREYIdle state after this method returns.
Declaration
Objective-C
- (void)drainOnce;
Swift
func drainOnce()
-
Blocking call that drains the UI thread for the specified number of @c seconds. This method can block for longer than the specified time if any of the signalled sources take longer than that to execute.
Declaration
Objective-C
- (void)drainForTime:(CFTimeInterval)seconds;
Swift
func drain(forTime seconds: CFTimeInterval)
Parameters
seconds
Amount of time that the UI thread should be drained for, in seconds.
-
Blocking call that drains the UI thread until both the UI and registered GREYIdlingResources are in idle.
@remark Be very careful while calling this as you could end up in state where the caller expects the callee to mark the thread as idle and callee inadvertantly calls GREYUIThreadExecutor::drainUntilIdle:, in which case it will go into an infinite loop and the test will have to be force-killed by the test-runner.
Declaration
Objective-C
- (void)drainUntilIdle;
Swift
func drainUntilIdle()
-
Drains the UI thread and waits for both the UI and idling resources to idle until the given amount of @c seconds have passed, at which point, a timeout occurs and the method returns @c NO. Returns @c YES if idled within @c seconds, @c NO otherwise.
Declaration
Objective-C
- (BOOL)drainUntilIdleWithTimeout:(CFTimeInterval)seconds;
Swift
func drainUntilIdle(withTimeout seconds: CFTimeInterval) -> Bool
Parameters
seconds
Amount of time to wait for the UI and idling resources to idle.
Return Value
@c YES if idled within @c seconds, @c NO otherwise.
-
Invokes GREYUIThreadExecutor::executeSyncWithTimeout:block:error: with @c kGREYInfiniteTimeout, @c execBlock and @c error as the respective parameters.
Declaration
Objective-C
- (BOOL)executeSync:(GREYExecBlock)execBlock error:(NSError **)error;
Swift
func executeSync(_ execBlock: GREYExecBlock!, error: UnsafeMutablePointer
Parameters
execBlock
The block to be executed.
error
Reference to the error that will store the failure cause, if any.
Return Value
@c YES if the block was executed, @c NO otherwise, in which case @c error will be set to the failure cause.
-
Executes @c execBlock on the main thread, synchronizing with all registered GREYIdlingResources and UI events. If the UI thread or idling resources are not idle until @c seconds have elapsed, @c execBlock is not executed and error (if provided) is populated.
@remark Blocks are executed in the order in which they were submitted. @remark This selector must be invoked on the main thread.
Declaration
Objective-C
- (BOOL)executeSyncWithTimeout:(CFTimeInterval)seconds block:(GREYExecBlock)execBlock error:(NSError **)error;
Swift
func executeSync(withTimeout seconds: CFTimeInterval, block execBlock: GREYExecBlock!, error: UnsafeMutablePointer
Parameters
seconds
The timeout for waiting for the resources to idle, in seconds. A value of @c kGREYInfiniteTimeout indicates an infinite timeout.
execBlock
The block to be executed.
error
Reference to the error that will store the failure cause, if any.
Return Value
@c YES if the block was executed, @c NO otherwise, in which case @c error will be set to the failure cause.