Skip to content

Instantly share code, notes, and snippets.

@jmoody jmoody/Screenshotter.m
Last active Dec 5, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.