Skip to content
Moataz Nabil edited this page Nov 26, 2019 · 9 revisions

Bitrise Step for Sauce Labs Integration

Sauce Labs offers the ability to run tests using a native framework such as Espresso on virtual devices using the Sauce Runner for Virtual Devices.

What is Bitrise?

Bitrise is a Continuous Integration and Delivery (CI/CD) Platform as a Service (PaaS) with the main focus on mobile app development (iOS, Android, Xamarin, …). It is a collection of tools and services to help you with the development and automation of your software projects.

Get started in 60 seconds, Bitrise help you to build your apps for any platform, After connecting your repository, Bitrise scans and configures your project for any mobile platform, be it native or hybrid, so you can start shipping your app immediately.

What is Sauce Labs?

The world's largest continuous testing cloud of web and mobile applications. Access web browsers, mobile emulators, simulators, and real mobile devices.

Sauce Labs Continuous Testing Cloud enables development and quality teams to test up to 10x faster. Sauce Labs provides the comprehensive coverage, scalability, and analytics required to rapidly deliver a flawless user experience.

Create Sauce Labs Free (Trial) Account

You can create your trial account from this link:

https://saucelabs.com/sign-up

The Free trial account includes:

Start testing today on thousands of browser/OS platform combinations, EMU/SIM and real Android and iOS devices.

  • Instant access to 900+ desktop browser & OS combos
  • Instant access to 200+ mobile emulators & simulators100 minutes of automated testing
  • Instant access to real mobile devices
  • 1 session on the Real Device Cloud
  • 2 concurrent sessions on the Virtual Device Cloud
  • 100 minutes of automated testing

The purpose of the integration between Bitrise and SauceLabs

If you are writing mobile test automation scripts for your Android app using the native tool Espresso and you need to run your tests with different OS and versions on different simulators with Bitrise, So you need to think about how can I run these tests, if you start thinking about implementing your device lab it will be a headache and will not give the value that you looking for, So you need to think about alternate solution that supports you with different devices, OS and versions. one of these solutions is SauceLabs

Sauce Labs offers the ability to run tests using a native framework such as Espresso on virtual devices using the Sauce Runner for Virtual Devices.

Note:

Sauce Runner is now supporting only Espresso and Virtual Devices.

Before implementing this step to use SauceLab Runner you need to create your custom scripts to download the runner zipped file, unzip it and running the command using a shell script. But with the step, all that you need is to add the step in your workflow and select your preferred device.

The Installation Steps:

  1. Go to https://app.bitrise.io/users/sign_up, you can signup with Github, Gitlab or Bitbucket
  2. The dashboard will be displayed after login and you can start building your first app
  3. Click on Add your first app button
  4. Select your account and set the privacy for the App (Private or Public) and click Next
  5. Choose the repository name but before that, you have to give Bitrise access rights to your source code provider.
  6. After connected successfully, your repositories will be displayed and you can select which project you need to integrate with Bitrise
  7. You need to Setup repository access you can click on auto-add SSH key
  8. Choose Branch name (for ex: master branch) and click Next
  9. Once we click Next, Bitrise will start to validate the repository and fetch the type of project
  10. After validating the Project build configuration will be displayed successfully (In my case the repository is Android App)
  11. You just need to confirm that the configuration is correct by click on Confirm button or if you want to change anything you can click on Edit button (for example change the Android Stack to another version)
  12. The final step is Webhook setup, we just need to click on Register a Webhook for me! button
  13. Finally, one more click on We've kicked off your first test build for you!
  14. After that, the build will start, you can see the log for each step in the workflow
  15. In the end, you will find a summary of all the tasks that you run during the build with time, title and also you can download logs or check the Apps and artifacts

Now it's time to change the workflow by removing the Android lint step and add 2 steps for Instrumentation tests using Espresso and SauceLabs

  1. Click on Open Workflow Editor button (Also you can check the bitrise.yml file)
  2. Click on Android lint step and I will click on Delete Step button
  3. You can click CTRL + S to save the changes or you can click on Save button above the Workflow (if you create one step by mistake before saving you can discard the changes)
  4. Between Android Unit Test Step and Deploy Step I will add a new step for UI testing, Click on + button and a right side menu will be displayed with a different type of steps and configuration
  5. In the search textbox we will type UI and from the search result will click on Android Build for UI Testing (this step to build the Test apk from our espresso test cases and added it in the correct path)
  6. We will need to add two values only Module = app and Variant = debug and click the Save button
  7. After this step, we will need to add a new one to run the test on a virtual device on SauceLabs
  8. Click on + again and search about SauceLabs and click Add
  9. We need to configure the step now with the following values:
  • SauceLabs username: you need to add a new Secret Environment Variable (SAUCELABS_USERNAME) in the Secrets tab and add your SauceLabs username.
  • SauceLabs Access Key: you need to add a new Secret Environment Variable (SAUCELABS_ACCESS_KEY) in the Secrets tab and add your SauceLabs access key.
  • In Test Automation Options:
  • Device Name: Google Pixel GoogleAPI Emulator,platformVersion=7.0
  • SauceLabs Data Center: eu-central-1

Our pipeline is ready now run our build, Go back to the project and click on Start/Schedule a Build, then click on Start build

Note: In this screen also you can schedule your build at any day or time to be like nightly, build, just allow the feature and change the settings

You will notice in the log screen during the build steps for assembling the app and the test app like this one:

Run build:

$/bitrise/src/gradlew ":app:assembleDebug" ":app:assembleDebugAndroidTest"

After the build finished successfully you can navigate to the SauceLabs and check the UI tests with logs, videos, and detailed information. By default, you will get a notification by email from Bitrise about the build status.

Upcoming feature

  • Include/Exclude Tests
  • Run-on multiple devices
  • Run with Sauce Labs tunnel