AWS Device Farm Sample App for iOS
This is a sample native iOS app that contains many of the stock iOS components and elements. It also contains multiple Calabash tests to get you started. You can also use this app with the AWS Device Farm Built-in Fuzz Test.
You can use this app and example test suite as a reference for your own Device Farm tests.
All of the views are programatically created within the app. Storyboard or XIB files are not used. This is to prevent merge conflicts in the future.
Explicit delays are occasionally added to the tests to allow the page to fully render, they are commented as such in the code.
In order to run this app within Device Farm you will need to create a local copy of this repository and build the application from source.
Building Project with Xcode
- Select the Calabash target (if built with Calabash) and select an iOS Device
- Use the
Product/Build for Runningoption
Packing and Creating IPA
- Go into your build directory:
- Create a new directory named "Payload"
- Move the appName.app folder into the "Payload" folder
- Zip the "Payload" folder and give it a .ipa extension
Testing on Device Farm
Follow the steps in the official AWS Device Farm documentation for:
Examples of Specific Scenarios
|Alerts: Modal View, Alerts, Pop Overs (only works on iPads)||source code - Calabash Test|
|Static Page||source code - Calabash Test|
|Login Page||source code - Calabash Test|
|Navigation Controllers||source code - Calabash Test|
|Expected Crash||source code|
|Web View||source code - Calabash Test|
Examples of Native Features
|Image Gallery||source code|
|Scroll View||source code|
|Out of View Content||source code|
|Table of Elements||source code|
Examples of Inputs
Examples of Navigation
|Tab Bar||source code|
|Page Viewer||source code|
Using XCUI Recorder
- Xcode 9 or above
- iOS simulator downloaded or a physical iOS device.
- Download the AWS Device Farm iOS sample app.
- Open the project in Xcode.
- We will generate tests XCUI using a new test target.
- Select File —> New —> Target —> iOS UI Testing Bundle.
- Click Next.
- Enter a Product Name
For e.g. AWSDeviceFarmiOSReferenceAppUITests_Mock
- If you have a apple developer account you can choose that for the Team option.
- Choose Language as Swift.
- Click Finish.
- In your project navigator you should now see the new target swift files generated. Open AWSDeviceFarmiOSReferenceAppUITests_Mock.swift.
- The file will have setUp(), tearDown() and a testExample() function. testExample() is the function where our test code generated through XCUI test recorder will live. Click inside the scope of function testExample().
- Select a target device for the recording. Click on the red record button present in the Debug bar as shown below. This will open up the selected simulator for you to record your UI interactions.
When the app opens up on the simulator, inside the app click on More —> Alerts —> Modal --> OK
Go to Xcode and press the record button again to stop recording the test. We now have the test code generated to test Alert section of the sample app.
We will add an XCAssert after the recording is complete to check if the modal view is present. This can done using the code snippet :
XCTAssertNotNil(app.staticTexts["This is a modal view"])
- The project has existing XCUI tests which we do not want to run. We will disable the existing tests and only run our generated tests. Go to Product —> Scheme —>Edit Scheme. Select Build on left hand side. Uncheck all existing test targets except AWSDeviceFarmiOSReferenceApp and your generated test target AWSDeviceFarmiOSReferenceAppUITests_Mock
- For specifying which tests to build select Test on the left side. Click on ‘+’ . Choose only your test target. Click Add. Click Close in the main window.
- To build the tests for simulator go to Product —> Build for Testing.
Note: If you want to run on Device Farm you should build and run your tests against a real physical device. Tests build for simulator will not run on real devices. For the purpose of the instructions here we are going to consider simulator.
- To run the tests go to Product —> Test. This will open up the simulator and run the tests.
- We want to package and upload these tests to Device Farm to test it against a number of devices.
To package the tests go to your Project explorer on the left hand side. Right click on AWSDeviceFarmiOSReferenceApp under Products folder —> Show in Finder. This will take to the location of your app and tests build output. Look for the runner app of your tests: AWSDeviceFarmiOSReferenceAppUITests_Mock-Runner. Create a folder named “Payload” case-sensitive anywhere in your file system. Copy the tests runner app inside Payload. Right click on Payload —> Compress Payload. Rename the extensions of the compressed zip file to .ipa. When asked if you want to keep .ipa option choose yes. This is your test IPA that can be uploaded to AWS Device Farm.
- You can build an IPA of the app using your developer account or a pre-built version of the app and tests can be found here.