使用 Xray、Robot Framework 和 GitLab 进行自动化测试:如何开始?

问题描述 投票:0回答:1

我希望使用 Xray、Robot Framework With python 和 GitLab 对我的项目进行自动化测试,但我不确定如何继续。有人可以提供有关如何设置自动化工作流程的指导吗?

了解如何使用此工具进行自动化测试

testing gitlab robotframework cicd jira-xray
1个回答
0
投票

假设您采用 ATDD,总体流程将是这样的:

如果您在 Jira Datacenter 上使用 Xray,您可以在此处查看详细教程,其中展示了在 Robot Framework 中实现的一些自动化测试,以及与 Xray 的集成;有一个 GibHub 存储库,其中包含使用的示例代码

因此,专注于本质,您会:

  • 编写您的机器人框架测试
  • 像往常一样在 RF 中执行测试(例如,
    robot ...
    ),这将生成并输出.xml 报告
  • 使用 Xray 的 REST API 将该报告提交给 Xray;有特定的端点来处理 RF output.xml 类型的报告;如果您在 Jira Datacenter 上使用 Xray,请参阅this;如果您在 Jira Cloud 上使用 Xray,请参阅 this

举个例子,要将 RF 报告提交到 Jira Datacenter 上的 Xray,您可以使用类似的方法发出 POST 请求(假设您有

curl
工具):

curl -H "Content-Type: multipart/form-data" -u someuser:somepass -F "[email protected]" "http://192.168.56.102/rest/raven/2.0/import/execution/robot?projectKey=CALC

如果您在 Jira Cloud 上使用 Xray,有一个类似的教程

要在 Gitlab 上进行设置,您应该在存储库中创建一个

.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 http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip 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: | google-chrome --version && \ 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 "[email protected]" "$XRAY_SERVER_URL/rest/raven/2.0/import/execution/robot?projectKey=$PROJECT_KEY"' - echo "done" dependencies: - test
不要忘记在 GitLab UI 的 Pipeline 区域下的 GitLab CI/CD 配置上添加环境变量。

当您手动或通过提交运行此工作流时,工作流程将在 Gitlab 上运行,您可以在其中看到有关在 Xray 上创建的测试执行问题的信息;在屏幕截图中显示“CALC-408”。

如果您转到 Jira/Xray 实例,您将能够看到新的测试执行以及结果。

注意:Xray 可能支持 RF 最高版本 6.x;不是最新的 RF 7.0。

================================================

如果您使用 CircleCI 作为 CI/CD 工具,该过程将非常相似;我将在最初使用 CircleCI 实现它时分享它,为您准备答案。

要在 CircleCI 上进行设置,您应该在存储库中创建一个

.circleci/config.yml

 文件,并添加类似以下内容的内容(不要忘记在 CircleCI 项目配置中创建一些环境变量):

# Use the latest 2.1 version of CircleCI pipeline process engine. # See: https://circleci.com/docs/configuration-reference # For a detailed guide to building and testing with Python, read the docs: # https://circleci.com/docs/language-python/ for more details version: 2.1 # Orbs are reusable packages of CircleCI configuration that you may share across projects, enabling you to create encapsulated, parameterized commands, jobs, and executors that can be used across multiple projects. # See: https://circleci.com/docs/orb-intro/ orbs: # See the Python orb documentation here: https://circleci.com/developer/orbs/orb/circleci/python python: circleci/[email protected] browser-tools: circleci/[email protected] # Define a job to be invoked later in a workflow. # See: https://circleci.com/docs/jobs-steps/#jobs-overview & https://circleci.com/docs/configuration-reference/#jobs jobs: build-and-test: # Specify the execution environment. You can specify an image from Docker Hub or use one of our convenience images from CircleCI's Developer Hub. # See: https://circleci.com/docs/executor-intro/ & https://circleci.com/docs/configuration-reference/#executor-job docker: # Specify the version you desire here # See:https://circleci.com/developer/images/image/cimg/python - image: cimg/python:3.12-browsers # Add steps to the job # See: https://circleci.com/docs/jobs-steps/#steps-overview & https://circleci.com/docs/configuration-reference/#steps steps: # Checkout the code as the first step. - checkout - python/install-packages: pkg-manager: pip # app-dir: ~/project/package-directory/ # If your requirements.txt isn't in the root directory. # pip-dependency-file: test-requirements.txt # if you have a different name for your requirements file, maybe one that combines your runtime and test requirements. # get server up and running in the background - run: name: Run webserver to be target by tests command: python demoapp/server.py background: true - run: name: Run tests # This assumes Robot Framework is installed via the install-package step above command: robot -x junit.xml -o output.xml login_tests || true - run: name: Upload results to Xray DC command: | echo uploading RF output.xml, if available, to Xray... [ -f output.xml ] && curl -H "Content-Type: multipart/form-data" -u $XRAY_USERNAME:$XRAY_PASSWORD -F "[email protected]" "$XRAY_SERVER_URL/rest/raven/2.0/import/execution/robot?projectKey=$PROJECT_KEY" - store_test_results: path: junit.xml when: always # Orchestrate jobs using workflows # See: https://circleci.com/docs/workflows/ & https://circleci.com/docs/configuration-reference/#workflows workflows: sample: # This is the name of the workflow, feel free to change it to better match your workflow. # Inside the workflow, you define the jobs you want to run. jobs: - build-and-test
当您运行此命令时,无论是手动还是通过提交,工作流程将在 CircleCI 上运行,您可以在其中看到有关在 Xray 上创建的测试执行问题的信息;在屏幕截图中,它显示“CALC-395”,即使 CircleCI 编辑了项目密钥(即“CALC”)。

如果您转到 Jira/Xray 实例,您将能够看到新的测试执行以及结果。

© www.soinside.com 2019 - 2024. All rights reserved.