Utilizing GitLab Runner and Pipeline for Mobile Test Automation

Yogi is ariyanto
4 min readOct 8, 2023

--

The first time I heard about it was approximately three years ago at my previous company. It was amazing when I learned about GitLab Runner. I liked it because it felt like magic. Why? Because our MacBook or PC can be controlled, and tasks can be executed through GitLab. This allows for the automation of various types of tasks on our MacBook. Isn’t that interesting?

Image Source: https://gitlab.com/uploads/-/system/project/avatar/15677351/runner_logo.png

Let’s consider implementing GitLab Runner in our mobile automation script.

Let’s first introduce what it’s GitLab Runner.

What is GitLab Runner?

GitLab Runner is an application that works with GitLab CI/CD to run jobs in a pipeline.

There are two different ways to run GitLab Runner:

  1. Use GitLab.com SaaS runners:
    This means using a runner hosted by GitLab as a cloud-based service. GitLab fully manages this runner, and it seamlessly integrates with the GitLab.com platform.
  2. Use self-managed runners:
    This means using a runner that you install and manage yourself, independently of GitLab’s hosting. You can configure and control this runner according to your specific requirements.

I am here to explain the implementation of self-managed GitLab Runners on your MacBook for executing mobile automation testing scripts.

Install GitLab Runner on macOS

Let’s start first, you can download the binary for your system according to your local host. I am using a MacBook with Apple Silicon, so I will use this one:

sudo curl - output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-arm64"

Don’t forget to grant permission. otherwise, your GitLab Runner won’t be able to execute.

Give it permissions to execute:

sudo chmod +x /usr/local/bin/gitlab-runne

Oh, by the way, here you will see the directory of the GitLab Runner that will be used to store the runner configuration you have created.

Currently, the config.toml file does not exist, it will be created automatically when you register your first runner on your MacBook.

Registering runners

Then, after GitLab Runner is installed on your MacBook, you can create your own runner by following the steps shown in the following image:

The first step, Select Settings > CI/CD -> Expand the Runners section -> Select New project runner

The second step, Select your operating system -> In the Tags section, I'm using the tag "macbook-yogi", You also have the option to select the “Run untagged” checkbox here. For a clearer understanding of the difference between “Run untagged” and “Run only tagged” you can read more here.

In the third step, register the runner on your MacBook.

Here, the config.toml file is automatically generated and stores the runner configuration you have created.

GitLab Runner provides various executors to execute your builds in diverse environments. These include::

Here, I am using the Shell executor because it is a straightforward executor used to run builds locally on the machine where GitLab Runner is installed.

Here, your runner is not online yet, so you need to verify your runner locally by running the command gitlab-runner run.

After successfully verifying your runner, it will be in an online state.

Integration with Mobile Test Automation

Here is a simple pipeline I have created to run mobile test automation:

default:
tags:
- macbook-yogi

stages:
- test

before_script:
- echo "Ready Test...."
- npm install
- adb devices

automation-test:
stage: test
script:
- npm test
only:
- /^te-test-/

And i am using WebDriverIO here, and below is a simple script that I have created. You can view the details at the following link here

Please make sure that your local environment has all the necessary tools installed for mobile test automation, with everything set up, let’s proceed and execute it. I’ll demonstrate it in this video, please take a look.

References

--

--