Where is the screenshot file from Xcode UI Test?

旧巷老猫 提交于 2019-12-05 14:35:20

问题


I'm interested how to find the location of a screenshot which is created during UI Tests of my app. I would like to understand how Fastlane Snapshot grabs this screenshot. After couple of hours of research I can't find location of those screenshots.


回答1:


Screenshots are stored inside your Derived Data folder. You can find this by going to Xcode, Window > Projects and click the little arrow next to your derived data path for the project.

From your project derived data folder (should be the name of your folder with a load of letters after it), go to Logs/Test.

Inside the Test folder will be test summary .plist files with UUIDs in their names (one per test run) and a folder called Attachments - the screenshots are in here.

If any of these folders aren't there, make sure you've run the tests first.

To work out which screenshot you want, you'll need to dig through the *_TestSummaries.plist file. Open it in Xcode and follow the test summary down to the SubActivity you're interested in. Some SubActivities don't have screenshots, and will have the HasScreenshotData key set to NO.

When you find a SubActivity with screenshot data, match the UUID for that SubActivity with the filename of the screenshot in the Attachments folder.

My screenshots were located at: /Users/{username}/Library/Developer/Xcode/DerivedData/{project_name}-tywebfjsswmghapfjfbzhuazjf/Logs/Test/Attachments.

In the .plist, I followed this path to find details of the screenshot data for an event: TestableSummaries > Item 0 > Tests > Item 0 > Subtests > Item 0 > Subtests > Item 0 > ActivitySummaries > Item 1 > SubActivities > Item 0.




回答2:


You can find screenshots in Xcode -> Report navigator -> select your test

Or go to

DerivedData -> ProjectName... -> Logs -> Test -> find .xcresult -> Show Package Contents -> Attachments



回答3:


In Xcode 11, the contents of an .xcresults file changed to no longer include an Attachments folder that's browsable in Finder. You can still download individual attachments from the Test Report as shown in yoAlex5's answer, but to get the attachments without using the Xcode GUI, you have to use xcresulttool or a third party tool that leverages xcresulttool like xcparse. See this blog post for more information: https://www.chargepoint.com/engineering/xcparse/



来源:https://stackoverflow.com/questions/37283647/where-is-the-screenshot-file-from-xcode-ui-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!