Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this scenario, we want to get visibility of the automated test results from some UI tests implemented in Robot Framework (Python) together with Selenium (using the "robotframework-seleniumlibrary"), and using Chrome for testing.

We need to setup set up a Git repository containing the code along with the configuration for GitLab build process.

...

The GitLab configuration file .gitlab-ci.yml contains yml contains the definition of the build steps, including running the automated tests and submitting the results, as two different stages.

Code Block
languagejs
title.gitlab-ci.yml
# Official language image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/python/tags/
image: python:3.12.2

# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"

# https://pip.pypa.io/en/stable/topics/caching/
cache:
  paths:
    - .cache/pip

stages:
  - execute_automated_tests
  - upload_test_results

before_script:
  - python --version ; pip --version  # For debugging
  - pip install virtualenv
  - virtualenv venv
  - source venv/bin/activate
  - pip install -r requirements.txt
  - apt-get update


test:
  stage: execute_automated_tests
  before_script: | 
    set -e
    apt-get install -yqq unzip curl
    # Install Chrome & chromedriver
    curl -sS -o - https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
    echo "deb https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
    apt update && apt install google-chrome-stable -y
    wget -O /tmp/chromedriver.zip https://storage.googleapis.com/chrome-for-testing-public/121.0.6167.85/linux64/chromedriver-linux64.zip
    ls -la /tmp/chromedriver.zip
    unzip -j /tmp/chromedriver.zip chromedriver-linux64/chromedriver -d /usr/local/bin/
    nohup python demoapp/server.py &
  script: |
    chromedriver -v && \
    pip install -r requirements.txt && \
    robot -x junit.xml -o output.xml login_tests || true
  allow_failure: true
  artifacts:
    paths:
      - output.xml
    when: always

  
upload_results_to_xray:
  stage: upload_test_results
  script:
    - echo "uploading results to Xray..."
    - 'curl -H "Content-Type: multipart/form-data" -u $XRAY_USERNAME:$XRAY_PASSWORD -F "file=@output.xml" "$XRAY_SERVER_URL/rest/raven/2.0/import/execution/robot?projectKey=$PROJECT_KEY"'
    - echo "done"
  dependencies:
  - test


n In order to submit those results, we'll just need to invoke the REST API (as detailed in in Import Execution Results - REST).However, we do not want to have the JIRA credentials hardcoded in GitLab's configuration file. Therefore, we'll use some secret variables defined in GitLab project settin

However, we do not want to have the Xray API credentials hardcoded in the GitLab's configuration file. Therefore, we'll use some environment variables defined in the project settings, including:

  • XRAY_SERVER_URL: Jira's base URL
  • XRAY_USERNAME: the username used on in the REST API
  • XRAY_PASSWORD: the password used on in the REST API
  • PROJECT_KEY: Jira project

...

Info
titlePlease note

The user associated with the Xray's API key must have permission permissions to Create Test and Test Execution Issues.



In .gitlab-ci.yml a yml a "step" must be included that will use "curl" in order to submit the results to the REST API, using the Xray/Jira credentials.

...

We're using "curl" utility that comes in Unix based OS'es but you can easily use another tool to make the HTTP request; however, "curl" is provided in the container used by GitLab.


 Image Added



Info
titleTriggering automation from Xray

If you aim to trigger automation from the Xray/Jira side, please have a look at Taking advantage of Jira Cloud built-in automation capabilities page where you can see an example of triggering a GitLab pipeline from a Test Plan and reporting results back to it.

...