2

I am newbie with selenium and writing selenium test cases, I am basically trying to modify existing code in order to enhance some functionality.

I am creating a webDriver using the following code :

 DesiredCapabilities capabilities = new DesiredCapabilities();
 capabilities.setBrowserName("firefox");
 capabilities.setCapability("key", true);
 capabilities.setCapability("key", "value");
 if (driverUrl != null) {
 System.out.println(" Capabilities are "+capabilities.toString());
 try {
 URL url = new URL(driverUrl);
 System.out.println(" DriverUtil: createDriver() path: "+url.toString()+" protocol "+url.getProtocol()+" hostName :"+url.getHost()+" port "+url.getPort());
 WebDriver driver = new RemoteWebDriver(url, capabilities);
 System.out.println(" WebDriver is "+driver);
 return driver;
 } catch (MalformedURLException e) {
 throw new IllegalStateException("Failed to create remote web driver for url " + driverUrl, e);
 }
 }

The url as well as the capabilities have the following values :

 DriverUtil webDriver is http://xyz-qaa.abc.no
 Capabilities are Capabilities [{browserName=firefox, key=value}]

I have modified the url in this question but as such the url has a valid value and can be opened in the browser.

But when I try to run the test cases I see this :

 Caused by:
 java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
 at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:218)
 at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
 at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:129)
 at heimdall.ui.webtest.DriverUtil.createDriver(DriverUtil.java:46)

I have looked around to find a solution for this but I am unable to find one. Any suggestions?

I am not entirely sure which version of selenium is being used, because I am not the original author, but in te eclipse project I did find that the org.seleniumhq.selenium/selenium-remote-driver/2.32.0.jar and selenium-firefox-driver-2.32.0.jar is being used.

asked Nov 15, 2013 at 7:17
4
  • Which version of Selenium? Commented Nov 16, 2013 at 21:27
  • @user246 updating the question with more information Commented Nov 18, 2013 at 7:54
  • The latest version of Selenium is 2.37. Do you have the same problem in that release? Also, what is the purpose of these two lines: capabilities.setCapability("key", true); capabilities.setCapability("key", "value"); Commented Nov 19, 2013 at 0:12
  • @user246 I am using those lines to set some dummy values, I have as such no requirement of those lines, but I just verified that even after I remove those lines I stil seem to be facing the above issue Commented Nov 19, 2013 at 4:14

1 Answer 1

2

I have seen this error in other WebDriver projects, and my experience suggests that the URL you're passing as the first parameter to the RemoteWebDriver constructor is not a valid RemoteWebDriver grid URL. Double-check to ensure that the WebDriver grid server is running, and that the URL is valid for the server.

For example, my RemoteWebDriver URLs look something like this:

  1. An account on a professional WebDriver service, like BrowserStack:

    http://username:[email protected]/wd/hub

  2. A Selenium WebDriver grid that you set up yourself, on your local network:

    http://192.168.90.148:4444/wd/hub

  3. PhantomJS running on your local machine:

    http://127.0.0.1:8910

The URL in your sample code and output looks a little different:

http://xyz-qaa.abc.no

Your example shows no port number, and no /wd/hub suffix in the URL. In addition, you state that you can open the URL in a web browser. If you attempt to open a RemoteWebDriver server URL in a web browser, you will probably only see something like this:

{"value":{"message":"200 OK"}}

I suspect that the first parameter to your RemoteWebDriver constructor is not a valid RemoteWebDriver server URL, and that's what's causing this (admittedly quite misleading) error. Are you accidentally setting the URL in the RemoteWebDriver constructor to the URL of your test page? Take care to ensure that the URL in the first parameter of the RemoteWebDriver constructor is the correct URL for the RemoteWebDriver server, or else you will receive the "java.lang.String cannot be cast to java.util.Map" error.

answered Jun 14, 2014 at 0:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.