Continuous integration with Gitlab

Estimated reading time: 4 minutes

About the Author

Ahmed Hussein Karam, Software Engineer

Contact Ahmed at https://www.linkedin.com/in/ahmed-hussein-86b147153/

Introduction

When you make changes to your project source code, you definitely need to run Katalon tests again to make sure that changes are correct. But you may find it boring to run them every now and then, with a possibility to forget to do that. Here, Continuous Integration becomes very important, as it allows you to automate the Change-Then-Test process.

This tutorial walks through the steps needed to automatically run your Katalon test suites when you push any change on your Gitlab repository.

Requirements

  • You have a Gitlab account and you already put your web app in a Git repository. You can download this sample php application to be able to go through.
  • You have a web server hosting your application (e.g. XAMPP Apache Server).
  • You have Katalon Studio installed and you have created a test suite with one or more test cases.
  • This tutorial is limited to Windows. But you may perform similar steps on other platforms.

Register and install Gitlab runner

Download Gitlab runner for x86 or amd64, then follow the steps in the following video:

Note: we added the tag “shell” in order to run test cases on the local machine. However, you can add other tags like docker and ssh.

Add a configuration file to your repository

In the root directory of your repository, add file named .gitlab-ci.yml. Open the file and type the following:

run_katalon_test_suite:
      tags:
        - shell
      script:
        - katalon -noSplash  -runMode=console -consoleLog -projectPath=
          "<Your_Project_Directory>" -retry=0
          -testSuitePath="Test Suites/<Test_Suite_Name>" -executionProfile=
          "default" -browserType="Chrome (headless)"

Note: typically, your default project directory is _“C:\Users\\\Katalon Studio\\<PROJECT\_NAME>\\<PROJECT\_NAME>.prj"_

If you want to start your web server automatically before running test cases, add a command at the beginning of the configuration file. For example, to open XAMPP apache server, add this command at the beginning of the file:

before_script:
      - start /B cmd /K "<Path_To_HTTPD_Executable>"

Note: typically, the default httpd.exe file location in XAMPP is “C:\xampp\apache\bin\httpd.exe”

If you want to stop your web server after executing test cases, add a command at the end of your script. For XAMPP apache server, the command is “taskkill /F /IM httpd.exe”. So, the final file should look like this:

before_script:
      - start /B cmd /K "<Path_To_HTTPD_Executable>"

    run_katalon_test_suite:
      tags:
        - shell
      script:
        - katalon -noSplash  -runMode=console -consoleLog -projectPath=
          "<Your_Project_Directory>" -retry=0
          -testSuitePath="Test Suites/<Test_Suite_Name>" -executionProfile=
          "default" -browserType="Chrome (headless)"
        - taskkill /F /IM httpd.exe

Add Katalon path to environment variables

  • Go to Control Panel > System and Security > System
  • Click on “Advanced system settings” on the left pane

Add Katalon Path

  • Choose “Advanced” tab and click “Environment Variables…”

Katalon Environment Variables

  • In “System variables” section, choose the variable “Path” and click “Edit…”

Katalon System variables

  • In the “variable value” field add ; then the directory of Katalon Studio

Katalon Edit System Variables

Note: the first 3 steps are needed only once.

Make changes and test

After saving some changes, push them to your git repository. After that, open the repository > CI/CD > Pipelines

gitlab changes and test

  • You can see one of the following marks in your pipeline:

pipeline

Now, click on the job link.

Run Katalon Test Suite

  • See testing results (you may need to wait some time to see results)

Katalon Testing Results

Note: you can see an error like this:

Katalon Error run test

If you see it, run the command below from your local git repository and try again.

git config --system http.sslverify false

Conclusion

Once you have Katalon test cases prepared, you only need to focus on updating your project. You will no longer need to repeatedly go and run test cases manually after each update, because this process is already automated. You are just informed whether your commits are successful or not. However, you can still find detailed testing reports in the Reports folder that is located in your Katalon Studio project root directory. The development and testing processes can be summarized in the following diagram:

Development and testing processes