Karate UI tests are Failing in Jenkins Pipeline [duplicate] - jenkins

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?

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.

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!

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.

Related

Cypress can't see rails server output from within the same docker container

I'm attempting to get cypress working with rails in a single docker container. I'm using the Simplest possible Rails 6 + docker-compose project (at https://github.com/bdavidxyz/simplest-rails-docker), with cypress/included:3.8.1 (at https://github.com/cypress-io/cypress-docker-images/tree/master/included), based on the End-to-End Testing Web Apps: The Painless Way blog (at https://mtlynch.io/painless-web-app-testing/).
After building, I run docker-compose up and cypress tries to start. Then the rails server starts, cypress succeeds and tests run.
Cypress baseurl http://web-srv:3000/ gets 403
"landing" http://host.docker.internal:3000/ ECONNREFUSED 192.168.65.2:3000
google https://google.com works
localhost http://localhost:3000/hello/say_hello ECONNREFUSED 127.0.0.1:3000
---but I do see the rails welcome on a browser at localhost:3000.
Does anyone know a way to get Cypress to see the Rails output?
For clarity, I made a gitub repository with code and steps to reproduce: https://github.com/Sambalero/docker-cypress-rails (I'm on windows 10)
Thank you!

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?
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.
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!
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.

How to get SonarQube (running in docker container) to connect to localhost:9000 from Jenkins Pipeline?

I am running SonarQube on both java and javascript code inside a CentOS VM. I pulled the sonarqube docker image and am running the container. I exposed port 9000 and am able to open up localhost:9000 and interact with the sonarqube gui. When I run the sonar-scanner from the command line on the JavaScript code using this command:
sonar-scanner -Dsonar.projectKey=javascript_code -Dsonar.sources=. -Dsonar.host.url=http://localhost:9000 -Dsonar.login=admin -Dsonar.password=admin
I get a fully analyzed project. As well as the JavaScript code I can run it on the Java code using the maven build. Both work correctly from the command line.
When I add it into a Jenkins Pipeline I do the exact same commands and get the following:
Error: SonarQube server [http://localhost:9000] can not be reached
Caused by: Fail to get bootstrap index from server
Caused by: Failed to connect to localhost:9000
Caused by: Connection refused (Connection refused)
I also tried when starting the container to use --network="host" instead of publishing port 9000, but it still does not connect from the Jenkins Pipeline. Everything works correctly when I am running the commands from the Command Line, just when I try to put it into a Jenkins Pipeline.
Any suggestions on how to fix this? Thanks.
*Edit: Using the sonarqube plugin I was able to get my analysis to run as a Jenkins Job. However, when I try to add the analysis into the pipeline I get the same SonarQube server cannot be reached error. It says it skips my project because the project has been banned form the build due to previous failures and gives me this error message:
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar (default-cli) on project sonarqubeproj:
Unable to execute SonarQube: Fail to get bootstrap index from server: unexpected end of stream on Connection{localhost:9000, proxy=DIRECT hostAddress=localhost/127.0.0.1:9000 cipherSuite=none protocol=http/1.1}: \n not found: limit=0 content=… -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar (default-cli) on project feedback-tool-ui: Unable to execute SonarQube
The problem you are facing is most likely related to how you run jenkins.
I assume you also run jenkins via docker. this means that in the context of jenkins, localhost is not your host system, but the jenkins container. This means you need to adapt your sonarqube-url to reference the host system.
Therefore you have multiple options:
use the public ip of the host system
use the docker ip of the host system
resolve the ip via dns. docker has an internal DNS and if those container run in the same network, you can normally reach them by containername.
sidenote:
i am not sure if you are using docker-compose or kubernetes, but if you are not using it, you might also want to dive into docker-compose as it is just a simple yaml-config in which you can easily start up servers.

Unable to listen on port 33848 when running Jenkins tests

I am using jenkins-test-harness to run some tests on my jenkins library code, but when it executes the tests I get the following error for each test :
hudson.UDPBroadcastThread#run: Cannot listen to UDP port 33,848, skipping: java.net.SocketException: Can't assign requested address
The test will pass (if it should pass), but it then takes about 75 seconds for the jenkins server to shut down. I believe that these two are related, but I can't work out why I am getting this error. I have nothing else running on this port.
When I run the tests within a gradle docker container, rather than locally on the command line or inside the IDE (IntelliJ). This is very frustrating. While it does not change the result of the tests, it takes the running from about 10 minutes to over 1 hour and 15 minutes.
Am I missing a setting which is making this fail?
For me this was caused by Jenkins assuming that the default IP address it would be provided with would be IPv4 when in fact my machine was dual stack, preferring IPv6. I resolved it by ensuring that the integrationTest section of my build.gradle file had systemProperties 'java.net.preferIPv4Stack' : true. A bit like this:
integrationTest: {
/* other statements */
systemProperties 'java.net.preferIPv4Stack' : true
}
I must confess I saw no significant difference to my Jenkins shutdown time. I'd be interested to know if this resolves the error message, and if that resolves your overall issue.

Orleans: "Running in a Stand Alone Silo" example does not run

I have just started to get myself familiar with Orleans for a project. I have some questions regarding that. I am currently using the Step by Step Tutorial. Unfortunately when I try to run the example with "Running in a Stand-Alone Silo" in my laptop, the Grains collection fails with lots of exceptions. I am not sure how to troubleshoot that?
The document mentions "OrleansHost.exe is a ready-made host executable intended for running Orleans code on Windows Server (Azure has a different host)". I am not sure what this means? Is this the reason why it does not work on my laptop which has Windows 10 running?
From your logs, it looks like you're still connecting to the gateway by port 4000, the default one. Have you tried specifying your client to use the same port as your server? The example uses port 3000:
var config = Orleans.Runtime.Configuration.ClientConfiguration.LocalhostSilo(30000);

Resources