Set up your Appium Android Tests with Bitrise CI
Who should read this article?
Test automation integration with CI tools is what every fast-paced team wants these days. So, those who have already done with their automation of mobile apps using appium, they can integrate their test suites with Bitrise CI. I also believe that you can follow similar steps with other CI tools like Jenkins, Bamboo etc to create a smooth pipeline.I hope this will be helpful to reduce the pain of on-demand execution for your tests.
The best part about Bitrise is the way it is being designed, especially for mobile platforms. Also, it makes your life easy when it comes to the integration of your automation suites. It includes many such steps that will help us to create a complete End 2 End pipeline such as Android SDK Updates, Create & Launch Android emulators (subject to the availability on Bitrise stack).
This post is not promoting Bitrise, it’s just about choices since we were using Bitrise already to build our iOS, Android and React-Native apps. So the challenge was to add our automation test suites on top of our mobile build plans.
Before I start, I would like to highlight about the setup which we have on our Bitrise server. At the moment we have an android build plan that will generate a .apk file. So, we are going to create another plan on the same stack in which our .apk file is being generated.
Step 1: Clone your automation project
The very step I’m performing here is cloning my automation project to the Bitrise source directory. So use
Git Clone Repository step to clone your project. But before that, make sure you add an
Activate SSH key step. With this, you will be able to connect to GitHub without supplying your username or password.
Please don’t be confused with
Delete previous Repository step. Since I’m already in a directory where the Android project was cloned previously so I’m simply deleting that repository and cloning the automation project in order to avoid any conflicts while cloning.
You simply need to mention
Git repo URL of your project and the destination where you want to clone.
Step 2: Android SDK Update
Once you successfully clone your project, the next step would be to update Android SDK packages. Since this step is based on the images available on Bitrise stack so please check your tech stack for versions related to build-tools, platform-tools, and platform version. Here, I’m going with
API level 26 as I believe this is one of the stable versions available at the moment on Bitrise.
Step 3: Create Android Emulator
Now that we have our project with us and updated Android SDK as per our choice, let’s go ahead and add one of the important steps in our build plan i.e. “
Create Emulator”. Here, you have to mention emulator details like name, platform version (very important), ABI to be used. Apart from that, you can also mention custom hardware configuration for your emulator.
This is what you can mention in your custom hardware configuration or can be kept empty, all depends on your requirement.
Step 4: Start your Android Emulator
The next would be definitely to start your created emulator. So, let's go ahead and add “
Start Android Emulator” step. This will help us to start the newly created emulator and wait till it’s completely booted. Because it’s important that our emulator should be in the active state when we start running our test.
“Create Emulator” step will return Emulator name as
$BITRISE_EMULATOR_NAME. We will be using this as the name of the emulator which needs to be started & booted. You can also mention emulator skin in case you are specific with the size. Here I’ve set this to
1080X1920. Additionally, you can add emulator flags such as
“-no-boot-anim -no-window -no-audio” that will help to boot emulator faster to some extent. At last, you can mention the timeout for the emulator.
Step 5: Install & Start Appium Server
By now, we have almost reached the final stage of the build plan where it’s time to install and run appium server. In case you are starting appium server programmatically using
AppiumServiceBuilder then it’s not necessary to start, you can simply install it. Since Bitrise doesn’t have a pre-defined appium step, we are going to use “
Script” step and add a small script to install. I guess scripts are very powerful and can be used where you run out of options. So, here is what we need to write in a script step.
“npm install -g appium —-unsafe-perm=true --allow-root
appium &>/dev/null &”
Step 6: Run your Appium Test
Finally, you reached the moment where you can see your code running on a CI tool. I’m sure this will give you immense pleasure to see your test script and Bitrise dating each other. So, quickly we will add another script step to run our automation project. My automation project is of maven type and we can easily trigger this by simply adding a maven command and that’s it.
In case you face any issues while running a maven command, then you can install maven as well by adding another simple script.
mvn clean test “-DargLine=-Dplatform=android”
Step 7: Deploy to Bitrise.io
Well, this step is optional, But if we want to attach our test reports/artifacts then this step will help you to do that. This will be helpful for you as well as for your team when you see execution reports, failure screenshots after the tests are finished. You just have to give the path to your report folder rest all will be taken care by bitrise. Once the execution is done it will attach all your reports under the artifact section of the build.
Send a Slack Message (Optional)
Let your team know that your execution is done and reports are ready. If you are using slack as a communication channel in your organization then sending a slack notification will be a nice addon.
At the end...
I hope this will be helpful to you. In case if anyone has done a better implementation please help to improve this article by adding your comments.