Skip to content

Instantly share code, notes, and snippets.

@jmoody
Last active December 5, 2019 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmoody/3f8a456eef395ff6dc8d1265f8271ff5 to your computer and use it in GitHub Desktop.
Save jmoody/3f8a456eef395ff6dc8d1265f8271ff5 to your computer and use it in GitHub Desktop.
Add a step and a screenshot to your Test Cloud report
#import <XCTest/XCTest.h>
#import "Screenshotter.h"
@implementation Screenshotter
+ (void)screenshotWithTitle:(NSString *)format, ... {
NSString *title = nil;
va_list args;
va_start(args, format);
title = [[NSString alloc] initWithFormat:format arguments:args];
va_end(args);
[XCTContext
runActivityNamed:title
block:^(id<XCTActivity> _Nonnull activity) {
XCUIScreenshot *screenshot = [[XCUIScreen mainScreen] screenshot];
XCTAttachment *attachment;
attachment = [XCTAttachment attachmentWithScreenshot:screenshot];
[attachment setLifetime:XCTAttachmentLifetimeKeepAlways];
[activity addAttachment:attachment];
}];
}
+ (void)addScreenshotToActivity:(id<XCTActivity> _Nonnull ) activity; {
XCUIScreenshot *screenshot = [[XCUIScreen mainScreen] screenshot];
XCTAttachment *attachment;
attachment = [XCTAttachment attachmentWithScreenshot:screenshot];
[attachment setLifetime:XCTAttachmentLifetimeKeepAlways];
[activity addAttachment:attachment];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment