NotConnectedException error in WebDriver tests running under Jenkins on Linux - firefox

I have a WebDriver test using the FirefoxDriver that I am attempting to run as a Jenkins job.
It works fine in Windows, it also works from the command line in Linux, where my Jenkins server lives.
Unfortunately, I got the following error during executing as a Jenkins job:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms
The Jenkins job consists of 2 steps: a shell step that executes:
Xvfb :1 -screen 0 1024x768x24 &
export DISPLAY=:1
And then a maven package to run the test class.
Why can't I get the Jenkins job to execute Firefox?

What finally ended up working was to create the entire Jenkins job as one step that ran shell commands:
Xvfb :1 -screen 0 1024x768x24 &
export DISPLAY=:1
mvn package
and that worked. No more NotConnectedException.
I had originally had the Jenkins job as 2 steps, shell to create virtual frame buffer and maven goal.

When you run the job from jenkins, it runs the same test as "Jenkins" user. You need to add one more line in etc/hosts file for jenkins user like
your.ip.address.value jenkins

Related

How to run jmeter test through remote servers via jenkins

I am having a linux machine (say m1) [an openStack machine] to run my jmeter test.
My typical process was to put latest jmx file on this machine and trigger below command:
nohup /path/to/jmeter/bin/jmeter -n -t /path/to/script/test.jmx -l /path/to/resultsFolder/results.jtl
Now, I want to trigger same test via jenkins job which should actually do the same activity as above.
I perform two activities (one is to manually trigger jmeter-server on m1 and other to run jenkins job to run test via m1)
To start jmeter server
Ran following command manually on m1 ( SERVER_PORT=1099 nohup /path/to/jmeter/bin/jmeter-server)
Jenkins Job
I have created a jenkins pipeline job:
Stage1: checks out jmeter in jenkins master
stage2: checks out latest script in jenkins master
stage3: Runs jmeter remote test -
command used :
sh '''
chmod u+x jmeter/bin/jmeter.sh
jmeter/bin/jmeter.sh -n -t path/where/jenkins/checked/latest/test/test.jmx -R 10.X.X.X -l results.jtl'''
Stage1 and stage2 runs perfectly.
Stage3: console output shows as below
jmeter/bin/jmeter.sh -n -t jmeter/bin/jmeter.sh -n -t path/where/jenkins/checked/latest/test/test.jmx -R 10.X.X.X -l results.jtl
Creating summariser
Created the tree successfully using path/where/jenkins/checked/latest/test/test.jmx
Configuring remote engine: 10.X.X.X
Starting remote engines
Starting the test # Tue Aug 14 10:41:46 CEST 2018 (1534236106818)
Remote engines have been started
Waiting for possible shutdown message on port 4445
And it keep showing processing ......... unless I trigger manual shutdown.
So, I'm looking for two things
a mechanism to start jmeter-server on slave nodes via jenkins job itself
Running test via remote machines (which can go locations within load machine and trigger test from there itslef)
. Any ideas appreciated. Thank you in advance!
You can launch jmeter server on remote slaves in at least 2 ways:
From Jenkins using Jenkins SSH Plugin
From JMeter itself using OS Process Sampler or SSH Command plugin (in this case you will have 2 scripts, one which will set everything up and another will be the main test in distributed mode.

Xvfb plugin to run multiple job instances concurrently on Jenkins

I have a job in Jenkins that runs UI tests written in Selenium. The job can run multiple instances of it concurrently. I am running into a problem while trying to use Xvfb (the Xvfb plugin or otherwise).
Using the Xvfb plugin
The configuration is as below.
The plugin assigns the same display port to 2 concurrent job instances, and then one fails.
From the Xvfb log (note displayfd is 2 and screen is 0 in both cases):
Xvfb starting$ /usr/bin/Xvfb -displayfd 2 -screen 0 1024x758x16 -fbdir /srv/jenkins/xvfb-86-2156913754362856583.fbdir
Xvfb starting$ /usr/bin/Xvfb -displayfd 2 -screen 0 1024x758x16 -fbdir /srv/jenkins/xvfb-87-5845090375656014678.fbdir
One of the above 2 job instances fails. The failure message is this:
02:11:51 _XSERVTransSocketINETCreateListener: ...SocketCreateListener() failed
02:11:51 _XSERVTransMakeAllCOTSServerListeners: server already running
How can this error be fixed so that the concurrent instances run without any issue?
Further, I wonder how Xvfb plugin does the association of the display to the running browser instances (Firefox in this case). Does it do export DISPLAY=:xx internally, where xx = the display port as computed by the plugin?
Command line (not using Xvfb plugin)
The second way I tried is not to use the plugin and run Xvfb directly using the CLI. I used the Jenkins env variable BUILD_NUMBER to ensure unique display association to the job instance.
export DISPLAY=:${BUILD_NUMBER}
Xvfb :${BUILD_NUMBER} -screen 0 1024x768x24 &
Xvfb starts up fine in both job instances, but the tests fail with this.
Failed to connect to binary FirefoxBinary(/usr/local/bin/firefox) on port 7055; process output follows:
Error: cannot open display: 0:0
It appears the tests are still trying to use display 0:0.
Any help to fix this problem is greatly appreciated.
Have you tried to use Display environment variable in Jenkins, the same Xvbf has started with? In my case it worked and I followed the instructions, described in this article headless execution selenium tests in Jenkins

Why Jenkins isn't able to start the service, but it is starting fine when I start it manually?

I am trying to start HYBRIS server from Jenkins.
When I run the sh hybrisserver.sh start command manually in the server it starts correctly.
But, when I try to run the same command through Jenkins it is not able to start the service.
The Hybris server and Jenkins master are connected through a slave (node).
What could be the issue?
You can include following line of entry on jenkins job and it will start nicely.
export CATALINA_BASE="<Your Hybris DIR>/hybris/bin/platform/tomcat"
export WRAPPER_CONF="$CATALINA_BASE/conf/wrapper.conf"
sudo sh <Your Hybris DIR>/hybris/bin/platform/tomcat/bin/wrapper.sh start
try setting up tools environment
using https://wiki.jenkins-ci.org/display/JENKINS/Tool+Environment+Plugin
then set up required env variable and run slave as cmd through admin rights

running Protractor on headless FF from jenkins with xvfb

Can't get my protractor running on remote server on headless mode. I'll be glad if anyone could help
This is my qa server setting:
Under /etc/init.d/xvfb script to stat Xvfb :99
export DISPLAY=:99 set in bash_profile ( echo $DISPLAY returns :99)
firefox and protractor installed.
My project pom.xml:
I'm using maven-wagon-plugin to execute
The script starting xvfb on display:99 on my qa server
Run protractor protractorTest/conf.js on my qa server
When running the job from jenkins
=> I'm getting error E/launcher - Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms.
Firefox console output: Error: no display specified
Checked if the xvfb is running:
ps -ef | grep Xvfb on QA server shows the Xvfb process running, but
Please let me know if something is wrong or missing?
The xvfb need to start in the same script that is running protractor. So Maven wagon plugin can be used to execute the command that starts the xvfb + runs protractor tests.
Source: #sou comment.

Running Glassfish asadmin Commands via Jenkins

I'm trying to create an automated deployment via Jenkins that deploys an application to Glassfish-2.1.
The problem comes when Jenkins is running the following commands:
sh /usr/local/glassfish/bin/asadmin start-domain --user admin --passwordfile /usr/local/glassfish/passwordfile.txt domain1
sh /usr/local/glassfish/bin/asadmin deploy -s --contextroot admin /tmp/artifacts/$admin_war_file_name
But Jenkins just hangs, apparently waiting for the password. However, I can run this script manaually on the server and it works.
Also, I was curious if this ok from a security standpoint? Should I actually be storing the master password (if in fact I can even get Jenkins to run these commands in the first place!)
Any help is greatly appreciated.

Resources