Páginas

fastlane snapshots and xamarin

As you all know, fastlane is the easiest way to automate beta deployments and releases for your iOS and Android apps. It handles all tedious tasks, like generating screenshots, dealing with code signing, and releasing your application.You can use fastlane snapshots  to automate the process of capturing screenshots of your app. It allows you to:
  • Capture hundreds of screenshots in multiple languages on all simulators
  • Take screenshots in multiple device simulators concurrently to cut down execution time (Xcode 9 only)
  • Do something else while the computer takes the screenshots for you
  • Configure it once, and store the configuration so anyone on the team can run it
  • Generate a beautiful web page showing all screenshots on all devices. This is perfect to send to Q&A, marketing, or translators for verification
  • Avoid having loading indicators in your App Store screenshots by intelligently waiting for network requests to be finished
  • Get a summary of how your app looks like across all supported devices and languages
Here https://docs.fastlane.tools/getting-started/ios/screenshots/  you have all the necessary information to take the best screenshots you need.

Unfortunately for Xamarin users, snapshots uses UITests, which require an Xcode project so, Is there anything we can do to use snapshots with our Xamarin projects? 

The answer is short, YES YOU CAN!!!

Setting up you XCUITest project

UITest  does not use the project code to test, it exists outside the app. UITest instead looks at what is available in the simulator and returns to us instances of XCUIElement based on what it finds, XCUIElement and XCUIApplication are the proxies that are used for this.

So you only need to open XCode, go to FILE --> NEW --> PROJECT and select SINGLE VIEW APP, click the NEXT button and on the next screen, the most important thing, is that you check "INCLUDE UI TEST".
 

Now you have almost ready, just follow this information https://docs.fastlane.tools/getting-started/ios/screenshots/ to configure your project.

Xamarin app? How?

As explained here https://medium.com/xcblog/hands-on-xcuitest-features-with-xcode-9-eb4d00be2781 now XCUIApplication() has initialiser which takes bundleIdentifier so that we can pass bundleID of our app and has new activate() method to activate app from background. 

As you can see, you can interact with any app within Simulator or device as long as we know bundle identifier. This is huge improvement in UI testing of iOS apps. 

Guess what? You can interact with you Xamarin app as far as it's deployed in the simulator! You can install your Xamarin in the simulator as normal, I mean, just hitting the PLAY / DEBUG button on your Visual Studio for macOS.

Automate everything

But what if you can automate you Xamarin iOs deployment? I also have the answer! 

To install an iOs app from the command line you can use this command: xcrun simctl install

Where
  1. device can be the device UUID, its name, or booted which means the currently booted device
  2. path is the path of your .app. 

Get simulator device UUID

To get all your devices UUID, execute this command: xcrun instruments -s devices

For more information please visit https://developer.xamarin.com/guides/testcloud/calabash/working-with/identifying-ios-devices-and-simulators/ 

Get the path of your .app

It's in your build folder pathToYourAppSourceCode/bin/iPhoneSimulator/Debug/device-builds/iphone[build ios version]/appName.app. In case of my hypstr app, the location is here

Tying everything up

Create a bash script to automate app deploy to all your selected simulators (https://www.macobserver.com/tmo/article/os-x-how-to-convert-a-terminal-command-into-a-double-clickable-desktop-file)

eg:

#!/bin/bash

echo booting iphone 6 simulator
xcrun simctl boot E26FC3E7-DF91-49DF-AE9D-3A7443B849AD

echo deploying app
xcrun simctl install E26FC3E7-DF91-49DF-AE9D-3A7443B849AD pathToYourAppSourceCode/bin/iPhoneSimulator/Debug/device-builds/iphone[build ios version]/hypstr.UI.iOs.app

echo shutdown simulator
xcrun simctl shutdown E26FC3E7-DF91-49DF-AE9D-3A7443B849AD


More info on ios simulator commands https://medium.com/xcblog/simctl-control-ios-simulators-from-command-line-78b9006a20dc

As only these screens are needed for iPhone when submitting to App Store, just create the script to deploy to this four simulator:
  1. iPhone 7 Plus (5.5-Inch)
  2. iPhone 7 (4.7-Inch)
  3. iPhone 5 (4-Inch)
  4. iPhone X
Those simulators are the ones you need to specify in you Snapfile (snapshots config file)

Magic, magic, magic! 

Following this approach, I manage to take my screeshots for my Xamarin app called hypstr published in the App Store https://itunes.apple.com/us/app/hypstr/id650216315 using fastlane snapshots as you can see in the following image


Enjoy!

More info about fastlane, snapshots and XCUITest: