Is it possible to make Jenkins use actual browser instead of headless browser? I a running some tests written in TestNG (using Selenium webdriver). When I run the testng.xml file in Eclipse, the browser starts and the tests run. But when I use Jenkins and run the tests with maven, it doesn't start any browsers.
If your jenkins is hosted in a Windows machine, there are some special configurations you should know about services that are allow to use the interface.
By the way, the easiest way to see the browsers running is starting jenkins using the command line:
java -jar jenkins.war
In linux you could use the same command or use xvfb plugin to run browsers in background.
Hope helps
In addition to this, the main reason for not launching the browser is JNLP (java network launch protocol) , when we execute the war we can interact with the desktop applications.
Using Selenium Grid will allow you to execute the test on Jenkins but open the browser on a remote slave.
To achieve this you need to create an instance RemoteWebdriver than ChromeDriver, IEDriver etc I
For linux. If jenkins is running as a daemon, you could specify active display to connect to and run your browser on it. Check what display you could connect to:
ps e | grep -Po " DISPLAY=[\.0-9A-Za-z:]* " | sort -u
My output is:
DISPLAY=:10.0
DISPLAY=:2
DISPLAY=:2.0
Then go to your jenkins project -> Configure -> Build and add the next string above your main build configuration through "Add build step -> Execute shell"
/bin/bash -c "export DISPLAY=:10"
Edited: I've encountered the issue again recently. To resolve it:
I've given for the jenkins' user ability to interact with the desktop of my current user:
xhost +si:localuser:jenkins
so if I connect to my linux system through ssh using jenkins' user credentials, export display of my current user (export DISPLAY=:10) and run, for example google-chrome or firefox inside of putty's terminal, they are launching on my current user's desktop.
After this I've checked If I could start "mvn test" command inside of workspace/MyTests folder from my putty so it will start browser and execute tests.
At the end I've created simple script in the root of my current user:
vi ~/.startup.sh
#!/bin/bash
xhost +si:localuser:jenkins
and added it to my Xfce4 GUI: Application -> Settings -> Session and Startup -> Application Autostart, specifying command field as:
sh -c $HOME/.startup.sh
It's because of this script should work only when desktop is loaded to share my current user's display with jenkins' user. After reboot and connecting to this server through RDC desktop loads with xhost command applied. And after this jenkins could interract with desktop even when I close the RDP connection but leaving current user's session alive.
I've removed Build step in my jenkins' project configuration that was stated "Invoke top-level Maven targets". It could not start my browsers.
I've changed my "Add build step -> Execute shell" to:
export DISPLAY=:10
cd /var/lib/jenkins/workspace/MyTests
mvn test
I've tried grid also, turning selenium-server-standalone -hub and -node into daemons. But it was slower than launching browsers with WebDriver in the such way.
Related
My Selenium headless tests are triggered from Jenkins server and run in EC2-Ubuntu. I want to view the test live on Chrome so I installed Xvfb plugin on Jenkins.
On EC2 I installed Xvfb. When I start executing the build, my test starts execution and I see below logs:
Xvfb /usr/bin/Xvfb :1 -fbdir /var/lib/jenkins/xvfb 27-..fbdir13700092919317283985
Parsing POMs
Established TCP socket on 30810
and I see the test is running successfully.
Now I do SSH to EC2 from Mac terminal by
ssh -L 5901:localhost:5901 qa_user#10.113.x.xxx
Then I execute:
qa_user#jenkins-it:~$ export DISPLAY=: 30810` (Port number from Jenkins logs above)
qa_user#jenkins-it:~$ vncserver "$DISPLAY" -geometry 1280x1024
New 'X' desktop is jenkins-it: 30810
Starting applications specified in /home/qa_user/.vnc/xstartup
Log file is /home/qa_user/.vnc/jenkins-it: 30810.log
qa_user#jenkins-it:~$ x11vnc --listen 0.0.0.0 -rfbport 5901 -display : 30810
This starts XVFB and I see:
Now when I connect from Mac to localhost:5901 from VNCviewer, I am taken to Ubuntu desktop.
But I don't see chrome opening up even though the test is running and I see test logs on Jenkins.
I am also able to use Chrome via VncViewer.
What am I missing here?
I tried many Xvfb set up instructions and has been trying to get this right since a month now. Here are few questions I asked:
https://askubuntu.com/questions/1262925/run-selenium-tests-on-ec2-with-gui?noredirect=1#comment2139716_1262925
How to view live headless Selenium tests on EC2-Ubuntu using vncserver and xvfb
https://sqa.stackexchange.com/questions/45376/looking-for-a-solution-to-run-selenium-tests-on-ec2-with-gui/45380#45380
Long way till here and now Stackoverflow is my last resort. Please help.
I found the solution to this myself. For anyone who's having the same issue:
What I did wrong was I used driver = new ChromeDriver(options); in my code instead of driver = new RemoteWebDriver(new URL("http://my.aws.ip:4444/wd/hub"), options);
After making this change, I downloaded selenium-server-standalone.jar to in EC2.
Then, before starting the test, I did ssh -X qa_user#my.aws.ip to EC2 and executed:
Xvfb :99 -ac -screen 0 1280x1024x24 &
export DISPLAY=:99
java -jar /home/qa_user/Selenium/selenium-server-standalone.jar
Now, execute the test, in parallel I opened a new terminal and did:
ssh -L 5900:localhost:5900 qa_user#my.aws.ip
Once the screen was set, I did:
x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :99 -auth /var/run/lightdm/root/:0 -rfbport 5900
Next, open VNC viewer, connect to localhost:5900 and you'll see Chrome execution.
Later you can move all this to Jenkins pre-build execute shell if required :)
More details on my latest answer :
XVFB on Jenkins connecting to wrong display. Display shows black screen
Summary: How do I extract Chromedriver logs when running Selenium standalone Chrome instance? I.e. interacting via Selenium API commonly on port 4444.
Details:
We are using Protractor to connect to a container running the Docker image selenium/standalone-chrome Selenium "grid". Connection info is specified via the HUB_PORT_4444_TCP_ADDR environment variable. The connection URL ends up being http://localhost:4444/wd/hub. This works fine and our tests are running successfully in Jenkins.
For completeness I'd like to extract the Chromedriver logs and attach them to the build in case we need more info for debugging test failues. How can that be done?
This question seemed like a close match but they are running Chromedriver directly. I need to ask Selenium to provide them somehow.
Log properties of standalone chrome container can be configured using JAVA_OPTS.
You can add JAVA_OPTS environment variable to standalone chrome container
name: JAVA_OPTS
value: "-Dwebdriver.chrome.logfile=<Path to log file, with file name>"
We had a shared volume mounted, and gave path to that folder for putting log file.
Used yaml file for creating container template so used in above mentioned way.
If you are using CLI to launch container, same can be passed through CLI too.
I've got a Selenium stand alone server, I run a simple test suite with a simple test case in command line and it works, here is the command line :
java -jar D:\POC\selenium-server-standalone-2.45.0.jar -Dhttp.proxyHost=XXXX -Dhttp.proxyPort=8080 -Dhttp.proxyUser=XXXX -Dhttp.proxyPassword=XXXX -htmlSuite *firefox http://XXXXX D:\Users\XXXX\Desktop\test_selenium.html D:\Users\XXXX\Desktop\result_selenium.html -firefoxProfileTemplate "C:\Users\XXXXX\AppData\Roaming\Mozilla\Firefox\Profiles\1yd4vpna.selenium" -debug
The same command is used by jenkins to run the test, here is the selenium result file :
info: Starting test /selenium-server/tests/test_case_selenium.html
info: Executing: |open | /index.php/fr/ | |
warn: currentTest.recordFailure: Timed out after 30000ms
info: Executing: |clickAndWait | css=li.item-175.first > a.subMenuBtn > span | |
error: Element css=li.item-175.first > a.subMenuBtn > span not found
warn: currentTest.recordFailure: Element css=li.item-175.first > a.subMenuBtn > span not found
When I read command line logs, Jenkins and commandline are different from firefox launch. On command line I can see a firefox poping, not with jenkins.
Without -debug, jenkins stops at "checking resource aliases".
I launched tomcat for jenkins as admin, still got my problem.
Any ideas?
From the paths being referenced, it looks like your Selenium server is in a Windows environment.
Since Selenium interacts with the desktop, make sure that the user account your Jenkins service is running under has the appropriate permissions to do that. (ie, run it as a named account and give that account access to the desktop via Computer Management / Services).
That would explain why you're seeing different behaviour running from the command line (as your user account) compared to in Jenkins (as the Jenkins service user account).
You can try js-code to fix this error. JS-redirect. As:
storeEval window.location="http://yourWebsiteToOpen.com"; js
echo ${js}
At least It helped for us.
Hello people.
I'm using Jenkins as CI server and I need to run some performance test using Jmeter. I've setup the plugin and configured my workspace and everything works ok, but I have to do some steps manually and I want a bit more of "automation".
Currently i have some small programs in a remote server. These programs make some specific validations, for instance (just to explain): validates e-mail addresses, phone numbers, etc.
So, before I run the build in jenkins, I have to manually start the program (file.sh) I want:
I have to use putty (or any othe ssh client) to conect to the server and then run, for instance, the command
./email_validation.sh
And the Jmeter test runs in a correct way, and when the test is done I have to manually "shut down" the program I started. But what I want is trying to start the program I need in Jenkins configuration (not manually outside Jenkins, but in "execute shell" or "execute remote shell using ssh" build step).
I have tried to start it, but it get stuck, because when Jenkins build finds the command
./email_validation.sh
the build stops, it waits for the command to finish and then it will continue the other build steps, but obviously, I need this step not to finish until the test is executed.
Is there a way to achieve this? Thanks
Run your command as a background process by adding the & symbol at the end of the command and use the nohup command in case the parent process gets a hangup signal, e.g.
nohup /path/to/email_validation.sh &
If the script produces any output, it will go by default to the file nohup.out in the current directory when the script was launched.
You can kill the process at the end of the build by running:
pkill email_validation.sh
we are using Jenkins as CI in our project. We were running the CI from the command line using the following command
java -jar C:\\jenkins\\jenkins.war --httpPort=8085 --ajp13Port=8009
As the system needs to restart frequently, we change CI to start as a windows service.
Now we are facing the issues for Selenium test cases. Selenium test cases are not running after we make Jenkins as service. We are getting the following log and no more progress from that point
18:36:30,718 INFO [org.openqa.selenium.server.SeleniumDriverResourceHandler] Command request: getNewBrowserSession[*iexploreproxy, http://192.168.132.105:8080/, ] on session null
18:36:30,718 INFO [org.openqa.selenium.server.BrowserSessionFactory] creating new remote session
18:36:30,796 INFO [org.openqa.selenium.server.BrowserSessionFactory] Allocated session 80b95d0273ac4ea4a82860c79438f071 for http://192.168.132.105:8080/, launching...
18:36:30,796 INFO [org.openqa.selenium.server.browserlaunchers.WindowsProxyManager] Modifying registry settings...
18:36:31,781 INFO [org.openqa.selenium.server.browserlaunchers.InternetExplorerCustomProxyLauncher] Launching Internet Explorer...
Per hudson wiki, you should be running Hudson (or jenkins) as tasks rather than service for GUI testing. Check here. Look at the section GUI Testing in Windows
Following changes will resolve the problem
Update the selenium version.
Use *iexploreproxy or *piiexplore for IE instead of *iehta/*iexplore