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);
Related
I created a selenium cucumber framework that has a test.
The test needs to open chromeDriver, and it is working when I run it in my IDE without any problems.
When I run the project in Jenkins, although the test runs, the chromeDriver doesn't open at all.
The console log is:
17:32:14 Starting ChromeDriver 89.0.4389.23
(61b08ee2c50024bab004e48d2b1b083cdbdac579-refs/branch-heads/4389#{#294})
on port 4816
17:32:14 Only local connections are allowed.
17:32:14 Please see
https://chromedriver.chromium.org/security-considerations for
suggestions on keeping ChromeDriver safe.
17:32:14 ChromeDriver was started successfully.
Of course, this log is shown in my ide with the difference that chromeDriver opens in IDE mode and doesn't open in Jenkins mode.
What can I do?
First of all you should add more description, like:
what language do you use?
how start driver in your code?
do you use local driver or remote one?grid or selenoid?
do you use --headless mode on jenkins?
does jenkins have Xs for running browser?
There's bunch of solving, but each of them is based on more particular description:
Best way, but a bit tricky/expensive:
launch own Grid/Seleloid server on ec2 instance on any cloud platform you like: GCP, AWS, Azure, DigitalOcean etc
install docker and launch selenoid intance
launch selenoid application by downloading from github release page:
chmod +x cm
./cm selenoid start --vnc
get its IP and provide it to your driver creation command
which looks like that:
java:
WebDriver driver = new RemoteWebDriver(new URL(SelenoidIP/wd/hub), firefoxOptions);
driver.get("http://www.google.com");
driver.quit();
ruby:
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :remote, url: SelenoidIP/wd/hub
driver.get "http://www.google.com"
driver.close
python:
from selenium import webdriver
driver = webdriver.Remote(
command_executor=SelenoidIP/wd/hub)
driver.get("http://www.google.com")
driver.quit()
Update:
I found a better solution.
Start Jenkins as a process from command line, not as a service, to get Chrome to open.
https://stackoverflow.com/a/41457823/1691651
command line commands:
Jenkins.exe stop
java -jar Jenkins.war
To save your Jenkins configurations, create an Environment Variable for JENKINS_HOME that points to location listed on the "Configure Jenkins" setting.
Old answer:
This also happened to me in webdriver.io when using the "chromedriver" service. To solve it, I had to manually download the chromedriver at https://chromedriver.chromium.org/downloads and then run it via a terminal--I don't know why that fixed it.
I don't need to run chromedriver separately in a terminal when testing via command line on the same EC2 instance.
WebDriver cannot be initialised when selenium-server-standalone is run as Windows service.
I'm connecting with Windows machine from Jenkins on centOS using SSH.
On Windows I installed selenium-server-standalone as service using nssm, so I run following command:
nssm start SeleniumWebDriver
The service is run as the same local Windows user that I'm using to log in.
The command is working correctly as I can see the process running in Task Manager and I'm able to access the hub and create the Chrome session.
But when the next step in Jenkins job is run, that is tests, it fails immediately because the WebDriver cannot be initialised.
When I run manually on Windows selenium-server-standalone (not as a service), the tests are executed because Chrome is being open. When run through service, Chrome is open but somewhere in the background (probably another session) and I and the tests cannot see the window.
How to change it to make the Chrome appearing so the WebDriver could be initialised and GUI actions be performed?
I have test classes written in java for UI testing using Maven using Selenium Web-Driver. I want to run them using mvn test command in Jenkins.
It is not able to launch the browser for the testing.
The error stack shown is something like this:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: no display specified
Error: no display specified
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:106)
Any help on this will be appreciated.
Firefox needs a X display to run, e.g. Xvfb
You will need to
install xvfb on your server. Doing this depends on your server operating system (and package management)
start xvfb before the build. You can do this using the xfvb plugin, or by running Xvfb as a daemon. I personally like to use the plugin.
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.
I'm trying to solve a problem and I was hoping I could do it with Selenium Grid but I'm not entirely sure that it's possible. Here's my problem...I'm developing test cases using Selenium WebDriver and I need my tests to run on a Windows machine however the AUT runs on a Linux server. I have several tools that only run on Linux and I would like to be able to run some commands/tests on the Windows machine and others in the Linux server. For instance
Test Starts -> Firefox launches (Windows machine)
Login to site (Windows machine)
Run command in Linux server
Return running commands/tests on the Windows box.
Alternatively I could figure out how to run those commands remotely from a Windows machine but I'm not looking forward to doing that.
Out of the box, you cannot use selenium to run commands on your local machine. Selenium/Webdriver is a browser testing tool and can interact only with browser.
Updated Answer based on your comments
Common part to both ways (which I think you already know)
In your java code you should have the code for webdriver/selenium commands that will do step 1 and 2. Your java code should also the contain the logic/code to execute the linux commands as step 3. Step 4 should again be your webdriver command.
This test code should run from the linux server so that the java command execution will happen in the linux box.
Now the only pending part is the execution of test in remote machine.
Method 1 without using grid
Start the selenium server in the windows machine. Point your java tests to the selenium server running in this machine. If your windows machine IP is 10.0.0.1, you should initialize the webdriver object as
WebDriver wd = new RemoteWebDriver(new URL("http://10.0.0.1:4444/wd/hub"),DesiredCapabilities.Firefox());
This will send all your webdriver commands to the selenium server running in 10.0.0.1 on port 4444. Your tests will then get executed in the windows machine. For this to work, your linux server and windows machine should be in same network.
Method 2 using grid.
Its all the same as above, but instead of giving the ip/dns name of windows machine, you should give the ip/dns name of the hub machine. You should also have windows machine registered as an RC to that hub.
I think with AutoIT kind of windows frameworks, we can invoke C:\Windows\System32\cmd.exe to open a command prompt and run some .bat files. If it is Linux /bin/csh or /bin/bash myscript.sh.