如何在GitLab上运行Python + Selenium自动化测试?

4

是否可以在GitLab中运行使用Python + Selenium编写的自动化测试?我在互联网上找不到相关信息。我知道有Jenkins,但我想在GitLab中运行自动化测试,然后生成Allure报告(如果可能的话)。

1个回答

4

在GitLab中使用Python + Selenium编写的自动化测试是可行的吗?

有几种/种类型的gitlab-runner executors可以实现这一点: dockerdocker-composeshell

下面是使用docker gitlab-runner executor的示例:

.gitlab-ci.yml

image: python:3.7.9-alpine
stages:
  - test

e2e:chrome:
  services:
    - selenium/standalone-chrome  # it's need to be configured with Remote webdriver in your tests to look at http://selenium__standalone-chrome:4444/wd/hub
  before_script:
    - pip3 install -r requirements.txt  # you can optimize this step by building your own image with pre-installled requirements and using it instead of current python:3.7.9-alpine image 
  script:
    - pytest /path/to/your/tests 
  

这是一个可行的示例,演示了如何使用gitlab-ci执行Python中的Selenium测试。
简单完整示例请查看标记为1.0.0的内容:https://github.com/aleksandr-kotlyar/python-gitlabci-selenium/releases/tag/1.0.0 更复杂的多浏览器示例,请查看标记为2.0.0的内容:https://github.com/aleksandr-kotlyar/python-gitlabci-selenium/releases/tag/2.0.0 本地Docker示例请查看标记为2.1.0的内容:https://github.com/aleksandr-kotlyar/python-gitlabci-selenium/releases/tag/2.1.0 免责声明:我开发了Python-Gitlab-CI和另一个针对新手的Python-CI模板,所以我将感谢您在我的项目https://github.com/aleksandr-kotlyar/python-gitlabci-selenium/中提供反馈和请求。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接