GREYScreenshotUtil

@interface GREYScreenshotUtil : NSObject

Provides interfaces for taking screenshots of the entire screen and UI elements of the App.

  • Draws the application’s main screen using the bitmap graphics context specified by the @c bitmapContextRef reference, centering it if the context size is different than the screen size. The provided reference must point to a CGBitmapContext. When @c afterUpdates is set to @c YES, this method waits for the screen to draw pending changes before taking a screenshot, otherwise the screenshot contains the current contents of the screen.

    Declaration

    Objective-C

    + (void)drawScreenInContext:(CGContextRef)bitmapContextRef
             afterScreenUpdates:(BOOL)afterUpdates;

    Swift

    class func drawScreen(inContext bitmapContextRef: Any!, afterScreenUpdates afterUpdates: Any!)

    Parameters

    bitmapContextRef

    Target bitmap context for rendering.

    afterUpdates

    Boolean indicating whether to render before (@c NO) or after (@c YES) screen updates.

  • Declaration

    Objective-C

    + (UIImage *)takeScreenshot;

    Swift

    class func takeScreenshot() -> Any!

    Return Value

    An image of the current app’s screen frame buffer. This method waits for any pending screen updates to go through before taking a screenshot. Returned image orientation is same as the current interface orientation.

  • Declaration

    Objective-C

    + (UIImage *)takeScreenshotForAppStore;

    Swift

    class func takeScreenshotForAppStore() -> Any!

    Return Value

    The App Store and iTunes Connect friendly image of the current screen frame buffer.

  • Declaration

    Objective-C

    + (UIImage *)snapshotElement:(id)element;

    Swift

    class func snapshotElement(_ element: Any!) -> Any!

    Return Value

    A snapshot of the provided @c element. @c element must be an instance of @c UIView or an accessibility element.

  • Saves the provided @c image as a PNG to the given @c filename under the given @c directoryPath. If the given directory path doesn’t exist, it will be created.

    Declaration

    Objective-C

    + (NSString *)saveImageAsPNG:(UIImage *)image
                          toFile:(NSString *)filename
                     inDirectory:(NSString *)directoryPath;

    Swift

    class func saveImage(asPNG image: Any!, toFile filename: Any!, inDirectory directoryPath: Any!) -> Any!

    Parameters

    image

    The source image.

    filename

    The target file name.

    directoryPath

    The path to the directory where the image must be saved.

    Return Value

    The complete filepath and name of the saved image or @c nil on failure.