Page History
...
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.
Robot Framework example
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.ym
l contains yml
contains the definition of the build steps, including running the automated tests and submitting the results, as two different stages.
Code Block | ||||
---|---|---|---|---|
| ||||
# 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..." export token=$(- 'curl -H "Content-Type: applicationmultipart/jsonform-data" -X POSTu $XRAY_USERNAME:$XRAY_PASSWORD --dataF "{ \"client_id\": \"$client_id\",\"client_secret\": \"$client_secret\" }" https://xray.cloud.getxray.app/api/v2/authenticate| tr -d '"')file=@output.xml" "$XRAY_SERVER_URL/rest/raven/2.0/import/execution/robot?projectKey=$PROJECT_KEY"' curl- -Hecho "Content-Type: text/xml" -H "Authorization: Bearer $token" -F "file=@output.xml" "https://xray.cloud.getxray.app/api/v2/import/execution/junit?projectKey=$project_key" dependencies: "done" dependencies: - test |
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 Xray API credentials hardcoded in the GitLab's configuration file. Therefore, we'll use some environment variables defined in the project settings, including:
- clientXRAY_SERVER_id: the client_id associated with the API key created in the Xray cloud instance
- client_secret: the client_secret associated with the API key created in the Xray cloud instance
- project_key: the client_secret associated with the API key created in the Xray cloud instance
- URL: Jira's base URL
- XRAY_USERNAME: the username used in the REST API
- XRAY_PASSWORD: the password used in the REST API
- PROJECT_KEY: Jira project
Infoinfo | ||
---|---|---|
| ||
The user associated with the Xray's API key must have permission permissions to Create Test and Test Execution Issues. |
In .gitlab-ci.ym
lyml
a "step" must be included that will use "curl" in order to first obtain a token and then finally submit the results to the REST API, using that token.
...
the Xray/Jira credentials.
curl -H "Content-Type: textmultipart/xmlform-data" -H "Authorization: Bearer $token" -f "outputu $XRAY_USERNAME:$XRAY_PASSWORD -F "file=@output.xml" "https://xray.cloud.getxray.app/api/v2"$XRAY_SERVER_URL/rest/raven/2.0/import/execution/junitrobot?projectKey=$project$PROJECT_jetKEY"
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.
Info | ||
---|---|---|
| ||
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. |
...