Yannis P.
Yannis P.

Reputation: 833

How do I take screenshots of my UI with Xcode 7 during UI Testing?

So I downloaded the beta of XCode 7 and I've created some UI tests, but I can't find the functionality of how to take screenshots of my app/UI during the test.

Can someone please help?

Upvotes: 11

Views: 6930

Answers (5)

KrauseFx
KrauseFx

Reputation: 11751

If you want to generate screenshots, you can also use snapshot, which describes how to trigger screenshots in UI tests: https://github.com/fastlane/fastlane/tree/master/snapshot#how-does-it-work

It basically rotates the device to .Unknown (Source), which triggers a snapshot without actually modifying your app's state.

Comparing the output with the generated plist file enables you to even properly name the screenshot

Upvotes: 3

TeodorN
TeodorN

Reputation: 11

I' ve created a tool that saves the tests last n screenshots and generates the JUnit tests results report, parsing TestSummaries plist file from test logs. https://github.com/nacuteodor/ProcessTestSummaries

Maybe, that helps you.

Upvotes: 0

divergio
divergio

Reputation: 2010

Facebook's ios-snapshot-test-case and KIF both run as Unit Tests, and therefore are in the same process as the app. As such, they can directly access views and use something like renderView: or snapshotViewAfterScreenUpdates. Xcode UI Testing runs in a separate process, and therefore cannot directly access the views.

UI Automation, Apple's now-deprecated Javascript UI testing library, had a function calledcaptureScreenWithName.

Unfortunately, the new Xcode UI Testing lacks any similar function in its testing library, which to me seems like a glaring omission and I encourage you to submit a Radar for it, as taking screenshots is fundamental to perceptual difference tests (which it sounds like you're trying to do). I hope (and expect) that able will address this deficiency in later Xcode updates.

In the meantime, there are more creative approaches to taking screenshots. See this stack overflow response for a workaround involving taking the screenshot in the app itself and then sending it to the test process.

Upvotes: 1

Senseful
Senseful

Reputation: 91911

UI Testing in Xcode automatically takes screenshots of your app after every step.

Simply go to one of the tests that has already ran (Report Navigator > choose a Test), then start expanding your tests. When you hover your mouse over the steps, you will see eye icons near each step that has a screenshot.

Here's an example... in this case, notice the eye icon at the end of the gray row. If I were to tap on it, I would see a screenshot of the app right when the button in my app was tapped (since the step is Tap the "Button" Button).

enter image description here

Upvotes: 18

ccoroom
ccoroom

Reputation: 689

Facebook's FBSnapshotTestCase can be alternative solution:

https://github.com/facebook/ios-snapshot-test-case

Upvotes: -1

Related Questions