2

I need to run portable Firefox using RemoteWebDriver, but facing the problem:

Here is code for a local run which works perfectly:

FirefoxProfile profile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(
                     new FirefoxBinary(
                         new File(System.getProperty("user.dir"),
                         "/tools/FirefoxPortable/FirefoxPortable.exe")),profile);       
driver.get("http://google.com");

How can I run it on local server? With something like:

WebDriver driver = new RemoteWebDriver(DesiredCapabilities.firefox());
driver.get("http://google.com");
Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73
Alex Smoke
  • 619
  • 1
  • 8
  • 18

1 Answers1

2

If you are using RemoteWebDriver, There are two ways to set firefox binary as below :

  • You need to set FirefoxBinary into DesiredCapabilities as :

    FirefoxBinary bin = new FirefoxBinary(
                     new File(System.getProperty("user.dir"),
                     "/tools/FirefoxPortable/FirefoxPortable.exe"));
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability(FirefoxDriver.BINARY, bin);
    
    WebDriver driver = new RemoteWebDriver(capabilities);
    driver.get("http://google.com");
    
  • You need to run selenium-server-standalone-x.jar with -Dwebdriver.firefox.bin property which will point to firefox binary path as :

    java -jar selenium-server-standalone-x.jar -Dwebdriver.firefox.bin="path/to/firefox binary"
    

    Now you can instantiate RemoteWebDriver with firefox as :

    WebDriver driver = new RemoteWebDriver(DesiredCapabilities.firefox());
    driver.get("http://google.com");
    
Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73
  • What is the exception you are getting?? – Saurabh Gaur Aug 11 '16 at 10:41
  • Sorry, my bad, second case works perfectly. For the first one:WedDriverException : java.util.HashMap cannot be cast to java.lang.String when initializing RemoteWebDriver – Alex Smoke Aug 11 '16 at 10:43
  • @user1274184 But in my case both options work perfect...I think problem other than that because here is no java.util.HashMap present..:) – Saurabh Gaur Aug 11 '16 at 10:49
  • Same problem as here - http://stackoverflow.com/questions/21260364/weddriverexception-java-util-hashmap-cannot-be-cast-to-java-lang-string-when-i Says something about incompatible versions. Thanks a lot. – Alex Smoke Aug 11 '16 at 10:54