Runtime exception at selenium.start() - Could not start Selenium session: Failed to start new browser session: Error while launching browser - selenium

Followed this post -
Selenium - Could not start Selenium session: Failed to start new browser session: Error while launching browser
Error comes up at selenium.start().
I am using selenium rc(2.16) , junit(4.5) in eclipse ide.
The only way to over come this issue is to redeploy our framework in tomcat server, just restart everything.
This is the piece of code that starts selenium
private static HttpCommandProcessor proc;
public static DefaultSelenium selenium;
if (selenium == null) {
proc = new HttpCommandProcessor("localhost", 4444, browserName,
urlName);
selenium = new DefaultSelenium(proc);
**selenium.start();**
selenium.setTimeout(String.valueOf(PAGE_TIMEOUT_TIME));
selenium.useXpathLibrary("javascript-xpath");
selenium.deleteAllVisibleCookies();
}
the selenium server is already started when the execution reaches the above code.
Below is the exception that comes up when execute the tests -
java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Error while launching browser
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:107)
at <package>.SuperClass.connectToUrl(SuperClass.java:340)
Any help or clue to resolve this thing would be appreciated!

Related

WebDriver: ChromeDriver attempting to reach http://localhost/session on initialization and failing

The full error message is:
Test(s) failed. OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:59662/session timed out after 60 seconds.
----> System.Net.WebException : The operation has timed out
The line in my code where this is happening simply instances a new ChromeDriver instance:
CurrentDriver = new ChromeDriver(section["chromedriverfolder"]);
So my question is... why does a new ChromeDriver invokes the /session URL, and what could be causing it to fail?
I experienced this same error using Selenium.WebDriver.ChromeDriver v2.22 and Chrome v52.0.2743.116 m running on TeamCity 9.x. I was able to fix the problem by rolling back the version of Chrome running on the TeamCity agents to v51.
When examining the agent executing the test, there is a popup with error: "Chrome Automation extension has crashed. Click this balloon to reload the extension."
It seems like a bug with the latest version of Chrome and Selenium.WebDriver.ChromeDriver, but as of yet this is the only lead I've found
EDIT: The link to the ChromeDriver issue
EDIT2: The link to the resolution
I have the answer where ChromeDriver invokes the /session URL, but not to the second part why it is timing out. Please see if it can provide some lead to the debug process to find out the failure :
When we call new ChromeDriver()
It creates RemoteWebDriver in the constructor :
super(new DriverCommandExecutor(service), capabilities);
which ultimately goes to :
public RemoteWebDriver(CommandExecutor executor, Capabilities desiredCapabilities,
Capabilities requiredCapabilities) {
In this method we do startClient which basically does nothing in this particular case
After startClient we do :
startSession(desiredCapabilities, requiredCapabilities);
This method issues the request /session in the following line :
Response response = execute(DriverCommand.NEW_SESSION, parameters);
The DriverCommand.NEW_SESSION is set as newSession which is mapped to post /session in the Command Codec
defineCommand(NEW_SESSION, post("/session"));

Selenium Exception with no stack trace (grunt / protractor / selenium)

I try to run grunt test, and Selenium exits without closing the browser. I am unable to see where the exception is coming from.
grunt test
Running "protractor_webdriver:start" (protractor_webdriver) task
Starting Selenium server
Started Selenium server: http://127.94.0.1:4444
Running "protractor:projecttest" (protractor) task
[10:16:33] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[10:16:33] I/launcher - Running 1 instances of WebDriver
Session created: count=1, browserName=chrome
......Exception thrown: Going to shut down the Selenium server
Shutting down Selenium server: http://127.94.0.1:4444
Shut down Selenium server: http://127.94.0.1:4444 (OKOK)
Fatal error: 10:16:45.529 WARN - Exception thrown
All of my tests are passing. I even added logs to prove the final test passes and exits without exception.
I tried to up my logging from "dots" to "progress" but it doesn't change anything. Any ideas?

Failed to start new browser session: org.openqa.selenium.server.RemoteCommandException: Error while launching browser on session null

09:39:51.984 INFO - Got result: Failed to start new browser session: org.openqa.selenium.server.RemoteCommandException: Error while launching browser on session null
09:39:52.002 INFO - Command request: getNewBrowserSession[*firefox, http://website.localhost] on session null
09:39:52.002 INFO - creating new remote session
09:39:52.003 INFO - Allocated session 4b3951d894ed4a2c94b7fd9758cd5554 for http://website.localhost, launching...
jar:file:/usr/bin/selenium-server-standalone-2.41.0.jar!/customProfileDirCUSTFFCHROME
09:39:52.071 INFO - Preparing Firefox profile...
09:40:12.129 ERROR - Failed to start new browser session, shutdown browser and clear all session data
java.lang.RuntimeException: Timed out waiting for profile to be created!
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.waitForFullProfileToBeCreated(FirefoxChromeLauncher.java:307)
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.populateCustomProfileDirectory(FirefoxChromeLauncher.java:119)
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.launch(FirefoxChromeLauncher.java:89)
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.launchRemoteSession(FirefoxChromeLauncher.java:346)
at org.openqa.selenium.server.browserlaunchers.FirefoxLauncher.launchRemoteSession(FirefoxLauncher.java:114)
at org.openqa.selenium.server.BrowserSessionFactory.createNewRemoteSession(BrowserSessionFactory.java:400)
at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession(BrowserSessionFactory.java:144)
at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession(BrowserSessionFactory.java:105)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.getNewBrowserSession(SeleniumDriverResourceHandler.java:809)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.doCommand(SeleniumDriverResourceHandler.java:435)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.handleCommandRequest(SeleniumDriverResourceHandler.java:405)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.handle(SeleniumDriverResourceHandler.java:151)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1526)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1479)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:920)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:358)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:537)
09:40:12.131 INFO - Got result: Failed to start new browser session: org.openqa.selenium.server.RemoteCommandException: Error while launching browser on session null
09:40:12.143 INFO - Command request: getNewBrowserSession[*firefox, http://website.localhost] on session null
what i am doing ?
Step 1: Start the hub
The Hub is the central point that will receive all the test request and distribute them the the right nodes.
Open a command prompt and navigate to the directory where you copied the selenium-server-standalone file. Type the following command:
java -jar selenium-server-standalone-2.14.0.jar -role hub
Step 2: Start the nodes
Regardless on whether you want to run a grid with new WebDriver functionality, or a grid with Selenium 1 RC functionality, or both at the same time, you use the same selenium-server-standalone jar file to start the nodes.
java -jar selenium-server-standalone-2.14.0.jar -role node -hub http://localhost:44444/grid/register (here 44444 is for the environment i am working)
This is due to compatibility issues between selenium and firefox.
You need to upgrade to the latest selenium server, 2.44 at the moment.
Yes! As alec[xe suggested this is due to the compatibility issues between firefox and selenium. For firefox version higher than 30 you must use selenium 2.44 version.Here's the changelog of the selenium please take a look and decide which version of the selenium will fulfill your requirement.
Click here to download the latest(2.44) version of the selenium.

Selenium Grid with safari browser

Plese Help me
How do I instantiate the Safari in selenium grid
capabilities = new DesiredCapabilities();
// Version browser
capabilities.setVersion(versaoBrowser);
capabilities.setBrowserName("safari");
capabilities.setJavascriptEnabled(true);
// Platform test runner
capabilities.setPlatform(platform);
On the server is weel
-browser "browserName=safari,version=5,platform=WINDOWS,javascriptEnable=true"
If the question is about using Safari the new way, with SafariDriver over Grid2, then this would be the typical method I believe (more or less):
import org.openqa.selenium.*;
import org.openqa.selenium.remote.*;
import java.net.*;
DesiredCapabilities c = new DesiredCapabilities();
c.setBrowserName("safari");
/* you can then set version & platform as well, but the minimum is just browser. Maybe for Grid2 you need the others, but for remote web driver only, you don't.
*/
WebDriver d = new RemoteWebDriver(new URL("http://hubIpOrHostname:hubPort/wd/hub"),c);
and that should work. On the server side, I believe you just instantiate normally for Grid2 per the wiki docs (last I check, could be diff now):
//start hub
java -jar selenium-server-standalone-2.21.0.jar -role hub -port theHubPort
//start the node
java -jar selenium-server-standalone-2.21.0.jar -role node -hub http:
//172.22.6.198:4446/wd/hub -port theNodePort
however, seems that the current Grid2 doesn't offer Safari support. When I looked up the console for the registered node in hub, it didn't show icon for Safari. Maybe I missed something. I'll try adding platform and version next time to see if that makes a diff but think not.
Here's a snippet of the error I get for Grid2 with SafariDriver:
May 11, 2012 6:01:11 PM org.openqa.selenium.remote.RemoteWebDriver execute
INFO: Executing: [null, newSession {"desiredCapabilities":"Capabilities [{browse
rName=safari}]"}]
// Error: // Uncaught Exception: Typed variable declaration : Object constructor
: at Line: 7 : in file: : new RemoteWebDriver ( new URL ( "http:
//172.22.6.198:4446/wd/hub" ) , c )
Target exception: org.openqa.selenium.WebDriverException: Error forwarding the n
ew session cannot find : {browserName=safari}
Command duration or timeout: 109 milliseconds
To note: with webdriver, same code can be used for (standalone) remote webdriver execution vs grid, difference is that for remote you use remote server ip and with grid2, you use hub ip. SafariDriver works over remote webdriver, but currently doesn't seem to work over Grid2 yet.
remote webdriver startup:
java -jar selenum-server-standalone-2.21.0.jar [-port somePort]
//default port of 4444
I believe what you are asking for is something like this?
selenium = new DefaultSelenium("localhost", 4444, *safari,"http://google.com.au");
selenium.start();
I generally use WebDriver, but my understanding is capabilities are options for when you create an instance of a browser, not to open the browser itself. Though I could be wrong as I am not experienced with Selenium Grid.
EDIT: This and this might help.

Selenium RC throws sessionsid should not be null exception with assertTextPresent, phpunit 3.4 bug only?

I am looking to migrate my selenium RC tests to using PHPUnit 3.4.12 from PHPUnit 3.3.2.
The selenium test will fail with an exception of the following when I use assertTextPresent():
PHPUnit_Framework_Exception: Response from Selenium RC server for getLocation().
ERROR Server Exception: sessionId should not be null; has this session been started yet?.
For example:
public function testSending($browser)
{
...
$browser->click("send");
$browser->waitForPageToLoad("30000");
$browser->assertTextPresent("text");
}
Below is the selenium RC log (running on Windows):
15:40:19.676 INFO - Command request: isTextPresent[text, ] on session 153d03a123c42098711994f43c2db34
15:40:19.691 INFO - Got result: OK,false on session 153d023a123c42098711994f43cdb34
15:40:19.879 INFO - Command request: testComplete[, ] on session 153d023a123c4298711994f43c2db34
15:40:19.879 INFO - Killing Firefox...
15:40:20.269 INFO - Got result: OK on session 153d023a123c42098711994f43c2db34
15:40:20.472 INFO - Command request: getLocation[, ] on session null
15:40:20.472 ERROR - Exception running 'getLocation 'command on session null
java.lang.NullPointerException: sessionId should not be null; has this session been started yet?
As you can see, the test should have completed as indicated by the "Killing Firefox" bit, but it instead continued to do something else and triggered the getLocation[, ] command which caused the exception.
I have tried the same test with PHPUnit 3.3.2 which did not produce this problem - the test would happily end without the getLocation().
Any ideas?
Actually the problem is with setAutoStop() method - by default it's set to TRUE, so PHPUnit sends stop signal to Selenium RC prior to tearDown().
Add $this->setAutoStop(false); to your setUp() method and $this->stop(); to the end of tearDown().