1

I try to use ptrthomas/karate-chrome image docker. I wish execute multiple driver/ui karate tests in the docker image. Currently use, your image docker ptrthomas/karate-chrome, but only 1 scenario driver/ui is successful execute.

The scenario are basic:

Scenario: 
Given driver 'https://github.com/login'

After execution, I have this error:

[ForkJoinPool-2-worker-1] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 3][route: {}->http://localhost:9222][total available: 0; route allocated: 1 of 5; total allocated: 1 of 10]
 karate-chrome-runner_docker | 16:07:50.206 [ForkJoinPool-2-worker-1] DEBUG org.apache.http.impl.execchain.MainClientExec - Opening connection {}->http://localhost:9222 
karate-chrome-runner_docker | 16:07:50.206 [ForkJoinPool-2-worker-1] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to localhost/127.0.0.1:9222 
karate-chrome-runner_docker | 16:07:50.206 [ForkJoinPool-2-worker-1] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connection established 127.0.0.1:54604<->127.0.0.1:9222
karate-chrome-runner_docker | 16:07:50.206 [ForkJoinPool-2-worker-1] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-3: set socket timeout to 30000 
karate-chrome-runner_docker | 16:07:50.206 [ForkJoinPool-2-worker-1] DEBUG     org.apache.http.impl.execchain.MainClientExec - Executing request GET /json HTTP/1.1
karate-chrome-runner_docker | 16:07:50.206 [ForkJoinPool-2-worker-1] DEBUG org.apache.http.impl.execchain.MainClientExec - Target auth state: UNCHALLENGED 
karate-chrome-runner_docker | 16:07:50.206 [ForkJoinPool-2-worker-1] DEBUG org.apache.http.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED

And I try to use 2 dockers (one to execute tests -maven:3.6-jdk-11 and one to target UI chrome -justinribeiro/chrome-headless:stable ) But already issues: connection failed So, I try many configuration to drivers:

karate.configure( 
    'driver', {
      type: 'chrome',
      executable: 'chrome',
     // port: 9222, //default value
     // host: 'localhost', //default value
      showDriverLog: true,
      showProcessLog: true,
      start: false,
      headless: true
    }
  )

Docker_compose :

      version: '3.7'

networks:
  karate: {}

services:
  karate-chrome-runner:
    image: ptrthomas/karate-chrome
    container_name: "karate-chrome-runner_docker"
    volumes:
      - "~/.m2:/var/maven/.m2"
      - "./:/usr/src/mymaven"
    environment:
      - MAVEN_CONFIG=/var/maven/.m2
    working_dir: "/usr/src/mymaven"
    entrypoint: "./entrypoint.sh"
    networks:
      - karate

Please, would you help me to understand the correct operation? Have you an example to project docker ?

Thanks for your help

chlo
  • 21
  • 1
  • 3

1 Answers1

0

I don't know about docker compose, but please look at the regression tests that the Karate project itself uses: karate-e2e-tests

So the docker container is built locally and the tests are run within it. This is the batch script: build-docker.sh

The approach here is to start the docker container with name karate and mount your existing tests in the current folder to /karate

docker run --name karate --rm --cap-add=SYS_ADMIN -v "$PWD":/karate -v "$HOME"/.m2:/root/.m2 ptrthomas/karate-chrome &

Since the above is run in the background you can now easily invoke the command to run tests:

docker exec -w /karate karate mvn test -Dtest=com.myco.MyTestRunner

EDIT: for those looking for advanced guidance on how to set up cross-browser testing, parallel-execution and managing large browser-automation test-suites, refer: https://stackoverflow.com/a/60387907/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248