空手道是否支持在 CI 环境下进行无头测试 (gitlab CI)

Does karate support headless testing in CI environment (gitlab CI)

我们已经使用空手道框架完成了 UI 自动化。但是我在尝试 运行 使用 gitlab 管道进行测试时面临挑战。

我正在使用 gradle 构建工具并在 gitlab-ci.yaml 中添加了一个简单的步骤,但每次构建都失败。这是我尝试过的: 在功能文件中添加了这个: * configure driver = { type: 'chrome', headless: true } 收到错误:

  18:10:39.056 [ForkJoinPool-1-worker-1] DEBUG org.apache.http.impl.execchain.MainClientExec - Opening connection {}->http://localhost:9222
  18:10:39.056 [ForkJoinPool-1-worker-1] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to localhost/127.0.0.1:9222
  18:10:39.056 [ForkJoinPool-1-worker-1] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-8: Shutdown connection
  18:10:39.056 [ForkJoinPool-1-worker-1] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection discarded
  18:10:39.057 [ForkJoinPool-1-worker-1] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 8][route: {}->http://localhost:9222][total available: 0; route allocated: 0 of 5; total allocated: 0 of 10]
  18:10:39.057 [ForkJoinPool-1-worker-1] ERROR com.intuit.karate - org.apache.http.conn.HttpHostConnectException: Connect to localhost:9222 [localhost/127.0.0.1] failed: Connection refused (Connection refused), http call failed after 1 milliseconds for URL: http://localhost:9222

此外,尝试添加 chromedriver:* configure driver = { type: 'chromedriver', port: 9515, executable: 'chromedriver' }。收到此错误:

   18:19:01.541 [ForkJoinPool-1-worker-1] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {}->http://localhost:9515][total available: 0; route allocated: 0 of 5; total allocated: 0 of 10]
    18:19:01.542 [ForkJoinPool-1-worker-1] ERROR com.intuit.karate - org.apache.http.conn.HttpHostConnectException: Connect to localhost:9515 [localhost/127.0.0.1] failed: Connection refused (Connection refused), http call failed after 19 milliseconds for URL: http://localhost:9515/session
    18:19:01.542 [ForkJoinPool-1-worker-1] ERROR com.intuit.karate - http request failed: 
    org.apache.http.conn.HttpHostConnectException: Connect to localhost:9515 [localhost/127.0.0.1] failed: Connection refused (Connection refused)

我想在管道 运行 时在特定环境中执行测试,但目前没有任何效果。

UI 和 CI 并不容易,我们已经记录了如何使用 karate-chrome 容器:https://github.com/intuit/karate/tree/master/karate-core#karate-chrome

其他人在 SaaS 提供商方面取得了成功:

如果您正在尝试另一条路线,您可能需要做一些研究/挖掘。请将您的发现回馈给社区。

我们可以在.gitlab-ci.yml中的before_script中添加安装chrome和chrome驱动程序的代码来解决上述问题。

before_script:
  - apt-get update && apt-get install -y --no-install-recommends google-chrome-stable
  - wget https://chromedriver.storage.googleapis.com/2.35/chromedriver_linux64.zip
  - unzip chromedriver_linux64.zip
  - mv chromedriver /usr/bin/chromedriver
  - chown root:root /usr/bin/chromedriver
  - chmod +x /usr/bin/chromedriver