This repository is an example of how you can utilize AWS Device Farm for testing your React Native applications. We can take advantage of Appium and WebdriverIO to run our tests against our application on emulator/simulators and physical devices.
It also includes a short description how to use this kind of testing as part of your CI/CD pipeline.
Clone the repository and npm install. Verify you can run the application through React Native.
Once you are able to run the application your React Native CLI, you are now ready to install Appium.
This repository uses the following versions:
-
Appium 1.18.3
-
React Native 63.3
-
React 16.13.1
-
XCode 12.0.1
To test locally you will need the Appium server running. You can either use the Appium CLI or Appium Desktop App.
To use the CLI:
npm install -g appium@1.18.3 && appium
This will start a basic Appium server. You can see more about the CLI here http://appium.io/docs/en/writing-running-appium/server-args/
You will also want to install appium-doctor to ensure your environment is setup to use Appium correctly:
npm install -g appium-doctor
See more information here: https://github.com/appium/appium-doctor
To build the Android APK, we can use the Gradle build script in the android folder:
cd android && ./gradlew assembleRelease
The APK should be located at android/app/build/outputs/apk/release/app-release.apk.
To build the iOS .app file for a simulator device, open the RNDeviceFarm.xcodeproj file in the ios directory.
Now, select the iOS simulator you wish to build for and then go to Product -> Scheme -> Manage Schemes. Update the scheme Build Configuration to Release in the Run tab. This will build our application in production mode.
Finally, click Product -> Clean and Product -> Build. This will create a .app file in your XCode build output directory. The default should be ~/Library/Developer/Xcode/DerivedData/. Once your app builds and you have verified the .app file exists, you are ready to test on the simulator locally.
If you have problems building the iOS app for the simulator on XCode 12 (Error: building for iOS Simulator, but linking in object file built for iOS, for architecture arm64
) please check out this link.
To run the tests locally using Appium, you will need an APK for Android or a .app file for the iOS simulator.
cd e2e && npm install
This will install the WebdriverIO and dependencies we need to test.
You can edit the wdio.*.local.conf.js files for local testing (update app location, change simulator, ...).
Once you are ready to test, start the Appium server, start the emulator/simulator, and run the desired test.
Android:
npm run test:android:local
iOS
npm run test:ios:local
To deploy to Device Farm, simply run the package script to generate the zip file needed.
npm run package
In the AWS console, start a new run in Device Farm, upload the APK or IPA (not .app file) and use the zip file for your test package.
For the Appium YAML configuration, use either the appium.android.yml file or the appium.ios.yml file.
When working with CLI tools like Bitrise, you have to know the ARNs of you project, device pool and test configuration.
To get this ANRs you have to work with the AWS CLI, which is pretty easy to understand.
You can find a detailed instruction about installing the AWS CLI here: https://aws.amazon.com/de/cli/.
After installing the CLI you have to configure your credentials for connecting to AWS device farm (you can create your AWS Access Key in AWS IAM).
aws configure
Get all information about your projects (including ANRs)
aws devicefarm list-projects
Get all information about your device pools (including ANRs)
aws devicefarm list-device-pools
Get all information about all your uploads (including test configurations and ANRs)
aws devicefarm list-uploads
Bitrise provides predefined steps for uploading and running tests.
Upload tests
Amazon Device Farm File Deploy
Please note that you have to upload your tests during the "File Deploy" step, not your app bundle.
Run tests
Amazon Device Farm Runner
Now you can upload your app bundle.
This repo is based on the awesome work of Nicolas Ames. You can find the original repository here.