Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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.

share|improve this question
    
Which version of Selenium? –  user246 Nov 16 '13 at 21:27
    
@user246 updating the question with more information –  bhavs Nov 18 '13 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"); –  user246 Nov 19 '13 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 –  bhavs Nov 19 '13 at 4:14
add comment

1 Answer 1

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:apikey@browserstack.com/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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.