空手道:如何使用sudo为Linux使用实现--no-sandbox标头

时间:2019-06-12 09:01:24

标签: karate

我想在jenkins中为UI测试自动化设置无头chrome驱动程序。

但是要运行测试命令

sudo -E java -jar karate-0.9.3.jar karate_GUI.feature

我必须以root用户身份运行,并且需要--no-sandbox,如果我没记错的话,v0.9.3仍不支持它。

如果可能,如何包含--no-sandbox选项?

我检查了https://intuit.github.io/karate/karate-core/,没有--no-sandbox选项。

我的功能配置:

Feature: message end-point
Background:
* configure driver = { type: 'chrome', executable: '/usr/bin/google-chrome', headless: true }
# Login Url
* def browserManagementUrl = 'http://localhost:8000/login/'

Scenario: GUI Testing for Login page
    Given driver browserManagementUrl
    And eval driver.input('input[name=name]', 'admin')
    And eval driver.input('input[name=password]', 'adminadmin')
    And driver.submit('#login-button')
    When driver.submit('#login-button')
    Then match driver.location == 'http://localhost:8000/select/'

linux命令及其结果

sudo -E java -jar karate-0.9.3.jar karate_GUI.feature
07:15:56.296 [main] INFO  com.intuit.karate.Main - Karate version: 0.9.3
07:15:57.345 [ForkJoinPool-1-worker-1] WARN  com.intuit.karate - skipping bootstrap configuration: could not find or read file: classpath:karate-config.js
07:15:57.418 [chrome_1560323757416] DEBUG c.i.k.driver.chrome_1560323757416 - command: [/usr/bin/google-chrome, --remote-debugging-port=9222, --no-first-run, --user-data-dir=/var/jenkins_home/workspace/my-karate_GUI@2/integrations/target/chrome_1560323757416, --disable-popup-blocking, --headless]
07:15:57.419 [ForkJoinPool-1-worker-1] DEBUG c.i.k.driver.chrome_1560323757416 - poll attempt #0 for port to be ready - localhost:9222
07:15:57.420 [chrome_1560323757416] DEBUG c.i.k.driver.chrome_1560323757416 - env PATH: /sbin:/bin:/usr/sbin:/usr/bin
07:15:57.423 [ForkJoinPool-1-worker-1] DEBUG c.i.k.driver.chrome_1560323757416 - sleeping for millis: 250
07:15:57.674 [ForkJoinPool-1-worker-1] DEBUG c.i.k.driver.chrome_1560323757416 - poll attempt #1 for port to be ready - localhost:9222
07:15:57.675 [ForkJoinPool-1-worker-1] DEBUG c.i.k.driver.chrome_1560323757416 - sleeping for millis: 250
07:15:57.793 [chrome_1560323757416] DEBUG c.i.k.driver.chrome_1560323757416 - [0612/071557.791933:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
07:15:57.810 [chrome_1560323757416] DEBUG c.intuit.karate.shell.CommandThread - command complete, exit code: 1 - [/usr/bin/google-chrome, --remote-debugging-port=9222, --no-first-run, --user-data-dir=/var/jenkins_home/workspace/my-karate_GUI@2/integrations/target/chrome_1560323757416, --disable-popup-blocking, --headless]
07:15:57.926 [ForkJoinPool-1-worker-1] DEBUG c.i.k.driver.chrome_1560323757416 - poll attempt #2 for port to be ready - localhost:9222
07:15:57.927 [ForkJoinPool-1-worker-1] DEBUG c.i.k.driver.chrome_1560323757416 - sleeping for millis: 250
07:15:58.178 [ForkJoinPool-1-worker-1] DEBUG c.i.k.driver.chrome_1560323757416 - poll attempt #3 for port to be ready - localhost:9222
[...]
07:16:02.206 [ForkJoinPool-1-worker-1] DEBUG c.i.k.driver.chrome_1560323757416 - poll attempt #19 for port to be ready - localhost:9222
07:16:02.207 [ForkJoinPool-1-worker-1] DEBUG c.i.k.driver.chrome_1560323757416 - sleeping for millis: 250
07:16:02.848 [ForkJoinPool-1-worker-1] DEBUG c.i.k.driver.chrome_1560323757416 - request:
1 > GET http://localhost:9222/json
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Host: localhost:9222
1 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_212)

07:16:02.862 [ForkJoinPool-1-worker-1] ERROR c.i.k.driver.chrome_1560323757416 - org.apache.http.conn.HttpHostConnectException: Connect to localhost:9222 [localhost/127.0.0.1] failed: Connection refused (Connection refused), http call failed after 13 milliseconds for URL: http://localhost:9222/json
07:16:02.863 [ForkJoinPool-1-worker-1] ERROR c.i.k.driver.chrome_1560323757416 - http request failed:
org.apache.http.conn.HttpHostConnectException: Connect to localhost:9222 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
07:16:02.918 [pool-1-thread-1] INFO  com.intuit.karate.Runner - <<fail>> feature 1 of 1: karate_GUI.feature
---------------------------------------------------------
feature: karate_GUI.feature
report: target/karate_GUI.json
scenarios:  1 | passed:  0 | failed:  1 | time: 5.4993
---------------------------------------------------------
Karate version: 0.9.3
======================================================
elapsed:   6.39 | threads:    1 | thread time: 5.50
features:     1 | ignored:    0 | efficiency: 0.86
scenarios:    1 | passed:     0 | failed: 1
======================================================
failed features:
karate_GUI: karate_GUI.feature:8 -
org.apache.http.conn.HttpHostConnectException: Connect to localhost:9222 [localhost/127.0.0.1] failed: Connection refused (Connection refused)

Exception in thread "main" picocli.CommandLine$ExecutionException: there are test failures
    at com.intuit.karate.Main$1.handleExecutionException(Main.java:133)
    at picocli.CommandLine.parseWithHandlers(CommandLine.java:1157)
    at com.intuit.karate.Main.main(Main.java:139)

1 个答案:

答案 0 :(得分:0)

我想您确实知道UI自动化部分仍处于试验阶段,是的,我不认为我们支持--no-sandbox-随时打开票证并向我们提供一些链接,以了解需要这样做的原因,以及确实如此。

建议的解决方法是,您可以将批处理文件作为executable键传递给configure driver调用。然后,在此批处理文件中,您可以使用所需的任何自定义参数或参数来调用chromedriver可执行文件。

请告诉我们是否可行。对我来说,听起来还需要一种传递任何自定义标志的方法,请将其添加到您的功能请求中。