selenium server, selenium client, on an UBUNTU GUI server - java

i have a VPS with ubuntu 14.04 LTS and with the desktop package installed, that mean I can launch firefox from a ssh -X session.
To make tests, I launched from my server the selenium standalone server jar (selenium-server-standalone-3.0.0-beta3.jar)
After launching it, in another ssh session, i just enter python commands :
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
And after that, following the instructions from
http://selenium-python.readthedocs.io/getting-started.html#using-selenium-with-remote-webdriver, I enter :
driver = webdriver.Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=DesiredCapabilities.FIREFOX)
After 45sec, i have lots of errors in both server window and client window.
Here is the main error :
Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: GDK_BACKEND does not match available displays
I saw some people with the same problem, but even with the latest java and selenium versions, i still got this issue.
Thank you in advance for your help

It seems you're trying selenium 3 with latest firefox version. To support latest firefox with selenium 3, need to download latest geckodriver executable from this link and extract it into you system at any location.
Now to run selenium-server-standalone-3.0.0-beta3.jar use below command :-
java -jar selenium-server-standalone-3.0.0-beta3.jar -Dwebdriver.gecko.driver = "path/to/downloaded geckodriver"
Now you need to set capability with marionette property to true to support latest firefox with selenium 3 as below :-
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.FIREFOX
# Tell the Python bindings to use Marionette.
caps["marionette"] = True
driver = webdriver.Remote(command_executor = 'http://127.0.0.1:4444/wd/hub', desired_capabilities = caps)
Note :- For more information about marionette follow this Mozilla official page

Related

Selenium code is not opening firefox browser when running selenium code in Jenkins server as Job

