Jenkins running selenium tests without opening browser - selenium

I browsed a lot on this topic. There are different variations of this question or no answer to fix my issue. Any help is appreciated.
I have installed firefox on my VM as root in /usr/bin/firefox.
I downloaded the maven project to run selenium tests, and run it
manually on my VM using mvn clean install command. This opens the
browser and also successfully runs the test.
Now I run Jenkins as myself ( JAVA_HOME is /usr/java/latest and started the service as
nohup java -jar jenkins.war --httpPort=-1 --httpsPort=8082; version
is 1.522).
Create a new freestyle s/w project; Configure the job
to download the maven project and invoke maven target 'clean
install';
When I run the job, I can see the steps in the console
output but the browser is not opening. It also locks up my AD account.
Why is this happening? What is the fix?

nohup runs Jenkins in the background (http://en.wikipedia.org/wiki/Nohup), in which case according to this post Jenkins will start the browser in the background as well.
Try starting jenkins without nohup so that it runs in the foreground (java -jar jenkins.war --httpPort=-1 --httpsPort=8082).
Or you can start Jenkins as a daemon (this Jenkins Wiki page contains an example of init script). When Jenkins is started as daemon, the browser started by its job is visible.

Related

Running EdgeDriver in Jenkins

I have Selenium tests that I am running through Jenkins on a build server. The tests all run as expected in Chrome (using ChromeDriver) and Firefox (using FirefoxDriver). However, the tests don't run in Edge using EdgeDriver.
When the tests run it gives an error:
Microsoft Web Driver can't be used with the Built-In Administrator account or while User Account Control is turned off.
I have tried turning UAC on, but that no effect. I tried running the Jenkins service as a different user and that also had no effect. I've tried the suggestions from: MicrosoftWebDriver fails when constructing while running under TeamCity agent's windows service
I can run the tests in the same location from a command prompt, just not through Jenkins.
If you configure jenkins slave agent as a windows services, Will get the issues. Because Edge won't run as a headless browsers.
For avoid those issues. we are not suppose to set a slave agent as window services.
Follow the below steps for setup slave agent and then run your script:
***** Then download the agent.jar and place it under jenkins working directory("D:/Jenkins")
***** Open the command prompt as admin user and execute the commands.
java -jar agent.jar -jnlpUrl http://srv-cbe-com4:8080/computer/T/slave-agent.jnlp -secret 07ba92bb8017901287acb979cf30d40a45c17abd2c0edba5b2b3f17cc94915e8 -workDir "D:/Jenkins"

Browser is not launching even test is running through Jenkins on ubuntu

I am trying to launch browser for automation testing(selenium) using jenkins on ubuntu OS. Test are running properly but browser is not launching seems like it is running headlessly.
I am able to fix this using this solution -
Added Xvfb plugin and added DISPLAY variable.
Running jenkins.war
from console using java -jar jenkins.war
As I know in Windows OS by checking "Allow service to interact with desktop" while jenkins installation we can fix this. So Is there any way we can do this on ubuntu by updating some configuration so we don't have run jenkins.war from console everytime.
There are two ways to facilitate the launch of browser on ubuntu OS.
1.First way - Configure your Jenkins nodes and add the ubuntu machine. Add the sshing details(username-password OR RSA key) of the target machine. This configuration is recommended if you are in cloud.
2.Second way(not recommended on cloud environments) -You have to run a Selenium standalone-Server (a standalone node), and register your remote WebDriver to it.
WebDriver driver = new RemoteWebDriver(new URL("http://ipOfUbuntuMachine:port/wd/hub"), capability);

how to stop and resume jenkins service

I got confused, how to stop/start the Jenkins after I have installed jenkins.war on my terminal with this script
java -jar jenkins.war -httpPort=8080
cause if run above code again, could be error cause port already in use. I can uninstall it, but it's like wasting time if I need Jenkins I must uninstall it and then install again. need someone that knows how to stop/start command without uninstall the installed jenkins
thanks
if you have administrative right you should be able to access the following URL. Just confirm the restart.
http://<Jenkins_IP>/restart
i would explain the step, i install my jenkins as admin
http://localhost:8080/exit [login to jenkins first]
close your terminal
open your terminal and go to your directory .war file
run java -jar jenkins.war -httpPort=8080
http://localhost:8080/restart

how to upload a file to selenium test running in docker

Am running my selenium java tests in Docker's chrome container installed in my windows system.
Tests to upload will pass if i run tests in windows - chrome, but failing with error path is not absolute: D:\xyz.csv if i run same tests in docker.
Am pushing my tests on chrome node in docker.
Normal selenium tests work in docker, but upload doesn't.
Please suggest on how to copy this file inside container to give that path for upload tests..
Thanks
That is because Chrome would look for that path in the system where it. But the container is a linux based system and the file paths are not like this.
So you need to share volume while launching the chrome container
docker run -v localfolder:containerfolder
and in your test you need to use the contaienrfolder path and not the localfolder path
I got the solution of this problem long time back.
Use below command to copy the files from windows/Linux system to Chrome container running in docker's say 'tmp' folder , this path can be later referenced in selenium tests running in Docker.
"docker cp D:\file.csv docker_chrome_1:/tmp/"
This above command can be run once Docker's Chrome container is up and running in Windows/Linux machine.

Selenium server cannot be started inside Bamboo

I am trying to configure a Selenium testing through Bamboo. I am able to run Selenium scripts directly from command line, however it always fails if I run it through Bamboo remote agent. The error is:
: Could not start Selenium session: Failed to start new browser session: Error while launching browser
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:107)
I took some advice from the web, and checked "Allow service to interact with desktop" for Bamboo remote agent service. However, it does not work.
Anyone have other suggestions?
You must run Bamboo in Console Mode for this to work. Also, the build machine desktop must be active - and not covered or minimized if you want mouse simulations to work. I know right!