Karate: How to implement --no-sandbox header for linux usage with sudo

冷暖自知 提交于 2021-02-17 02:03:34

问题


I want to setup a headless chrome driver for UI Test Automation in jenkins.

But to run the test command

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

I have to run as root and it requires --no-sandbox, which, if I'm not wrong, it's still not supported in v0.9.3.

If possible, how can I include --no-sandbox option?

I checked https://intuit.github.io/karate/karate-core/ and there is no --no-sandbox option.

My feature configuration:

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/'

The linux command and it's results

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:


I guess you do know that the UI automation pieces are still experimental and yes I don't think we support --no-sandbox - feel free to open a ticket and help us with some links to why this is needed, what it does etc.

A suggested workaround is you can pass a batch file as the executable key to the configure driver call. In this batch file you can then call the chromedriver executable with whatever custom parameters or arguments you need.

Do let us know if that works. It also sounds to me that a way to pass any custom flags is a needed feature, do add this to your feature request.

EDIT: for those landing here in future, I'm not 100% sure, but maybe the info here will help: https://github.com/intuit/karate/issues/1134#issuecomment-638990087



来源:https://stackoverflow.com/questions/56558357/karate-how-to-implement-no-sandbox-header-for-linux-usage-with-sudo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!