Why does my code Not connect to my Hub or Node? - selenium

Why does my code Not connect to my Hub or Node?
I need to execute my test cases using a node.
I have successuflly setup a hub and node.
My code:
case "chrome":
if (null == webdriver) {
System.setProperty("webdriver.chrome.driver", Constant.CHROME_DRIVER_DIRECTORY);
webdriver = new ChromeDriver();
DesiredCapabilities capability = DesiredCapabilities.chrome();
webdriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),capability);
Output from the hub:
Output from the node:
testng output:
Hub & Node Setup: JSON File:

On node registration you should add chrome driver path like this
-Dwebdriver.chrome.driver=<pathToChormeDriverExe>/chromedriver.exe
In your case, something like this should work:
java -Dwebdriver.chrome.driver=C:/Temp/chromedriver/chromedriver.exe
-jar selenium-server-standalone-3.0.1.jar
-role node
-hub http://172.16.1.48:4444/grid/register
-browser "browserName=chrome, version=ANY, maxInstances=5, platform=WINDOWS"

Related

Selenium Grid: Not able to create Gecko Driver Session [duplicate]

I fail to drive Firefox from Selenium with geckodriver. This is odd, because chrome is driven with same framework without errors!
These are my Version numbers:
Firefox 54.0 (64-bit)
Chrome Version 62.0.3202.94 (Official Build) (64-bit)
selenium-server-standalone-3.7.1.jar
client-combined-3.5.3-nodeps.jar
geckodriver-v0.19.1-linux64
chromedriver_linux64
Ubuntu 16.10
The error I get from Selenium webdriver with java is the following:
--------------------------------Error:
leder#leder-VirtualBox:~/Source/SeleniumCheese/bin$ ./execute_grid.sh
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new service: GeckoDriverService
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:07:36.161Z'
System info: host: 'leder-VirtualBox', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.8.0-59-generic', java.version: '1.8.0_131'
Driver info: driver.version: unknown
Command duration or timeout: 1.39 seconds
---------------------------------Schnapp
This is my setup, where firefox is broken and chrome is OK:
Grid_SetUp.java
package de.auticon.selenium_server;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.MalformedURLException;
import java.net.URL;
public class Grid_SetUp {
public static WebDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException{
System.setProperty("webdriver.chrome.driver","/opt/selenium/chromedriver");
String URL = "http://www.google.de";
String Node = "http://192.168.40.40:4444/wd/hub";
DesiredCapabilities cap = DesiredCapabilities.firefox();
driver = new RemoteWebDriver(new URL(Node), cap);
driver.navigate().to(URL);
WebElement element = driver.findElement(By.name("q"));
//Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
Thread.sleep(5000);
driver.quit();
}
}
selenium_grid.sh:
#!/bin/bash
java -jar /opt/selenium/selenium-server-standalone-3.7.1.jar -role hub &
java -Dwebdriver.gecko.driver=/opt/selenium/geckodriver -jar /opt/selenium/selenium-server-standalone-3.7.1.jar -role webdriver -hub http://192.168.40.40:4444/grid/register -nodeConfig /opt/selenium/defaultNodeConfig.json -browser "browserName=firefox,platform=LINUX" &
execute_grid.sh:
#!/bin/bash
java -cp ".:/opt/selenium/selenium-server-standalone-3.7.1.jar" de.auticon.selenium_server.Grid_SetUp
I updated the question for working configuration now. But when running the firefox Selenium TC the TC completes, unfortunately the server ends with an error message "session not created":
13:49:10.376 INFO - Removing session org.openqa.selenium.remote.server.ServicedSession#70c81601
13:49:10.381 INFO - To downstream: {"value":{"error":"session not created","message":"Tried to run command without establishing a connection","stacktrace":"stack backtrace:\n 0: 0x4edb3c - backtrace::backtrace::trace::hc4bd56a2f176de7e\n 1: 0x4edb72 - backtrace::capture::Backtrace::new::he3b2a15d39027c46\n 2: 0x4409a1 - webdriver::error::WebDriverError::new::h81babdd86c977032\n 3: 0x4280ea - <webdriver::server::Dispatcher<T, U>>::run::h2119c674d7b88193\n 4: 0x4029b9 - std::sys_common::backtrace::__rust_begin_short_backtrace::h21d98a9ff86d4c25\n 5: 0x40be65 - std::panicking::try::do_call::h5cff0c9b18cfdbba\n 6: 0x5e6a6c - panic_unwind::__rust_maybe_catch_panic\n at /checkout/src/libpanic_unwind/lib.rs:99\n 7: 0x41eb22 - <F as alloc::boxed::FnBox<A>>::call_box::h413eb1d9d9f1c473\n 8: 0x5df13b - alloc::boxed::{{impl}}::call_once<(),()>\n at /checkout/src/liballoc/boxed.rs:692\n - std::sys_common::thread::start_thread\n at /checkout/src/libstd/sys_common/thread.rs:21\n - std::sys::imp::thread::{{impl}}::new::thread_start\n at /checkout/src/libstd/sys/unix/thread.rs:84"}}
A few words about Selenium Grid Configuration:
You mentioned your Test Bed as selenium-server-standalone-3.7.1.jar and client-combined-3.5.3-nodeps.jar. As per Best Practices, you should use either of the following not both
Always try to use the latest released version i.e. selenium-server-standalone-3.7.1.jar
In selenium_grid.sh: you need to change the following :
java -Dwebdriver.gecko.driver=/opt/selenium/geckodriver
I simply follow this code using my firefox browser, seleinum grid with Testng in eclipse
System.setProperty("webdriver.gecko.driver","E:\\FireFoxDriver\\geckodriver.exe");
String URL = "http://demo.automationtesting.in/Register.html";
String Node = "http://192.168.43.97:4444/wd/hub";
DesiredCapabilities cap = DesiredCapabilities.firefox();
driver = new RemoteWebDriver(new URL(Node), cap);
driver.get(URL);
driver.manage().window().maximize();
System.out.println("Page title is: " + driver.getTitle());
Thread.sleep(5000);
driver.close();
For creating hub in your local machine
java -jar E:\SeleniumGrid\selenium-server-standalone-3.141.59.jar -role hub
open cmd and enter above line where your selenium standalone server is downloaded
Then you will get these two
Nodes should register to http://192.168.43.97:4444/grid/register/
Clients should connect to http://192.168.43.97:4444/wd/hub
Then again open cmd and type this for node
java -Dwebdriver.gecko.driver="E:\FireFoxDriver\geckodriver.exe" -jar E:\SeleniumGrid\selenium-server-standalone-3.141.59.jar -role node -hub http://192.168.43.97:4444/grid/register

