I have some (very old ObjC) XCUITests, in Xcode 15.2. I recently noticed programmatic screenshots are not saving. The screenshots generated automatically by XCUITest are saving fine. This is code that used to work as expected; I do not know when it broke as I haven't had need to run this in a while.
-(void)takeScreenshotWithName:(NSString *)name {
XCUIScreenshot *screenshot = XCUIScreen.mainScreen.screenshot;
XCTAttachment *attachment = [XCTAttachment attachmentWithScreenshot:screenshot];
attachment.lifetime = XCTAttachmentLifetimeKeepAlways;
attachment.name = name;
[self addAttachment:attachment];
UIImage *image = screenshot.image;
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
During testing I added the UIImageWriteToSavedPhotosAlbum call, to verify the code is running and the image is available - and it does. But I really don't want these images cluttering up my library.
The results are the same whether I run my tests from within Xcode, or via the command line.
I need these screenshots so I have a set in PNG format, with standardized naming, for archiving, searching, and comparisons. The automatic screenshots are in Xcode's format - useful when reviewing a single test, which isn't my use case here.