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

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.

Related

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

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"

Browsers are not launching from command prompt. Same testng File is working while running through eclipse

I am trying to run my testng test cases from command prompt. I can see browser's instance are created in task manager but it is not launching with given URL. I debugged the code and found it is failing on new ChromeDriver() below line but there is no exception.
On command line, I can see below message :
Starting ChromeDriver 2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a) on port 7108
Only local connections are allowed.
Browser instance will create in task manager but it will not launch and will not go to next line.
This issue is coming from all browsers on same line.
same code worked well in Eclipse.
Using Selenium 2.53.0 and testng 6.9.13 versions
Try this solution:
ChromeDriverService service = null;
try
{
service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File(chromeDriver))
.usingAnyFreePort()
.build();
service.start();
}catch(IOException io){}
if(service.isRunning())
{
DesiredCapabilities cap = DesiredCapabilities.chrome();
try{
driver = new RemoteWebDriver(service.getUrl(), cap);
}catch (SessionNotCreatedException e)
{
}
}

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

selenium grid, creating node programmatically

I have to create a java application that will start a node and connect it to the hub. So far I have been able to do so when the hub and node are on the same computer, but as soon as I try to connect on another machine hub, the registering process hang forever.
I tried different approach. To just call my bat file function in code.
String command = "java -jar selenium-server-standalone-2.26.0.jar -role node -hub http://192.168.0.11:4444/grid/register -port 4449 -Dwebdriver.chrome.driver=data\\driver\\chromedriver.exe -Dwebdriver.ie.driver=data\\driver\\IEDriverServer.exe -nodeConfig data\\configurations.json";
try
{
pr = Runtime.getRuntime().exec(command);
}
catch(Exception e)
{
e.printStackTrace();
}
The command work when called from a bat file, but in code it only works if the node and hub are on the same computer.
I also tried to use the RegistrationRequest.
RegistrationRequest req = new RegistrationRequest();
req.setRole(GridRole.NODE);
Map<String, Object> nodeConfiguration = new HashMap<String,
Object>();
nodeConfiguration.put(RegistrationRequest.AUTO_REGISTER, true);
nodeConfiguration.put(RegistrationRequest.HUB_HOST, "192.168.100.66");
nodeConfiguration.put(RegistrationRequest.HUB_PORT, 4444);
nodeConfiguration.put(RegistrationRequest.PORT, 5555);
URL remoteURL = new URL("http://" + "192.168.100.66" + ":" + 5555);
nodeConfiguration.put(RegistrationRequest.PROXY_CLASS, "org.openqa.grid.selenium.proxy.DefaultRemoteProxy");
nodeConfiguration.put(RegistrationRequest.MAX_SESSION, 1);
nodeConfiguration.put(RegistrationRequest.CLEAN_UP_CYCLE, 2000);
nodeConfiguration.put(RegistrationRequest.REMOTE_HOST, remoteURL);
nodeConfiguration.put(RegistrationRequest.MAX_INSTANCES, 1);
req.setConfiguration(nodeConfiguration);
remote = new SelfRegisteringRemote(req);
remote.startRemoteServer();
remote.startRegistrationProcess();
Same result, when I try to run on another computer hub, it hand at the registering process.
INFO - Registering the node to hub :http://192.168.100.66:4444/grid/register
any idea why? or how to do it.
I figured out my problem, which is really simple to fix. In my code I had
URL remoteURL = new URL("http://" + "192.168.100.66" + ":" + 5555);
I just needed to replace the ip address by my local ip address, not the hub ip address, and it worked. Which is weird cause I am pretty sure I took this code from somewhere online and he had a variable for the ip, and it was the same for remoteURL and the HUB_HOST
well. Not sure whether is suitable for you but I'd like to share approach I use on my project.
I've got remote machine with 192.168.4.52 IP and selenium stanadlone server running on it.
All selenium test suites I got locally.
So to run my selenium test suite on remote machine I simply use these settings in BaseSeleniumTest.java on my local machine:
....
#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();
}
where string
driver = new RemoteWebDriver(new URL("http://192.168.4.52:4444/wd/hub"), capability);
indicates IP of machine which I want to run my selenium test siute on.
I'm starting server on remote machine with this command:
java -jar selenium-server-standalone-2.26.0.jar in cmd before I run my test suite.
Hope it be helpful for you.

selenium: trying to use selenium Grid for running tests on multiple browsers

I am running these 3 tests on Selenium ID,
but i want to run these tests in parallel on different browsers , for that i am trying to use Selenium Grid and referring this http://code.google.com/p/selenium/wiki/Grid2
for that i am using this code
public class testjava extends SeleneseTestCase {
#Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "www.yahoo.com/");
selenium.start();
}
#Test
public void testTestjava() throws Exception {
}
#After
public void tearDown() throws Exception {
selenium.stop();
}
}
but i am getting this exception
java.lang.NoSuchMethodError: org.apache.http.conn.scheme.Scheme.<init>(Ljava/lang/String;ILorg/apache/http/conn/scheme/SchemeSocketFactory;)V
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:57)
at org.openqa.selenium.remote.internal.HttpClientFactory.<init>(HttpClientFactory.java:47)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:211)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:102)
at com.selenium.testjava.setUp(testjava.java:20)
at junit.framework.TestCase.runBare(TestCase.java:128)
at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:230)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Thanks
The DefaultSelenium is for Selenium 1 (RC)-compability. localhost is your RC-server (it's the seleniumserver).
But I would recommend you use Selenium 2. Like it says in your link you have to do the following:
DesiredCapabilities capability = DesiredCapabilities.firefox();
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability); //localhost is your hub here
This is a simple example, it requests firefox in your grid. you can specify any browser on any platform:
capability.setBrowserName(“firefox”);
capability.setPlatform(“LINUX”);
capability.setVersion(“3.6”);
And you need at least one node that you register to the hub like this:
java -jar selenium-server-standalone-2.x.0.jar -role wd -hub http://localhost:4444/grid/register -browser browserName=firefox,version=3.6,platform=LINUX
Again it is assumed Selenium hub is running on localhost. I hope this helps as a start. Just ask if you have any further questions.
You need to use JUnit 4 in combination with Selenium.
Copy your JUnit 4 Selenium test into Eclipse.
Write the start up of the Firefox Profile and furthermore DesiredCapabilities capability = DesiredCapabilities.firefox();
into #Before
Start the Hub, start the Node, run your tests.
But I suggest you read the basic tutorials about JUnit 4 and Selenium Testing in JUnit 4.
Just Google to find your solution.
Java knowledge also helps.