org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session

I am trying to setup selenium grid. and follow the following steps:-
1) Start hub on Windows 10 (32 bit) :-
java -jar "path to standalone jar" -role hub -port 4444
2) Start node on Ubuntu14.04 (64 bit) :-
java -jar "path to standalone jar" -role webdriver -port 5555 -hub "http:// ip of windows PC:4444/grid/hub"
The node and hub started successfully. But the problem is when I am trying to execute the following script it throws exception " org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session" Please look at the following code:-
public class gridclass
{
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver","Path to/geckodriver");
WebDriver wd=null;
try
{
DesiredCapabilities desire = DesiredCapabilities.firefox();
wd = new RemoteWebDriver( new URL("http://path to hub URL/grid/hub"), desire);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
wd.get("http://www.google.com");
wd.close();
wd.quit();
}
}
The above code I have written on Windows 10 (i.e on hub machine). Is that the correct way?
If it the correct and code is correct then how to solve org.openqa.selenium.SessionNotCreatedException.
Please help me in this case.

Issue using Selenium grid with Microsoft Edge browser

I'm setting up a Selenium Grid for remote automated testing, and can't seem to start a test on a Microsoft Edge node.
I set up my node on a test machine with this command:
java -Dwebdriver.ie.driver=C:\MicrosoftWebDriver.exe -jar selenium-server-standalone-2.52.0.jar -port 5555 -role node -hub http://192.168.1.201:4444/grid/register -browser "browserName=MicrosoftEdge, platform=WINDOWS, maxInstances=10"
And I try sending a simple test like this:
[SetUp]
public void Initialize()
{
DesiredCapabilities capabilities = DesiredCapabilities.Edge();
driver = new RemoteWebDriver(new Uri("http://192.168.1.201:4444/wd/hub"), capabilities);
}
[Test]
public void UrlCheck()
{
driver.Url = "http://google.com";
}
[TearDown]
public void EndTest()
{
driver.Quit();
}
When I run the above on my test machine, I can see it open the Edge browser (so it's getting to the node fine), but it can't navigate to the URL.
In Visual Studio I get this error:
Result Message:
System.InvalidOperationException : null (WARNING: The server did not provide any stacktrace information)
I can't find much information on sending tests to an Edge node. Any advice would be greatly appreciated.
Try -Dwebdriver.edge.driver= "C:\MicrosoftWebDriver.exe" instead of Dwebdriver.ie.driver

Error when passing IE version to Selenium Grid

I'm trying to pass a simple test to my Selenium grid, while specifying which version of IE to run the test on.
I've started my node like this:
java -jar selenium-server-standalone-2.52.0.jar -role webdriver -hub http://192.168.1.201:4444/grid/register -browserName="internet explorer",version=10.0,platform=WINDOWS -Dwebdriver.ie.driver=C:\IEDriverServer.exe
I see the node register to the hub with version 10, looks OK.
Then I start my test like this:
IWebDriver driver;
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities = DesiredCapabilities.InternetExplorer();
capabilities.SetCapability(CapabilityType.BrowserName, "internet explorer");
capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows));
capabilities.SetCapability(CapabilityType.Version, "10.0");
driver = new RemoteWebDriver(new Uri("http://192.168.1.201:4444/wd/hub"), capabilities);
But I get the error:
Result Message:
System.InvalidOperationException : Error forwarding the new session
cannot find : Capabilities [{platform=WINDOWS, browserName=internet explorer, version=10.0}]
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
The test can run when I don't specify the IE version, so the issue must be there - what is failing here?
I think browser version should be "10" without ".0":
capabilities.SetCapability(CapabilityType.Version, "10");
You also don't need to initialize DesiredCapabilities twice, and then change settings once again. You can just set them to correct values in constructor, so 5 lines collapse into 1:
DesiredCapabilities capabilities = new DesiredCapabilities( "internet explorer", "10", new Platform(PlatformType.Windows) );
I figured it out.
When registering a node as a browser version, you have to surround the browser parameters set with quotation marks. My new node startup command is:
java -Dwebdriver.ie.driver=C:\IEDriverServer.exe -Dwebdriver.chrome.driver=C:\chromedriver.exe -jar selenium-server-standalone-2.52.0.jar -port 5555 -role node -hub http://192.168.1.201:4444/grid/register -browser "browserName=firefox, maxInstances=10, platform=ANY, seleniumProtocol=WebDriver" -browser "browserName=internet explorer, version=10, platform=WINDOWS, maxInstances=10" -browser "browserName=chrome,version=ANY,maxInstances=10,platform=WINDOWS"

