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

5

11

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?

Ottillia answered 15/7, 2015 at 14:52 Comment(0)
D
18

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

Deweydewhirst answered 22/7, 2015 at 22:54 Comment(5)
Does this work in XCode 7.1 ? I am not able to see the same. Also through this process, XCode will take screenshots for Failed test cases as well ?Sides
In Xcode 7.1 right click on the test and select "Jump to report".Treenatreenail
Is there a way to reference these screenshots from within the tests themselves? That would allow us to compare the result of an action to the desired result. Is that possible?Commons
These eye icons are not appearing for me in Xcode 7.3beta5 (7D162j).Chap
@LeMotJuiced This can be used to analyze the results of a test and figure out why it broke, but it can't be used for perceptual difference testing. The screenshot is not available to the test code.Titrate
H
3

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

Handgun answered 9/8, 2016 at 20:12 Comment(3)
fastlane snapshot and deliver works great when generating app store screenshots. However I'm looking for a solution to generate a static website from snapshots which is targeted towards purely UITests. For example screenshots batches are separated based on test cases+devices+language. Can we have such a flavor in snapshot in future or do you know any alternative?Gerhard
Can you not use snapshot for that?Handgun
I can. And of course I'm using snapshot. I just want a different template for generated static web page.(A separation of image batches based on the test) which I'm working on. I was wondering if there anything already available.Gerhard
T
1

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.

Titrate answered 13/4, 2016 at 9:0 Comment(0)
L
0

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.

Lynnelynnea answered 24/5, 2016 at 16:11 Comment(1)
Can I ask you to take a look at How to offer personal open-source libraries? please?Spaghetti
U
-1

Facebook's FBSnapshotTestCase can be alternative solution:

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

Ultrared answered 15/7, 2015 at 15:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.