Gitlab ci selenium testing with docker not connecting to RemoteWebDriver - java

I want to run automatically selenium tests with gitlab-ci, docker.
Locally everything works fine, but it seems like, there are some connection issues with docker and selenium.
The job is failing with
selenium.test.dashboard.MyTest > myFirstTest FAILED
org.openqa.selenium.remote.UnreachableBrowserException
Caused by: java.net.ConnectException
Caused by: java.net.ConnectException
java.lang.NullPointerException
I tried to change different url's to connect to selenium server and I thought there is maybe a port issue. But every combination which I tried ended up with the same result.
.gitlab-ci.yml
image: gradle:alpine
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
stages:
- build
- seleniumTesting
build:
stage: build
script:
- echo $CI_JOB_STAGE
- echo $CI_COMMIT_REF_NAME
- gradle --build-cache war
artifacts:
paths:
- public
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths:
- build
- .gradle
seleniumTestingChrome:
stage: seleniumTesting
script: gradle integrationTest
# services:
# - selenium/standalone-chrome:latest
services:
- name: selenium/standalone-chrome:latest
artifacts:
paths:
- build/reports/tests/
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths:
- build
- .gradle
Java code for RemoteWebDriver
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
try {
// driver = new RemoteWebDriver( new URL("http://selenium_standalone-chrome:4444/wd/hub"), capabilities);
WebDriver driver = new RemoteWebDriver( new URL("http://127.0.0.1:4444/wd/hub"), capabilities);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
created container on runner
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
92f018da4cbe 8017d8c2ba74 "sh -c 'if [ -x /usr…" 20 seconds ago Up 19 seconds runner-Y2QWpCBd-project-4-concurrent-0-build-4
9dfdc838a7af 9e599fb82f84 "/opt/bin/entry_poin…" 40 seconds ago Up 38 seconds 4444/tcp runner-Y2QWpCBd-project-4-concurrent-0-selenium__standalone-chrome-0
docker logs command on runner
019-08-30 17:06:02,099 INFO Included extra file "/etc/supervisor/conf.d/selenium.conf" during parsing
2019-08-30 17:06:02,101 INFO supervisord started with pid 7
2019-08-30 17:06:03,106 INFO spawned: 'xvfb' with pid 10
2019-08-30 17:06:03,109 INFO spawned: 'selenium-standalone' with pid 11
17:06:03.826 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
2019-08-30 17:06:03,830 INFO success: xvfb entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2019-08-30 17:06:03,830 INFO success: selenium-standalone entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
17:06:04.065 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
2019-08-30 17:06:04.200:INFO::main: Logging initialized #1058ms to org.seleniumhq.jetty9.util.log.StdErrLog
17:06:04.804 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
17:06:05.050 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
I do expect that the test is running on the gitlab-ci-runner in a docker container. Connects to the selenium-server and executes the selenium test with a public available url

As pointed out by #Sascha Frinken
The URL to connect to the RemoteWebDriver was wrong. I missed one underscore.
"http://selenium_standalone-chrome:4444/wd/hub"
VS
"http://selenium__standalone-chrome:4444/wd/hub"

there is topic in gitlab https://docs.gitlab.com/ee/ci/services/#accessing-the-services, which states
Everything after the colon (:) is stripped.
Slash (/) is replaced with double underscores (__) and the primary alias is created.
Slash (/) is replaced with a single dash (-) and the secondary alias is created (requires GitLab Runner v1.1.0 or higher).

Related

Unable to launch Chrome Browser in Selenium Remote WebDriver

I am new to Selenium. I am trying to Launch Chrome using Remote web driver. Below are the environment I am using.
Windows : Windows 10 Enterprise
Java Version : 9.0.4
Selenium Standalone Jar : 3.5.3
IDE : Eclipse
Started hub and node servers on my local machine like below -
On one CMD session -
java -jar selenium-server-standalone-3.5.3.jar -role hub
22:10:41.391 INFO - Selenium build info: version: '3.5.3', revision: 'a88d25fe6b'
22:10:41.391 INFO - Launching Selenium Grid hub
2022-05-25 22:10:43.322:INFO::main: Logging initialized #2152ms to org.seleniumhq.jetty9.util.log.StdErrLog
22:10:43.332 INFO - Will listen on 4444
2022-05-25 22:10:43.365:INFO:osjs.Server:main: jetty-9.4.5.v20170502
2022-05-25 22:10:43.381:INFO:osjs.session:main: DefaultSessionIdManager workerName=node0
2022-05-25 22:10:43.381:INFO:osjs.session:main: No SessionScavenger set, using defaults
2022-05-25 22:10:43.382:INFO:osjs.session:main: Scavenging every 600000ms
2022-05-25 22:10:43.387:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler#4d0d9fe7{/,null,AVAILABLE}
2022-05-25 22:10:43.399:INFO:osjs.AbstractConnector:main: Started ServerConnector#1500b2f3{HTTP/1.1,[http/1.1]}{0.0.0.0:4444}
2022-05-25 22:10:43.400:INFO:osjs.Server:main: Started #2230ms
22:10:43.400 INFO - Nodes should register to http://********:4444/grid/register/
22:10:43.401 INFO - Selenium Grid hub is up and running
22:10:44.300 INFO - Registered a node http://******:5555
22:10:54.537 INFO - Registered a node http://********:5555
22:10:54.537 WARN - Cleaning up stale test sessions on the unregistered node http://********:5555
And on another CMD session i have like below -
java -jar -Dwebdriver.chrome.driver="C:\********\chromedriver.exe" selenium-server-standalone-3.5.3.jar -role node -hub http://localhost:4444
22:10:51.312 INFO - Selenium build info: version: '3.5.3', revision: 'a88d25fe6b'
22:10:51.313 INFO - Launching a Selenium Grid node
2022-05-25 22:10:53.750:INFO::main: Logging initialized #2658ms to org.seleniumhq.jetty9.util.log.StdErrLog
22:10:53.773 INFO - Driver class not found: com.opera.core.systems.OperaDriver
22:10:53.783 INFO - Driver provider class org.openqa.selenium.safari.SafariDriver registration is skipped:
registration capabilities Capabilities [{browserName=safari, version=, platform=MAC}] does not match the current platform WIN10
22:10:53.798 INFO - Using the passthrough mode handler
2022-05-25 22:10:53.811:INFO:osjs.Server:main: jetty-9.4.5.v20170502
2022-05-25 22:10:53.824:WARN:osjs.SecurityHandler:main: ServletContext#o.s.j.s.ServletContextHandler#4ed5eb72{/,null,STARTING} has uncovered http methods for path: /
2022-05-25 22:10:53.826:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler#4ed5eb72{/,null,AVAILABLE}
2022-05-25 22:10:53.837:INFO:osjs.AbstractConnector:main: Started ServerConnector#e19bb76{HTTP/1.1,[http/1.1]}{0.0.0.0:5555}
2022-05-25 22:10:53.837:INFO:osjs.Server:main: Started #2745ms
22:10:53.837 INFO - Selenium Grid node is up and ready to register to the hub
22:10:53.845 INFO - Starting auto registration thread. Will try to register every 5000 ms.
22:10:53.845 INFO - Registering the node to the hub: http://localhost:4444/grid/register
22:10:54.537 INFO - The node is registered to the hub and ready to use
I have the code for Chrome like below -
public class ChromeFactory extends DriverFactory{
String mcWebUrl;
public ChromeFactory(String mcURL) {
mcWebUrl = mcURL;
initBrowser();
}
#Override
protected void initBrowser() {
try {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setBrowserName("chrome");
URL remoteUrl = new URL("http://*******:4444/wd/hub");
WebDriver driver = new RemoteWebDriver(cap);
driver.get(mcWebUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
}
I get a below message in red and thats all the Browser do not launch -
May 25, 2022 10:23:25 PM org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer createTracer
INFO: Using OpenTelemetry for tracing
WebDriver driver = new RemoteWebDriver(cap);
You are missing the parameter URL in the RemoteWebDriver constructor.
The correct way to call is:
URL remoteUrl = new URL("http://*******:4444/wd/hub");
WebDriver driver = new RemoteWebDriver(*remoteUrl* , cap);

When i run the build in Jenkins i got this Error : Cannot find firefox binary in PATH. Make sure firefox is installed

I created a job Maven Project in Jenkins for the purpose to Compile and execute all my automatic tests, but when i build the job i got this error :
i got the same message error for all the scenarios
should i create a pipeline in place of project maven ?
i recupare my project with the link ssh GitLab and im working behind a proxy
Thnaks(y)
Here is a docker-compose file that will open 7 instances of FF and 1 instance on chrome. I use it with azure pipeline but you can integrate it with jenkins. You'll will have to add a jenkins task that runs docker-compose
To try on command line , just install docker desktop ( i use it with mac) and run below command
docker-compose -f /path/of/file up
version: "3"
services:
selenium-hub:
image: selenium/hub:3.141.59-20210607
container_name: selenium-hub
ports:
- "65299:4444"
chrome:
image: selenium/node-chrome:3.141.59-20210607
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
firefox:
image: selenium/node-firefox:3.141.59-20210607
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
deploy:
mode: replicated
replicas: 7
For using docker-compose with azure pipeline , I am using the below.
Make sure you have dockerRegistryEndpoint setup (in below ex: Dockerhub) . I use this to run my cucumber tests and integrate third party cucumber report (PublishCucumberReport#1)in pipeline
trigger:
- master
resources:
- repo: self
variables:
tag: '$(Build.BuildId)'
stages:
- stage: Build
displayName: Build and Push image
jobs:
- job: Build
displayName: Build and Push
pool:
vmImage: 'ubuntu-latest'
steps:
- task: DockerCompose#0
displayName: open browser instances
inputs:
containerregistrytype: 'Container Registry'
dockerRegistryEndpoint: Dockerhub
dockerComposeFile: '**/docker-compose.yml'
action: 'Run a Docker Compose command'
dockerComposeCommand: 'up -d'
detached: true
- task: Maven#3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/target/cucumber.html'
goals: 'clean verify -P acceptanceTests -e -X'
- task: PublishPipelineArtifact#1
displayName: Publish cucumber report
inputs:
pathToPublish: $(System.DefaultWorkingDirectory)/s/target/cucumber-report/
artifactName: 'cucumber.html'
- task: PublishCucumberReport#1
inputs:
jsonDir: ./target/cucumber-report/
outputPath: ./target/
For documentation , refer - https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/docker-compose?view=azure-devops

Getting error "ErrImagePull" in kubernetes deployment in simple print hello world program

helloworld.java:
import java.util.*;
public class helloworld {
public static void main(String[] a)
{
int index;
Scanner scan = new Scanner(System.in);
for(index=0;index<20;index++)
System.out.println("helloworld\t"+(index+1));
}
}
Dockerfile.file:
FROM openjdk:7
LABEL maintainer="Arun kumar"
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
RUN javac helloworld.java
CMD ["java", "helloworld"]
This prepares a docker image, which I can then create using this command (in the repository where the files are present):
docker built -t javaprogram .
Then I run this image using this command:
docker run -it -d javaprogram
Then I create the copy of container using this command:
docker commit containerId arunkumarduraisamy66/javacontprogram
Then I push the image to my docker hub repository in public mode using this command:
docker push arunkumarduraisamy66/javacontprogram
Then I start MiniKube:
minikube start
Then I try to create a container using this command:
kubectl create deployment javakubedeployment --image=arunkumarduraisamy66/javacontprogram
It gives the following error: ErrImagePull
I am not sure how to resolve this.
C:\Users\thula\Documents\kubernetes and docker\docker java\helloworld> kubectl describe pod javaprogram-64b48854-ns7jp
Name: javaprogram-64b48854-ns7jp
Namespace: default
Priority: 0
Node: minikube/192.168.49.2
Start Time: Wed, 30 Dec 2020 09:04:42 +0530
Labels: app=javaprogram
pod-template-hash=64b48854
Annotations: <none>
Status: Running
IP: 172.17.0.3
IPs:
IP: 172.17.0.3
Controlled By: ReplicaSet/javaprogram-64b48854
Containers:
javacontprogram:
Container ID: docker://8cb0722bde94704a3dfbec2514958c1cea88bd0f5df0afb2678292835c4f871e
Image: arunkumarduraisamy66/javacontprogram
Image ID: docker-pullable://arunkumarduraisamy66/javacontprogram#sha256:fe00f09ebc6a6bc651343a807b1adf9e48b62596ddf9424abc11ef3c6f713291
Port: <none>
Host Port: <none>
State: Terminated
Reason: Error
Exit Code: 1
Started: Wed, 30 Dec 2020 09:05:50 +0530
Finished: Wed, 30 Dec 2020 09:05:51 +0530
Last State: Terminated
Reason: Error
Exit Code: 1
Started: Wed, 30 Dec 2020 09:05:16 +0530
Finished: Wed, 30 Dec 2020 09:05:17 +0530
Ready: False
Restart Count: 3
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-bs9b6 (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
default-token-bs9b6:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-bs9b6
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 79s default-scheduler Successfully assigned default/javaprogram-64b48854-ns7jp to minikube
Normal Pulled 74s kubelet Successfully pulled image "arunkumarduraisamy66/javacontprogram" in 3.4663937s
Normal Pulled 68s kubelet Successfully pulled image "arunkumarduraisamy66/javacontprogram" in 3.5957121s
Normal Pulled 46s kubelet Successfully pulled image "arunkumarduraisamy66/javacontprogram" in 3.8325583s
Normal Pulling 16s (x4 over 77s) kubelet Pulling image "arunkumarduraisamy66/javacontprogram"
Normal Pulled 13s kubelet Successfully pulled image "arunkumarduraisamy66/javacontprogram" in 3.5564947s
Normal Created 12s (x4 over 74s) kubelet Created container javacontprogram
Normal Started 12s (x4 over 73s) kubelet Started container javacontprogram
Warning BackOff 10s (x5 over 66s) kubelet Back-off restarting failed container
I've recreated your application's image and as mentioned in comments by #mmking it is terminated because pod has finished it's task. When you check logs of the pod you can see that it has ran correctly and printed helloworld 20 times and then gets terminated as there is nothing more to do for this pod:
$kubectl logs javakubedeployment-7bcfb44b74-8b5zz
helloworld 1
helloworld 2
helloworld 3
[...]
helloworld 19
helloworld 20
To keep pod running you can add simple sleep command in it.

Selenium RC: I am unable run test suite in firefox or any other browser

I am newbie with Selenium. I recently encountered with one failure that I could not overcome.
I am trying to run next suite in firefox or chrome:
C:\auto_tools>java -jar selenium-server-standalone-2.46.0.jar -htmlSuite "*googlechrome C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "http://google.com" "D:\Selenium_2.0\Selenium_tests\Selenium_IDE&Selenium Builder\Selenium_start\test_suit.html" "D:\Selenium_2.0\Selenium_tests\Selenium_IDE&Selenium Builder\Selenium_start\results.html"
As answer I am see chrome browser with:
http://google.com/selenium-server/core/TestRunner.html?auto=true&multiWindow=true&defaultLogLevel=info&baseUrl=http%3A%2F%2Fgoogle.com&resultsUrl=../postResults&test=http%3A%2F%2Fgoogle.com%2Fselenium-server%2Ftests%2Ftest_suit.html
and
23:02:46.698 INFO - Launching a standalone Selenium Server
23:02:46.825 INFO - Java: Oracle Corporation 25.45-b02 23:02:46.826
INFO - OS: Windows 7 6.1 amd64 23:02:46.838 INFO - v2.46.0, with Core
v2.46.0. Built from revision 87c69e2 23:02:46.897 INFO - Driver class
not found:com.opera.core.systems.OperaDriver 23:02:46.897 INFO -
Driver provider com.opera.core.systems.OperaDriver is not registered
23:02:47.096 INFO - Launching Google Chrome...
with *firefox path/to/firefox.exe - same issue...
Can anyone help please?
Yesterday I found out that the reason was that my antivirus blocked connection to localhost including port 4444 - thats why I could not run test suit.

Selenium RC doesn't run the test suite by BAT file

I've tried to run my test suite by Selenium RC through a BAT file.
Actually it worked OK until yesterday morning and it stopped to run my test suite.
Probably because I've added user-extensions.js and since that I can't run my test suite by the selenium RC.
How can I add this script to my test suite?
I'm using Selenium IDE for to write my test cases, so I guess that make this more complex problem..
This is the console log of the BAT file during the execution:
>
C:\automation>cd C:\automation\screenshots\
C:\automation\screenshots>del *.png
Could Not Find C:\automation\screenshots\*.png
10:46:38.926 INFO - Launching a standalone server
10:46:39.098 INFO - Java: Oracle Corporation 25.25-b02
10:46:39.098 INFO - OS: Windows 8.1 6.3 amd64
10:46:39.113 INFO - v2.44.0, with Core v2.44.0. Built from revision 76d78cf
10:46:39.238 INFO - RemoteWebDriver instances should connect to: http://127.0.0.
1:4444/wd/hub
10:46:39.238 INFO - Version Jetty/5.1.x
10:46:39.238 INFO - Started HttpContext[/selenium-server,/selenium-server]
10:46:39.379 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler#6e3c1e
69
10:46:39.379 INFO - Started HttpContext[/wd,/wd]
10:46:39.379 INFO - Started HttpContext[/selenium-server/driver,/selenium-server
/driver]
10:46:39.379 INFO - Started HttpContext[/,/]
10:46:39.379 INFO - Started SocketListener on 0.0.0.0:4444
10:46:39.379 INFO - Started org.openqa.jetty.jetty.Server#b1bc7ed
jar:file:/C:/automation/selenium-server-standalone-2.44.0.jar!/customProfileDirC
USTFFCHROME
10:46:39.535 INFO - Preparing Firefox profile...
10:46:42.666 INFO - Launching Firefox...
10:46:44.245 INFO - Checking Resource aliases
This is the code line from the BAT file:
java -jar C:\automation\selenium-server-standalone-2.44.0.jar -htmlSuite "*firefox C:\Program Files (x86)\Mozilla Firefox\firefox.exe" "https://www.mywebsite.com" "C:\automation\emailSanity.html" "C:\automation\testing_results.html" -port 4444
This is the screenshot of the actual result of the Selenium RC in action:
http://i57.tinypic.com/28u71jl.png
Please your help!
Thanks a lot.
Considering your app is at the splash screen, I can only assume that you forgot to put in your URL to initially open.
Since you are using RC, then your first statement of your test script should be:
selenium.open("http://example.com"); // where example.com is the app is your SUT.

Categories

Resources