iOS UI Testing with AWS Device Farm and Jenkins
See this Gist for .app
to .ipa
.
Jenkins Step 1
#!/bin/bash -l
#
echo ">>> xctool, build tests"
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
cd src
export DERIVED_DATA_DIR=`mktemp -d`
echo " DerivedData folder is ${DERIVED_DATA_DIR}"
security unlock-keychain -p ci ~/Library/Keychains/login.keychain
xctool build-tests -workspace ./my-app.xcworkspace -scheme my-appUITests -derivedDataPath ${DERIVED_DATA_DIR}
java -jar ${JENKINS_HOME}/war/WEB-INF/jenkins-cli.jar -s ${JENKINS_URL} set-build-parameter DERIVED_DATA_DIR "${DERIVED_DATA_DIR}"
exit
Jenkins Step 2
#!/bin/bash -l
#
echo ">>> Derived Data"
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
echo " DerivedData folder is ${DERIVED_DATA_DIR}"
find ${DERIVED_DATA_DIR} -name "*.app"
#${DERIVED_DATA_DIR}/Build/Products/Debug-iphoneos/my-app.app
#${DERIVED_DATA_DIR}/Build/Products/Debug-iphoneos/my-appUITests-Runner.app
mkdir AWS_BUILD_DIR
mkdir AWS_BUILD_DIR/my-app
mkdir AWS_BUILD_DIR/my-app/Payload
mkdir AWS_BUILD_DIR/my-appUITests-Runner
mkdir AWS_BUILD_DIR/my-appUITests-Runner/Payload
cp -R ${DERIVED_DATA_DIR}/Build/Products/Debug-iphoneos/my-app.app AWS_BUILD_DIR/my-app/Payload
cp -R ${DERIVED_DATA_DIR}/Build/Products/Debug-iphoneos/my-appUITests-Runner.app AWS_BUILD_DIR/my-appUITests-Runner/Payload
# cp -R /var/folders/5x/kwy9lj794rs_rx98c0gy9fmr0000gn/T/tmp.VFwJCfgD/Build/Products/Debug-iphoneos/my-app.app AWS_BUILD_DIR/my-app/Payload
# cp -R /var/folders/5x/kwy9lj794rs_rx98c0gy9fmr0000gn/T/tmp.VFwJCfgD/Build/Products/Debug-iphoneos/my-appUITests-Runner.app AWS_BUILD_DIR/my-appUITests-Runner/Payload
cd AWS_BUILD_DIR/my-app
/usr/bin/zip -r my-app.ipa Payload
cd ../..
cd AWS_BUILD_DIR/my-appUITests-Runner
/usr/bin/zip -r my-appUITests-Runner.ipa Payload
cd ../..
mv AWS_BUILD_DIR/my-app/my-app.ipa .
mv AWS_BUILD_DIR/my-appUITests-runner/my-appUITests-Runner.ipa .
rm -rf AWS_BUILD_DIR
find . -name "*.ipa"
exit 0
AWS Device Farm can be used for UI testing of iOS apps.
Need to create two apps:
- APP.ipa
- APPUITests.ipa
NOTE: Should we also consider Smartphone Test Farm (STF)?
Don’t forget that * XCTest UI & XCTest are quite different.
This note pertains to UI testing which is covered by XCTest UI
.
This note also outlines the methology used to automate the build and testing using Jenkins and Fastlane.
See Jenkins job AWS_iOS_Upload_and_Run
which uploads two pre-build .ipa
files,
(my-app.ipa
& my-appUITests.ipa
)
.ipa Location
/users/ci/.jenkins/workspace/AWS_iOS_Upload_and_Run/
.ipa Structure
Analysing the two .ipa
files (Which are just ZIP files by another name) we see.
Q: The ipa files come from .app files but lack the Swift support libraries, how does AWS handle this?
TODO .ipa
/ .app
analysis
.ipa
/ .app
analysis.
.ipa
files are simply ZIP files. Contents as follows:
my-app.ipa
\payload\my-app.app
my-appUITests.ipa
\payload\my-appUITests-Runner.app
To generate
- In Xcode, Select “Generic iOS Device” as the build target
- Click Product > Build For > Testing
- Open the XCode Derived Data folder for the project, go to Build > Intermediates > Debug-iphoneos.
This contains 2 files: MyTestApp.app and MyTestAppUITests-Runner.app - Create a new directory called “Payload” on desktop
- Copy the MyTestAppUITests-Runner.app file into the Payload directory
- Right click Payload and select “Compress ‘Payload’”
- Rename the generated Payload.zip file to mytestapp-uitests.ipa
However, .app
files are actually folders which are managed as a single entity by macOS. So looking further, we have - TBS.
Createing an my-app.app
is pretty easy, we can even download from HockeyApp, my-appUITests-Runner.app
is less so. When
a Fastlane scan
is run, it uses the xcode
simulator, which creates a ‘x86’ architecture program, not ‘ARM’.
And from Stack overflow we have Building XCTest UI
tests for AWS Device Farm.
.Cf
- Derived Data ->
~/Library/Developer/Xcode/DerivedData/
The issue is in building my-appUITests-Runner.app
If we look at iOS-DevelopUITest we’ll see that the -Runner App is built in tandom with the main app.
Need to make this happen for ARM targets, not just x86.
TODO: Watch this YouTube video.