Using Selenium to test Safari gives GridException

I am using the code from this site (http://darrellgrainger.blogspot.com/2011/02/using-selenium-20-with-webdriver-and.html) to run Selenium tests in Safari 5. The code goes like this:
Selenium sel = new DefaultSelenium("localhost", 4444, "*safari", baseURL);
CommandExecutor executor = new SeleneseCommandExecutor(sel);
DesiredCapabilities dc = new DesiredCapabilities();
WebDriver browser = new RemoteWebDriver(executor, dc);
browser.get("http://www.google.com");
WebElement input = browser.findElement(By.name("q"));
input.sendKeys("Selenium");
So I start a Selenium server standalone version on the localhost machine and I register a test node (also on localhost) to the Selenium hub. Then I start the test. I then get the following exception: org.openqa.selenium.WebDriverException: Could not start Selenium session: org%2Eopenqa%2Egrid%2Ecommon%2Eexception%2EGridException%3A+Error+forwarding+the+new+session+The+server+returned+an+error+%3A+
I don't know what error. There is no server output on the console. Does anyone have ideas? I used the newest version (2.17.0) of Selenium.
EDIT: I just tried "firefox" instead of safari and it outputs the same exception. So actually it's not the fault of safari. Maybe there is something wrong with executing Selenium 1 code via the grid?
Try This:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("safari");
capabilities.setJavascriptEnabled(true);
CommandExecutor executor = new SeleneseCommandExecutor(new URL("http://localhost:5555/"), new URL("http://www.google.com/"), capabilities);
WebDriver driver = new RemoteWebDriver(executor, capabilities);
driver.get("http://google.com");
Don't create DefaultSelenium object. The above code works well for me with Safari browser.