通过Jenkins CI在Docker容器中运行Seleniumtesting的最简单的方法

我想执行我的自动化testing,在Nightwatch-Cucumber上用Docker容器中的Jenkins CI编写。 我有一个我想用它的Docker镜像。

这是我想要更详细地做的。

  1. 开始Jenkins CI工作的testing
  2. 在同一台机器上加载Docker镜像,并启动相关的Docker容器。 这个容器基于Unix操作系统。 此外,Docker容器中的一些configuration将被执行。
  3. testing将通过xvfb在无头模式下执行(从本地或远程),报告将保存在Jenkins机器上。

在GitLab CI上我已经通过.gitlab-ci.ymlconfiguration文件实现了它,它运行得非常好:

 image: "my-docker-image" stages: - "chrome-tests" before_script: - "apt-get update" - "apt-get install -y wget bzip2" - "npm install" cache: paths: - node_modules/ run-tests-on-chrome: stage: "chrome-tests" script: - "whereis xvfb-run" - "xvfb-run --server-args='-screen 0 1600x1200x24' npm run test-chrome" 

但我想要与Jenkins CI实现相同的过程。 什么是最简单的方法来执行它,并在由Jenkins调用的Docker镜像中运行我的自动化testing? 我应该写一个Dockerfile或不或或或?

我目前正在运行用PHP编写的Selenium Test脚本,并使用Docker Compose通过Jenkins运行它们。 你也可以做同样的事情,而不需要自己处理Xvfb的麻烦。

要使用Docker容器内的无头浏览器运行Seleniumtesting,并使用docker-compose将其链接到应用程序,可以简单地使用预定义的独立服务器。

https://github.com/SeleniumHQ/docker-selenium

我目前正在使用Chrome Standalone图片。

以下是你的docker-compose应该是这样的:

 version: '3' services: your-app: build: context: . dockerfile: Dockerfile your_selenium_application: build: context: . dockerfile: Dockerfile.selenium.test depends_on: - chrome-server - your-app chrome-server: image: selenium/standalone-chrome:3.4.0-einsteinium 

在运行docker-compose时,它将启动您的应用程序,将与您的应用程序交互的selenium环境以及为您提供无头浏览器的独立服务器。 因为它们是链接的,所以在你的selenium代码中,你可以通过your-app:80来向你的主机发送testing请求。 你的无头浏览器将是chrome-server:4444 / wd / hub这是默认地址。

这一切都可以在Jenkins内部使用一个命令在你的Jenkins Job的Execute Shell中完成。 docker-compose也将允许您轻松地在本地机器上运行testing,结果应该是相同的。

查看维护的Selenium Docker镜像 ,特别是节点风格。 无论您决定按原样使用容器还是自行开启,这都是一个很好的开始。

Interesting Posts