Selenium RemoteWebDriver giving UnreachableBrowserException - selenium-webdriver

I am implementing selenium grid and the capability to launch the tests on a remote machine using the RemoteWebDriver.
I am invoking the RemoteWebDriver instance as in:
private static String browserType = "firefox";
public static boolean setup(String browserType) throws Exception,MalformedURLException {
try {
logger.debug("Launching the browsersession");
DesiredCapabilities capability= new DesiredCapabilities();
capability.setBrowserName(browserType);
webdriver1 = new RemoteWebDriver(new URL("http://www.ipaddress.com:4444/wd/hub"), capability);
}
webdriver1.get(http://url of the webserver);
}
I started the selenium-standalone as hub with
java -jar selenium-server-standalone-2.30.0.jar -role hub
and the node as
java -Dwebdriver.chrome.driver=C:/Chrome/chromedri
ver.exe -jar selenium-server-standalone-2.30.0.jar -role webdriver -hub http://www.ipaddress.com:4444/grid/register -port 5555 -browser browserName=chrome
Hub was giving an error: INFO: I/O exception (java.net.SocketException) caught when connecting to the tar
get host: Permission denied: connect
When I run the tests from Eclipse, there is an exception:
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Has anyone encountered this error? Appreciate any suggestions

Just setting browsername doesn't suffice. You need to set the browser that you need to use. for eg.
DesiredCapabilities capability = DesiredCapabilities.firefox();
Browsername would just help shortlist the node the test should go to.
Please refer here to get started.

Related

unable to Launch Selenium Script in Grid

i have started selenium server hub by running command :
java -jar selenium-server-standalone-3.4.jar -port 4444 -role hub
i have also connected node by running the command : java -jar selenium-server-standalone-3.4.0.jar -role node -hub http://XXX.XXX.XXX.XXX:4444/grid/register/ -browser -browserName=firefox -port 5580
in grid console its showing v:null(don't know why?).
i am runing below code to run selenium :
public static void main(String[] args) throws MalformedURLException, InterruptedException{
String URL = "http://www.DemoQA.com";
String Node = "http://localhost:4444/wd/hub";
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setBrowserName("firefox");
cap.setPlatform(Platform.WIN10);
driver = new RemoteWebDriver(new URL(Node), cap);
driver.navigate().to(URL);
Thread.sleep(5000);
driver.quit();
}
`
gettinf these errors, someone please help with these?.
many thanks in adc
Grid console shows no instance for Firefox is the issue you faced. There seems to be some issue with your node.
Check the node registration command.
java -jar selenium-server-standalone-3.4.0.jar -role node -hub http://XXX.XXX.XXX.XXX:4444/grid/register/ -browser browserName=firefox,platform=WINDOWS,maxInstances=2
Try removing the - before browserName in the command.
The error message Error forwarding the new session cannot find is the Grid's way of telling you that whatever you requested for, the hub couldn't find any node that supports that capability.
In your case, when you did this
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setBrowserName("firefox");
cap.setPlatform(Platform.WIN10);
You are basically telling the hub that you need a node that can support a browser with its name as firefox and the node should be running on a Windows 10 Operating system.
But in your node starting command, you used this
java -jar selenium-server-standalone-3.4.0.jar -role node -hub http://XXX.XXX.XXX.XXX:4444/grid/register/ -browser -browserName=firefox -port 5580
which means you registered a node which supports firefox browsers, to the Hub, but you never mentioned anything about the platform. So the node assumes the platform to be "any".
Now when you created a new RemoteWebDriver instance, the Hub tried matching the requested capabilities with the available capabilities of every node. Since it didn't find any node that runs on Windows 10 and supports firefox (Remember you only have a node that supports firefox and whose platform is not set), the matching fails because "ANY" is not a match with "WIN10".
To fix the problem, please remove the line cap.setPlatform(Platform.WIN10); and try again.
PS :
The line DesiredCapabilities cap = DesiredCapabilities.firefox(); already figures out the browser name, so you don't need to explicitly set the browser name via cap.setBrowserName("firefox");

Unable to understand WebDriver execption?

I am getting Web-driver exception while running a selenium code for grid.Here is code detail:
Chrome Version : 58.0.3029.110 (64-bit)
Selenium server : 3.4.0
#Test
public void Testgrid() throws MalformedURLException{
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setBrowserName("chrome");
cap.setPlatform(Platform.ANY);
cap.setCapability("binary", "C:\\Program Files(x86)\\Google\\Chrome\\Application\\chrome.exe");
RemoteWebDriver driver = new RemoteWebDriver(newURL("http://localhost:4444/wb/hub"), cap);
driver.get("https://www.simplesite.com/pages/service-login.aspx");
driver.manage().window().maximize();
}
Exception:
org.openqa.selenium.WebDriverException: Unable to parse remote response:
Try with this :
System.setProperty("webdriver.chrome.driver", "E://chromedriver.exe");
set this property in your code before DesiredCapabilities.
or in node command give this command:
java -Dwebdriver.gecko.driver=E:\chromedriver.exe -jar selenium-server-standalone-3.5.0.jar -role node -hub http://localhost:4444/grid/register -port 4422
this worked for me once. I am not sure of using -Dwebdriver.gecko.driver=E:\chromedriver.exe here , you can edit it to -Dwebdriver.chrome.driver=E:\chromedriver.exe

IE Opens When I Use ChromeWebdriver

I have tried searching, but have had no luck in finding a solution. I trying to get Selenium Grid to work on my local machine before placing nodes on other machines. Long story short when I try using the chromewebdriver IE opens.
Everything compiles but IE opens and not chrome. While trying to find the problem I used the driver.getCapabilities().getBrowserName() and it showed internetexplorer. I tried looking through the remoteWebDriver class but could not find where its capability was set to IE.
I've also tried coping and running some code from similar questions, but IE still opens. Any help would be appreciated.
Hub:
java -jar selenium-server-standalone-2.31.0.jar -role hub -port 4444
Nodes:
java -jar selenium-standalone-2.31.0.jar -role node -port 5555 -hub http://localhost:4444/grid/register -browser browserName=chrome,platform=WINDOWS -browser browserName=firefox,platform=WINDOWS
(I have also tried adding -Dwebdriver.chrome.driver={path to web driver} but had no luck)
Code:
WebDriver driver;
#Before
public void setUp()throws java.net.MalformedURLException{
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setBrowserName("Chrome");
capability.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new java.net.URL("http://localhost:5555/wd/hub"), capability, capability);
driver.get("http://book.theautomatedtester.co.uk/chapter1");
}
Browser you registered was under the name "chrome" and capability has "Chrome". Ideally this should throw a no browser available

Not able to register selenium webdriver node on VM to the hub on Host

I have a host with IP 192.168.3.146. This IP is a static IP given from DHCP server.
Now I have VM with network configured as Bridged.
I am seeing the IP as 10.0.2.15.
Since it's bridged should I be getting anything in the range 192.168.3.x assigned to the VM as well?
When I register from this VM to the host I am not able to register the web driver, it just says "Registering" and does nothing until I kill it.
Command used to register the node:
java -jar selenium-server-standalone-2.26.0.jar -role web driver -hub http:/192.168.3.146:4444/grid/register -port 5558 -host 10.0.2.15 -browser "browserName=firefox, version=6, platform=WINDOWS"
Also tried:
java -jar selenium-server-standalone-2.26.0.jar -role node -port 5558 -hub http:/192.168.3.146:4444/grid/register
NOTE: in both commands http:/ is deliberate - please ignore it. I'm actually using // since I was getting error while posting I have used :/
Any suggestions please?
The easiest way to get this setup is to use NAT Networking, and local port forwarding. What's nice about this setup is that you can run everything offline, and not rely on a constantly changing dynamic IP address. Here's how you do that:
Configure the Guest VM to use NAT Networking, add Port Forwarding rules for ports 4444 and 5555.
Host Machine, as Hub
java -jar selenium-server-standalone.jar -role hub -port 4444
Guest Machine, as Node
java -jar selenium-server-standalone.jar -role node -host 127.0.0.1 -port 5555 -hub http://10.0.2.2:4444/grid/register
I use this setup to run multiple instances of the modern.ie VM machines in VirtualBox, and it works very nicely.
hmmmmm....
how about simply running selenium server on remote machine with:
java -jar selenium-server-standalone-2.26.0.jar
and in your e.g. BaseTest.java (where you have your webDriver initialization) you simply add:
static WebDriver driver;
private String loginBaseUrl;
#BeforeClass
public static void firefoxSetUp() throws MalformedURLException {
DesiredCapabilities capability = DesiredCapabilities.firefox();
driver = new RemoteWebDriver(new URL("http://192.168.4.52:4444/wd/hub"), capability);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.manage().window().setSize(new Dimension(1920, 1080));
}
#Before
public void homePageRefresh() throws IOException {
driver.manage().deleteAllCookies();
driver.get(propertyKeysLoader("login.base.url"));
}
#AfterClass
public static void closeFirefox(){
driver.quit();
}
i faced the same issue while trying to run the Remotely via VM's from host. I used Oracle VM Virtual Box.
Since the VM is assigned 2 different IP's one via NAT & other via Bridge adapter ...Hence Selenium node fails to register itself with the Selenium HUB as by default it registers for NAT.
Disconnect/disable the internet of VM NAT N/W adapter for which "10.0.2.15" IP is assigned. Don't Touch the bridge adapter settings...Then try to register the node...it works.
I would suggest to connect Bridge Adapter via VM >> Settings>> Network Screen
Please check the Links below...
http://www.thegeekstuff.com/2012/03/virtualbox-guest-additions/
https://blogs.oracle.com/fatbloke/entry/networking_in_virtualbox1
Hope this helps...All the best :-)
I had the same issue. I have NAT and "Host-only adapter" networks configurated for the virtual machine with default properties. I solved it using the the IP of the "Host-only adapter".
For me, the IP of NAT is 10.0.2.15 (same as you) and the IP of "Host-only adapter" is 192.168.56.101. So I used:
java -jar selenium-server-standalone-2.26.0.jar -role webdriver -hub http://192.168.3.146:4444/grid/register -port 5558 -host 192.168.56.101 -browser "browserName=firefox, version=6, platform=WINDOWS"

Selenium Grid 2 set up on Windows

I am setting up Selenium Grid 2 (selenium-server-standalone-2.1.0) on Windows 7 (I have also tried Windows Server 2008) both 64 bit. I test the WebDriver locally and all is well.
I launch the hub with:
java -jar selenium-server-standalone-2.1.0.jar -role hub
Adding a webDriver node for FireFox works, but anything else such as Google Chrome throws an IllegalOperation Exception.
For example:
I try adding a node for Chrome:
java -jar selenium-server-standalone-2.1.0.jar -role webDriver -hub http://127.0.0.1:4444 -browser browserName=chrome platform=windows version=12 -port 5556
This shows as a node on the hub when you go to http://localhost:4444/grid/console
I add code to call the webDriver such as:
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability(CapabilityType.Platform, "windows");
capability.SetCapability(CapabilityType.Version, "12");
capability.SetCapability(CapabilityType.BrowserName, "chrome");
IWebDriver driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"), capability);
I get an exception almost immediately:
{"cannot find : {platform=windows, browserName=chrome, version=12}"}
It seems as if the node isn't even being found. I am new to this is it something I have missed in the set up? (internet explorer does the same and changing versions doesn't seem to help).
I have searched for hours and hours but nothing that matches the exception seems as generic as my problem.
The IllegalOperation Exception {"cannot find : {platform=windows, browserName... is caused by there being no matching capability (it never gets as far as a Node).
If I use a config file when I launch the node that explicitly states the platform and browser such as:
{
"capabilities":
[
{
"browserName":"firefox",
"maxInstances":1
},
{
"browserName":"chrome",
"platform":"WINDOWS",
"maxInstances":1
},
{
"browserName":"internet explorer",
"version":"9",
"platform":"WINDOWS",
"maxInstances":1
}
],
"configuration":
{
"cleanUpCycle":2000,
"timeout":30000,
"proxy":"org.openqa.grid.selenium.proxy.WebDriverRemoteProxy",
"maxSession":5,
"url":"http://[myIP]/wd/hub",
}
}
and launch the hub with this line:
java -jar selenium-server-standalone-2.2.0.jar -role webdriver -nodeConfig myconfig.json -hub http://[myIP]:4444/grid/register
and create the capabilities like so:
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability(CapabilityType.Platform, "WINDOWS");
capability.SetCapability(CapabilityType.BrowserName, "internet explorer");
Then the test works (you have to set all Zones in IE to protected by the way).
N.B. I did notice that windows is UPPERCASE as in WINDOWS or you get an error.
The docs do actually document this but in an unclear way.
java -jar selenium-server-standalone-2.1.0.jar -role webDriver -hub http://127.0.0.1:4444 -browser browserName=chrome platform=windows version=12 -port 5556
Needs to be:
java -Dwebdriver.chrome.driver="C:\Users\Mike\Documents\Java Libraries\Selenium\chromedriver\chromedriver.exe" -jar selenium-server-standalone-2.1.0.jar -role webDriver -hub http://127.0.0.1:4444/grid/register -browser "browserName=chrome,platform=WINDOWS,version=12" -port 5556
You are missing grid/register from the hub URL. On top of this, if you are passing multiple arguments to -browser they need to be enclosed in quotes and separated by commas without spaces. You also need to pass in the webdriver.chrome.driver property in a similar way to how I did it.
You can check that it has successfully registered by going to your browser and hitting:
http://localhost:4444/grid/console
And as a sidenote, this is another way you could declare the desired capabilities:
DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setVersion("12");
dc.setPlatform(Platform.WINDOWS);
Lets consider Hub running on Machine-A whose IPAddress is = 192.168.10.10 default port no. 4444.
Lets Node running on Machine-B whose IPAddress is = 192.168.10.20.
Lets consider operating System on HUB and Node is installed on drive C:\ (C-Drive).
create a folder named selenium on c:\ as c:\selenium.
keep binaries of IExplorer.exe, chromeDriver.exe and Selenium-Standalone-server2.10.0.jar. (on both machine A and B).
configuring HUB on Machine-A
1- open Command prompt
2- go to folder selenium using
i type cd\ then enter
ii type c: then enter
iii c:> cd selenium then enter
3- java -jar selenium-server-standalone-2.20.0.jar -role hub
Configuring NOde on Machine - B
1- open Command prompt
2- go to folder selenium using
i type cd\ then enter
ii type c: then enter
iii c:> cd selenium then enter
3- java -jar selenium-server-standalone-2.20.0.jar -role node -hub http://192.168.10.10:4444/grid/register -port 5560 -browser browserName=chrome,maxInstance=4,platform=WIN8_1 -Dwebdriver.ie.driver=c:\selenium\ChromeDriver.exe
your node will get register with Hub on port 5560.
Test Case will become as-
package testCase;
import static org.junit.Assert.*;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class Avinash_Google_Chrome
{
WebDriver driver;
String baseUrl , nodeUrl;
#Before
public void setUp() throws Exception
{
nodeUrl = "http://192.168.10.20:5560/wd/hub"; //Machine-A IPAdress
with Port No.
DesiredCapabilities capability = DesiredCapabilities.chrome();
driver = new RemoteWebDriver(new URL(nodeUrl),capability);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(2, TimeUnit.MINUTES);
}
#After
public void tearDown() throws Exception
{
driver.quit();
}
#Test
public void test() throws InterruptedException
{
driver.get("https://www.google.co.in");
Thread.sleep(3000);
driver.findElement(By.linkText("Gmail")).click();
Thread.sleep(3000);
driver.findElement(By.id("Email")).sendKeys("aavinashpande#gmail.com");
driver.findElement(By.id("Passwd")).sendKeys("********");
driver.findElement(By.id("signIn")).click();
Thread.sleep(6000);
}
}
Try to lower the conditions about the chrome version and the operating system:
Your code to register the node would be the following
java -jar selenium-server-standalone-2.1.0.jar -role webDriver -hub http://127.0.0.1:4444 -browser browserName=chrome -port 5556
And to create your browser:
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability(CapabilityType.BrowserName, "chrome");
or
DesiredCapabilities capability = DesiredCapabilities.chrome();
It can be that your Chrome updated without you noticing or that the version number "12" is not perfectly fitting to your installed version.
If it runs under these conditions, try to add the "Platform=WINDOWS" and the "Version" CapabilityTypes with new combinations.
You can set
driver.quit();
at the end of your script

Resources