I have the below code in Selenium/Java test class. Now, this code I have pushed to GitHub.
Also, I have set up the Jenkins job to execute the same code (in the Jenkins job I have pointed the code to GitHub).
The Jenkins job is triggering fine and started executing the test, but throwing below error while opening the browser.
The test case is supposed to open the Firefox browser, but the Firefox browsing is not opening.
So, my question is, whether the below selenium code is correct if I want to execute the test case in Jenkins job (Jenkins server is running in Cento7.4 OS).
NOTE: In the same CentOS VM, I am able to execute the same (below) selenium code in eclipse and it's able to open the Firefox browser and open the URL without any issues.
The issue is coming only if I try to run the same code in the Jenkins server as a Jenkins job.
Selenium code
System.setProperty("webdriver.gecko.driver", "geckodriver");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.addArguments("--display=0");
WebDriver driver = new FirefoxDriver(firefoxOptions);
driver.get("https://www.facebook.com");
Jenkins job output
Running TestSuite
Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
1597912923234 mozrunner::runner INFO Running command: "/bin/firefox" "-marionette" "--display=0" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileFz0Zr2"
Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Running without a11y support!
Error: cannot open display: 0
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.972 sec <<< FAILURE!
Results :
Failed tests: loginTest4(com.training.browsers.LinuxTest): invalid argument: can't kill an exited process
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[ERROR] There are test failures.
xauth list output
[root#localhost ~]# xauth list
localhost.localdomain/unix:0 MIT-MAGIC-COOKIE-1 4eb74af687f2dbc022ef03617614456e
#ffff#6c6f63616c686f73742e6c6f63616c646f6d61696e#:0 MIT-MAGIC-COOKIE-1 4eb74af687f2dbc022ef03617614456e
You may want to look into setting up xvfb (https://centos.pkgs.org/7/centos-x86_64/xorg-x11-server-Xvfb-1.20.4-10.el7.x86_64.rpm.html). The problem is that your Jenkins server cannot open display 0 to run in. Notice the parameters being sent in to the firefox binary specifying display 0 in your firefoxOptions match the INFO log line for the binary execution. Assuming that you are running a headless server and this is why you get this error. The same is not the case when running locally.
With xvfb you should be able to specify a screen number and set your configurations accordingly or simply use xvfb-run.
The test case is supposed to open the Firefox browser, but the Firefox browsing is not opening.
To resolve this issue, use WebDriverManager to automate the management of the drivers (e.g. chromedriver, geckodriver, etc.) required by Selenium WebDriver.
To use WebDriverManager in a Maven project, add the following dependency in your pom.xml (Java 8 or upper required).
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>4.2.2</version>
</dependency>
Then simply add WebDriverManager.firefoxdriver().setup(); in your code as shown below:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import io.github.bonigarcia.wdm.WebDriverManager;
WebDriverManager.firefoxdriver().setup();
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.addArguments("--display=0");
WebDriver driver = new FirefoxDriver(options);
See the basic examples of running JUnit 4 tests on Firefox and Chrome using WebDriverManager here.
--display=n
The phrase display is used to refer to collection of monitors that share a common keyboard and pointer e.g. mouse, tablet, etc. Most workstations tend to only have one keyboard, and therefore, only one display. Multi-user systems, frequently have several displays and each display on a machine is assigned a display number (beginning at 0) when the X server for that display is started. display:0 is usually the local display i.e. the main display of the computer.
Using Jenkins
When Jenkins executes the batch file, Jenkins slave runs as service in the background for every program it initiates. So normally you won't be able to visualize the Firefox browser spinning up but in the task manager you can see Jenkins opens several Firefox processes in background.
Solution
There are a couple of approaches to address this issue as follows:
If you are using Jenkins as a windows service you need to Allow service to interact with desktop. Steps:
In windows service select the service of Jenkins:
Open properties window of the Jenkins service -> Logon-> enable the checkbox Allow service to interact with desktop
In this approach autolaunch of dbus-daemon works when under an X11 session, else it is disabled because there's no way for different applications to establish a common instance of the dbus daemon.
You can find a relevant detailed discussion in Jenkins : Selenium GUI tests are not visible on Windows
The other approach would be to run Jenkins from command prompt as java -jar jenkins.war instead of the windows installer version.
Another approach will be to use RemoteWebDriver. From Jenkins, make sure there is a machine where the selenium tests can run. On this server you spin up the firefox browser.
You can find a relevant detailed discussion in How to launch chrome browser from Jenkins directly instead of using code in eclipse
An alternative would be to invoke firefox-headless browser by setting setHeadless as true through an instance of FirefoxOptions() class as follows:
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.com/");
You can find a relevant detailed discussion in How to make Firefox headless programmatically in Selenium with Python?
invalid argument: can't kill an exited process
This error is commonly observed in the two following cases:
When you are executing your tests as a root/admin user. It is recommended to execute your tests as a non-root/non-admin user.
When there is an incompatibility between the version of the binaries you are using.
You can find a detailed discussion in WebDriverException: Message: invalid argument: can't kill an exited process with GeckoDriver, Selenium and Python on RaspberryPi3

Selenium Chrome webdriver SessionNotCreatedException

Using selenium & Chrome webdriver, I'm getting below exception on trying to launch. I have gone through lot of posts and tried all possible ways.
I'm using compatible chrome browser and chrome drivers versions -
Version 80.
Java - 1.8
Windows 10 os
The same test when i run on my personal computer, its working. But it's giving below error on my organization s machine. Also, no issues if I use edge drivers.
org.openqa.selenium.SessionNotCreatedException: session not created
disconnected: unable to send message to renderer
Any thoughts to solve this?
Check for chromedriver version in organization's machine. Please update your chromedriver with lastest version in organization machine. Issue will get resolve
The ChromeDriver Version you are using in your code might be different than the Chrome Browser installed in your system.
Check and download the same version of driver as of your browser version.
You need to use the matching ChromeDriver (matching MAX number) with respect to the installed google-chrome version installed in your system.
As an example if you are using the current chrome=88.0.4324.104 effectively you can use either of the following versions of ChromeDriver:
ChromeDriver 88.0.4324.27
ChromeDriver 88.0.4324.96
References
You can find a couple of relevant detailed discussions in:
SessionNotCreatedException: Message: session not created from disconnected: unable to connect to renderer with ChromeDriver 2.45 Chrome v71
WebDriverException: disconnected: unable to connect to renderer even on providing correct path of latest chromedriver
Automation Testing Error : org.openqa.selenium.WebDriverException: disconnected: unable to connect to renderer

org.openqa.selenium.SessionNotCreatedException: session not created disconnected:unable to send message to renderer error with ChromeDriver and Chrome

I try to run this simple program on Java with Selenium:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class MySelenium {
public static void main(String[] args) {
System.out.println("First Selenium");
System.setProperty("webdriver.chrome.driver", "C:\\automation\\drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.seleniumhq.org/");
driver.quit();
}
}
But on running shows the following error:
How can i fixed this error ?
This error message...
org.openqa.selenium.SessionNotCreatedException: session not created
disconnected: unable to send message to renderer
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
I suspect your main issue is the incompatibility between the version of the binaries you are using.
As per the snapshot you have provided the following set of binaries you are using looks fine to me:
JDK: 1.8.0_191
Selenium: 3.14.0
ChromeDriver: 2.43
Chrome: 69.0
Analysis & Solution
As per Unable to receive message from renderer error using chrome driver 2.27 another pottential reason can be presence of antivirus within your localhost which you need to disable.
Ensure that /etc/hosts on your system contains the following entry:
127.0.0.1 localhost.localdomain localhost
#or
127.0.0.1 localhost loopback
Keep Chrome version between Chrome v68-70 levels. (as per ChromeDriver v2.43 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
(WindowsOS only) Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
(LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint before and after the execution of your Test Suite.
If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test.
Reference
You can find a related discussion in Automation Testing Error : org.openqa.selenium.WebDriverException: disconnected: unable to connect to renderer
tl;dr
As per ChromeDriver 2.34 doesn't wait until iframe content loads after switching into iframe this issue was also observed with ChromeDriver 2.38 and Chrome 67+ combo and was related to static iframes (part of the originally loaded DOM) which seem to work correctly even till Chrome 66.
Try using JDK 1.8.0_181. I had the same issue after updating to JDK 1.8.0_191.

Selenium 2.53 not working on Firefox 47

I am getting error while using Firefox with WebDriver.
org.openqa.selenium.firefox.NotConnectedException: Unable to connect
to host 127.0.0.1 on port 7055 after 45000 ms.
Firefox version:47.0
Selenium:2.53.0
Windows 10 64 bit
Is anyone getting a similar issue or any idea what is the solution for this? It's working fine with Chrome but with Firefox none of the URLs are getting loaded.
Unfortunately Selenium WebDriver 2.53.0 is not compatible with Firefox 47.0. The WebDriver component which handles Firefox browsers (FirefoxDriver) will be discontinued. As of version 3.0, Selenium WebDriver will need the geckodriver binary to manage Firefox browsers. More info here and here.
Therefore, in order to use Firefox 47.0 as browser with Selenium WebDriver 2.53.0, you need to download the Firefox driver (which is a binary file called geckodriver as of version 0.8.0, and formerly wires) and export its absolute path to the variable webdriver.gecko.driver as a system property in your Java code:
System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver");
Luckily, the library WebDriverManager can do this work for you, i.e. download the proper Marionette binary for your machine (Linux, Mac, or Windows) and export the value of the proper system property. To use this library, you need to include this dependency into your project:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.1.0</version>
</dependency>
... and then execute this line in your program before using WebDriver:
WebDriverManager.firefoxdriver().setup();
A complete running example of a JUnit 4 test case using WebDriver could be as follows:
public class FirefoxTest {
protected WebDriver driver;
#BeforeClass
public static void setupClass() {
WebDriverManager.firefoxdriver().setup();
}
#Before
public void setupTest() {
driver = new FirefoxDriver();
}
#After
public void teardown() {
if (driver != null) {
driver.quit();
}
}
#Test
public void test() {
// Your test code here
}
}
Take into account that Marionette will be the only option for future (for WebDriver 3+ and Firefox 48+), but currently (version 0.9.0 at writing time) is not very stable. Take a look to the Marionette roadmap for further details.
UPDATE
Selenium WebDriver 2.53.1 has been released on 30th June 2016. FirefoxDriver is working again with Firefox 47.0.1 as browser.
Try using firefox 46.0.1. It best matches with Selenium 2.53
https://ftp.mozilla.org/pub/firefox/releases/46.0.1/win64/en-US/
I had the same issue and found out that you need to switch drivers because support was dropped. Instead of using the Firefox Driver, you need to use the Marionette Driver in order to run your tests. I am currently working through the setup myself and can post some suggested steps if you'd like when I have a working example.
Here are the steps I followed to get this working on my Java environment on Mac (worked for me in my Linux installations (Fedora, CentOS and Ubuntu) as well):
Download the nightly executable from the releases page
Unpack the archive
Create a directory for Marionette (i.e., mkdir -p /opt/marionette)
Move the unpacked executable file to the directory you made
Update your $PATH to include the executable (also, edit your .bash_profile if you want)
:bangbang: Make sure you chmod +x /opt/marionette/wires-x.x.x so that it is executable
In your launch, make sure you use the following code below (it is what I used on Mac)
Quick Note
Still not working as expected, but at least gets the browser launched now. Need to figure out why - right now it looks like I need to rewrite my tests to get it to work.
Java Snippet
WebDriver browser = new MarionetteDriver();
System.setProperty("webdriver.gecko.driver", "/opt/marionette/wires-0.7.1-OSX");
If you're on OSX using Homebrew, you can install old Firefox versions via brew cask:
brew tap goldcaddy77/firefox
brew cask install firefox-46 # or whatever version you want
After installing, you'll just need to rename your FF executable in the Applications directory to "Firefox".
More info can be found at the git repo homebrew-firefox. Props to smclernon for creating the original cask.
If you're on a Mac do brew install geckodriver and off you go!
In case anyone is wondering how to use Marionette in C#.
FirefoxProfile profile = new FirefoxProfile(); // Your custom profile
var service = FirefoxDriverService.CreateDefaultService("DirectoryContainingTheDriver", "geckodriver.exe");
// Set the binary path if you want to launch the release version of Firefox.
service.FirefoxBinaryPath = #"C:\Program Files\Mozilla Firefox\firefox.exe";
var option = new FirefoxProfileOptions(profile) { IsMarionette = true };
var driver = new FirefoxDriver(
service,
option,
TimeSpan.FromSeconds(30));
Overriding FirefoxOptions to provide the function to add additional capability and set Firefox profile because selenium v53 doesn't provide that function yet.
public class FirefoxProfileOptions : FirefoxOptions
{
private DesiredCapabilities _capabilities;
public FirefoxProfileOptions()
: base()
{
_capabilities = DesiredCapabilities.Firefox();
_capabilities.SetCapability("marionette", this.IsMarionette);
}
public FirefoxProfileOptions(FirefoxProfile profile)
: this()
{
_capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile.ToBase64String());
}
public override void AddAdditionalCapability(string capabilityName, object capabilityValue)
{
_capabilities.SetCapability(capabilityName, capabilityValue);
}
public override ICapabilities ToCapabilities()
{
return _capabilities;
}
}
Note: Launching with profile doesn't work with FF 47, it works with FF 50 Nightly.
However, we tried to convert our test to use Marionette, and it's just not viable at the moment because the implementation of the driver is either not completed or buggy. I'd suggest people downgrade their Firefox at this moment.
New Selenium libraries are now out, according to: https://github.com/SeleniumHQ/selenium/issues/2110
The download page http://www.seleniumhq.org/download/ seems not to be updated just yet, but by adding 1 to the minor version in the link, I could download the C# version: http://selenium-release.storage.googleapis.com/2.53/selenium-dotnet-2.53.1.zip
It works for me with Firefox 47.0.1.
As a side note, I was able build just the webdriver.xpi Firefox extension from the master branch in GitHub, by running ./go //javascript/firefox-driver:webdriver:run – which gave an error message but did build the build/javascript/firefox-driver/webdriver.xpi file, which I could rename (to avoid a name clash) and successfully load with the FirefoxProfile.AddExtension method. That was a reasonable workaround without having to rebuild the entire Selenium library.
Its a FF47 issue
https://github.com/SeleniumHQ/selenium/issues/2110
Please downgrade to FF 46 or below (or try out FF48 developer https://developer.mozilla.org/en-US/Firefox/Releases/48)
Instructions on how to downgrade:
https://www.liberiangeek.net/2012/04/how-to-install-previous-versions-of-firefox-in-ubuntu-12-04-precise-pangolin/
Or if you are on Mac, as suggested by someone else in this thread use brew.
Firefox 47.0 stopped working with Webdriver.
Easiest solution is to switch to Firefox 47.0.1 and Webdriver 2.53.1. This combination again works. In fact, restoring Webdriver compatibility was the main reason behind the 47.0.1 release, according to https://www.mozilla.org/en-US/firefox/47.0.1/releasenotes/.
You can try using this code,
private WebDriver driver;
System.setProperty("webdriver.firefox.marionette","Your path to driver/geckodriver.exe");
driver = new FirefoxDriver();
I upgraded to selenium 3.0.0 and Firefox version is 49.0.1
You can download geckodriver.exe from https://github.com/mozilla/geckodriver/releases
Make sure you download zip file only, geckodriver-v0.11.1-win64.zip file or win32 one as per your system and extract it in a folder.
Put the path for that folder in the "Your path to driver" quotes.Don't forget to put geckodriver.exe in the path.
I eventually installed an additional old version of Firefox (used for testing only) to resolve this, besides my regular (secure, up to date) latest Firefox installation.
This requires webdriver to know where it can find the Firefox binary, which can be set through the webdriver.firefox.bin property.
What worked for me (mac, maven, /tmp/ff46 as installation folder) is:
mvn -Dwebdriver.firefox.bin=/tmp/ff46/Firefox.app/Contents/MacOS/firefox-bin verify
To install an old version of Firefox in a dedicated folder, create the folder, open Finder in that folder, download the Firefox dmg, and drag it to that Finder.
Here's what the problem looked like in Wireshark
Just load up 2.53.1 and every thing will work.
As of September 2016
Firefox 48.0 and selenium==2.53.6 work fine without any errors
To upgrade firefox on Ubuntu 14.04 only
sudo apt-get update
sudo apt-get upgrade firefox
It seems to me that the best solution is to update to Selenium 3.0.0, download geckodriver.exe and use Firefox 47 or higher.
I changed Firefox initialization to:
string geckoPathTest = Path.Combine(Environment.CurrentDirectory, "TestFiles\\geckodriver.exe");
string geckoPath = Path.Combine(Environment.CurrentDirectory, "geckodriver.exe");
File.Copy(geckoPathTest, geckoPath);
Environment.SetEnvironmentVariable("webdriver.gecko.driver", geckoPath);
_firefoxDriver = new FirefoxDriver();
I can confirm that selenium 2.53.6 works with firefox 44 for me on ubuntu 15.

Trouble in launching of firefox browser using selenium for MAC OS

I am using Selenium to test a website in Java and trying to run it in Firefox on a MAC. But when I am trying to execute the code below
Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.example.com/");
I am getting the following runtime exception
java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Browser not supported: /Users/sumitghosh/Desktop/*firefox3
(Did you forget to add a *?)
Supported browsers include:
*firefox
*mock
*firefoxproxy
*pifirefox
*chrome
*iexploreproxy
*iexplore
*firefox3
*safariproxy
*googlechrome
*konqueror
*firefox2
*safari
*piiexplore
*firefoxchrome
*opera
*iehta
*custom
I have also tried changing the browser to *googlechrome, but the same error was firing!
But when *safari was used it ran successfully.
Since I want the application to run on Windows and MAC also, I was trying for *firefox or *googlechrome to run, but both browsers are giving exceptions both on Windows and MAC!
I have only ever got firefox 3.X to work on MACOSX with selenium.
Try downloading and installing a 3.X version (I got 3.18 to work).
Instead of "*firefox" you can try "*firefox /Apps/Firefox/firefox.exe" or any other absolute path to the file firefox.exe which works for your computer.

Categories