UIC
UIC

Reputation: 141

Run tests with Karate-Chrome (Connection refused exception)

Karate UI-based tests run successfully locally with karate-chrome (steps here) which starts a container with an exposed port.

Now, I am trying to run the tests within the karate-chrome container in CI. I have started the karate-chrome container with KARATE_SOCAT_START=trueand then executed the java -jar (standalone jar) command to run the tests. Non-UI based tests pass but the UI tests are throwing the following exception:

ERROR com.intuit.karate - http request failed: 
15:26:09 DOCKER: org.apache.http.conn.HttpHostConnectException: Connect to localhost:9222 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)

Note that driverTarget with docker has not been configured. Only the following driver's configuration:

  * configure driver = { type: 'chrome', start: false, showDriverLog: true, port:9222 ,pollAttempts: 5}

Is it possible to make it work this way or should a custom docker image be set up?

Upvotes: 1

Views: 1723

Answers (3)

jcsilva94
jcsilva94

Reputation: 11

I know this question is old, but today I stumbled upon this very same issue where I had to configure Karate UI tests for automation. The solution I found was to configure the chrome driver as follows:

* configure driver = { type: 'chrome', showDriverLog: true, port: 9222, pollAttempts: 5, addOptions:['--no-sandbox'], headless: true }

Then the karate standalone jar was able to launch the browser and all tests passed.

Hope this helps!

Upvotes: 1

UIC
UIC

Reputation: 141

I was not able to run UI-based tests directly on karate-chrome. Therefore, I ended up creating a new docker image (docker-openjdk8) to run the tests with driverTarget:

* configure driverTarget = { docker: 'ptrthomas/karate-chrome', showDriverLog: true}

This basically runs the tests with Docker-in-Docker (DIND) process. Would be happy to know if anybody else has got a better solution.

Upvotes: 1

Peter Thomas
Peter Thomas

Reputation: 58058

Sorry, your setup is not clear. But to use configure driverTarget = { docker: 'ptrthomas/karate-chrome' } means Docker should be installed on the machine where you are running the test.

I suggest you start looking at the 1.0 release, and we have a reference test that uses the Docker container a little differently, without using driverTarget. You can find details here: https://stackoverflow.com/a/66005331/143475

It would be great if after you get this working, you post your solution as another answer here so that it helps others and helps us improve the documentation if needed.

Upvotes: 0

Related Questions