10

Every time we change something in the UI, we have to manually prepare and take 375 (= 5 screenshots * 5 device types * 15 languages) screenshots for iTunes Connect's listing.

I'm trying to "exploit" iOS 9's new UI testing to automatically prepare and take these screenshots for each language. This should save a huge amount of time and provide a better experience to our users, because we didn't update the screenshots frequently due to the hard work involved.

I couldn't find much help on the internet, probably because this feature is too fresh. So here are two essential questions, hopefully we can find a way to make it happen.

  1. Is it possible to save a screenshot to disk through the UI testing API?

  2. Is it possible to have a clean install for a XCTestCase?

Senseful
  • 79,995
  • 61
  • 289
  • 423
Kof
  • 22,583
  • 8
  • 54
  • 79

3 Answers3

11

This isn't completely related to Xcode 7, but you can automate screenshot taking with snapshot.

rounak
  • 8,989
  • 3
  • 39
  • 58
  • 1
    Doesn't answer the UI tests API questions, but I'll accept because it solves the problem perfectly and maybe even in a better way. – Kof Jun 18 '15 at 09:51
  • @rounak I saw that yesterday when looking at snapshot :) – Andrew Jun 19 '15 at 03:18
  • @Kof I've implemented screenshot taking for Xcode7 UI tests. Screenshots are captured by the app and passed to the test via sockets, requires adding a framework to the app. The code is here: https://github.com/zmeyc/UITestUtils – Zmey Jul 16 '15 at 16:38
5

Yes, you can create screenshots using the Xcode UI Testing.

  • Create a custom scheme for your tests (optional but recommended).
  • Use CLI(terminal) to run the tests. Something like this:
xcodebuild -workspace App.xcworkspace \
     -scheme "SchemeName" \
           -sdk iphonesimulator \
           -destination 'platform=iOS Simulator,name=iPhone 6,OS=9.0' 
           test

Once you are done with this, to generate screenshots, add the path to where you want the screenshots, like this:

xcodebuild -workspace App.xcworkspace \
 -scheme "SchemeName" \
       -sdk iphonesimulator \
       -destination 'platform=iOS Simulator,name=iPhone 6,OS=9.0'
       -derivedDataPath './output'
       test

./output will tell Xcode to take screenshots for every test. You can find this in detail here

Gautam Jain
  • 2,913
  • 29
  • 25
3
  1. Is it possible to save a screenshot to disk through the UI testing API?

You can manually save them (through the "open in preview" button), but I do not know of an API to collect them during the tests. File a radar! (https://bugreport.apple.com)

  1. Is it possible to have a clean install for a XCTestCase?

I don't know of a way to actually reinstall your app for every XCTestCase, but you can uninstall it before running all of your tests, or you can use the setUp class method or instance method on XCTestCase to ensure that your app is in a fresh state before your tests are run (ex. reset user defaults, etc).

Community
  • 1
  • 1
Andrew
  • 15,264
  • 6
  • 63
  • 100
  • 2
    About #2, how do I reset user defaults / documents dir on the `setUp`? Couldn't find anything related in XCUIApplication reference. – Kof Jun 18 '15 at 09:33
  • @Kof: see here: http://stackoverflow.com/questions/32351149/how-do-i-reset-the-application-data-after-each-test-with-xcode-7-ui-testing , and here http://www.adamkaump.com/thoughts/uitests – Peacemoon Sep 15 '15 at 14:59