XCUITest Screenshots not saving

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.

I'm encountering the same issue. It works fine on Xcode 15.4, but not on Xcode 16. In Xcode 16, the path/to/my/app.xcresult/Staging/1_Test folder does not contain an Attachments folder, whereas in Xcode 15, the Attachments folder is created as soon as the tests start.

I am also having this problem. In Xcode 15, in every UITest failure, I can select the failure, and it goes to the "Automation Explorer" where I can replay the test at every step and see the screenshots to the right. In Xcode 16, the view on the right that shows the screenshots is simply gone, with no way to bring it back. That view was incredibly helpful, and I have no idea why it's gone or how to restore it. If I switch back to Xcode 15, it's there and working fine.

XCUITest Screenshots not saving
 
 
Q