Skip to main content
Skip table of contents

GitLab

GitLab CI/CD is a software development tool that allows organizations to implement “continuous” methodologies.

In this document, we will show you how to integrate AgileTest with it.

Firstly, you need to acquire Client id and Client secret from AgileTest. Please refer to this document for more details Access API documentation.

Make sure your account has permission to create TestCase and TestExecution issues; otherwise, the import will fail.

Setup with Gitlab

In your Gitlab repository, go to Settings →  CI/CDVariables, and add the variables as follows CLIENT_ID, CLIENT_SECRET, and PROJECT_KEY.

image (67).png

Variables screen

Ensure you untick the Project Variable option for all created variables. Otherwise, you won't be able to access them in the YAML file.

Screen Shot 2025-01-13 at 17.30.29.png

Edit variable

Upload test result

Here's a JUnit report example for you to experiment with:

JUnit report example
XML
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite tests="15" failures="0" name="ut.com.xpandit.raven.service.impl.IssueDataSetTest" time="0.163" errors="0" skipped="0">
  <properties>
    ...
  </properties>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidLimitOverflowOption_returnsExpectedSubset" time="0.114"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withNullOptionsAndValidIssue_throwsIllegalArgumentException" time="0.002"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidEmptyOptions_returnsAllIssues" time="0.002"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidGlobalSearchOptions_returnsExpectedTests" time="0.016"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndInvalidColumnSearchOption_returnsAllTests" time="0.007"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidLimitUnderOption_returnsExpectedSubset" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidGlobalSearchOptionThatMachesIssueKey_returnsExpectedTestWithMatchedKey" time="0.006"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidSummaryColumnAscSortOption_returnsExpectedIssuesInAscOrder" time="0.006"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidSummaryColumnDescSortOption_returnsExpectedIssuesInDescOrder" time="0.002"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidGlobalSearchOptionThatMatchesAllElements_returnsAllTests" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidColumnSearchOptionThatMatchesOneElement_returnsOneTest" time="0.002"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidColumnSearchOptionThatMatchesNoIssue_returnsEmptyList" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidGlobalSearchOptionThatMachesNoIssue_returnsEmptyList" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidKeyColumnDescSortOption_returnsExpectedIssuesInDescOrder" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidKeyColumnAscSortOption_returnsExpectedIssuesInAscOrder" time="0.001"/>
</testsuite>

If you need more detailed examples, please refer to our public repository on AgileTest GitHub for other sample projects.

Use API

Below is a sample .gitlab-ci.yml file.

BASH
stages:
  - test

tests:
  stage: test
  image: mcr.microsoft.com/playwright:v1.42.1-jammy
  script:
    - npm ci
    - npm run test
    - export token=$(curl 'https://agiletest.atlas.devsamurai.com/api/apikeys/authenticate' -X POST -H 'Content-Type:application/json' --data '{"clientId":"'"$CLIENT_ID"'","clientSecret":"'"$CLIENT_SECRET"'"}' | tr -d '"')
    - echo $token
    - curl 'https://api.agiletest.app/ds/test-executions/junit?projectKey=$PROJECT_KEY' -X POST -H 'Content-Type:application/xml' -H 'Authorization:JWT $token' --data @results.xml
    - echo "done"

In this file, we use 2 endpoints:

  • api/v1/apikeys/authenticate to get temporary token using acquired client_id and client_secret.

  • ds/test-executions/nunit to submit test report to Agile Test so that the application could create or Test execution and Test cases accordingly.

To learn more about these endpoints, please refer to this document API document.

Use AgileTest CLI

YAML
# You can override the included template(s) by including variable overrides
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
# Note that environment variables can be set in several places
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
stages:
  - test
  - upload-report

tests:
  stage: test
  image: mcr.microsoft.com/playwright:v1.42.1-jammy
  script:
    - npm ci
    - npm run test
  artifacts:
    name: test_result
    paths:
      - playwright-report/results.xml
upload-report:
  stage: upload-report
  image:
    name: ghcr.io/agiletestapp/agiletest-cli:latest
    entrypoint: [""]
  script:
    - |
      agiletest --client-id ${CLIENT_ID} --client-secret ${CLIENT_SECRET} \
              test-execution import \
              --framework-type junit --project-key ${PROJECT_KEY} \
              playwright-report/results.xml

In this .gitlab-ci.yml file, we have 2 jobs named tests and upload-report. Each of them is associated in a different stage and run in a container of different docker image.

In tests job, we run the automation test scripts and the process yields the reports. Then the report is uploaded to Gitlab artifact with the name test_result. By default, all artifacts of jobs belonging to a prior stage are downloaded automatically in the next stage. As a result, in upload-report, we use AgileTest command as below to upload it onto AgileTest.

BASH
agiletest --client-id ${CLIENT_ID} --client-secret ${CLIENT_SECRET} \
              test-execution import \
              --framework-type junit --project-key ${PROJECT_KEY} \
              playwright-report/results.xml

For each test run, a new Test Execution will be created along with linked Test Cases. However, if the Test Cases already exist in your project, Agile Test will only generate a new Test Execution and link the matching Test Cases to it, including the test results


Should you need any assistance or further AgileTest inquiries, contact here!

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.