Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 232
Yannis P. Avatar asked Jul 15 '15 14:07

Yannis P.


People also ask

How do you take a screenshot in XCode?

Open the screen that you want to capture. Press the Power and Volume down buttons at the same time.

How do I test UI in XCode?

How to Run XCUI Tests on XCode. To run the XCUITests on XCode, you can click the highlighted icon below to see your newly created UI Test targets. You can hover on the “testExample()” test case and click the “Play” icon to run that specific test to see if everything was set up properly.

How do you do iOS UI testing?

Recording a UI TestFrom the debug bar, click the Record UI Test button. Xcode will launch the app and run it. You can interact with the element on-screen and perform a sequence of interactions for any UI test. Whenever you interact with an element, Xcode writes the corresponding code for it into your method.


2 Answers

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

like image 154
Senseful Avatar answered Oct 18 '22 01:10

Senseful


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

like image 3
KrauseFx Avatar answered Oct 18 '22 01:10

KrauseFx