Make a Test Build to use with Appium
Prepare a build for Appium with Fastlane or xcodebuild
by
Lou Franco
When you make GUI tests using XCUI directly in Xcode, it will automatically build the app for you when you run the test. Appium, however, is run completely outside of Xcode, so you must supply a build for it. The best way is to build from the command-line so that can control where the files end up.
Making a test build with Fastlane
If you use fastlane, a lane like this will make a test build and put it into a folder you specify.
This is how you build for use in a simulator
desc "Build the app for Appium GUI testing in a simulator"
lane :build_for_gui_testing_sim do
scan(
build_for_testing: true,
derived_data_path: "test-app-sim"
)
end
This is how you build for use on a device
desc "Build the app for Appium GUI testing on a device"
lane :build_for_gui_testing_device do
scan(
build_for_testing: true,
derived_data_path: "test-app-device",
sdk: 'iphoneos',
destination: 'generic/platform=iOS'
)
end
With those lanes, you can build a test app with either
bundle exec fastlane build_for_gui_testing_sim
or
bundle exec fastlane build_for_gui_testing_device
Depending on how you want to test.
Making a test build with xcodebuild
Fastlane just ultimately calls xcodebuild
to build, but if you want to do it directly yourself, the important parts are:
- Pass in the parameter
-derivedDataPath
with the path to store the build - Pass in a
-destination
, either'generic/platform=iOS Simulator'
for a simulator or'generic/platform=iOS'
for a device - Pass in a
-sdk
, eitheriphonesimulator
for a simulator oriphoneos
for a device. - Use the
xcodebuild
commandbuild-for-testing
For example, I have a project file called EventOMat.xcodeproj
with the app scheme EventOMat
, so I can build for simulator testing with:
xcodebuild -project EventOMat.xcodeproj -scheme EventOMat -derivedDataPath test-app-sim -destination 'generic/platform=iOS Simulator' -sdk iphonesimulator build-for-testing
And for device testing with:
xcodebuild -project EventOMat.xcodeproj -scheme EventOMat -derivedDataPath test-app-device -destination 'generic/platform=iOS' -sdk iphoneos build-for-testing
Your exact command depends on whether you use a workspace or project file and the exact names. One nice thing about fastlane
is that it can figure that all out for you and call xcodebuild
correctly.