9

Currently I am able to send a firefox profile over a RemoteWebDriver, but I am not able to send the RestCLient extension over the profile. I require a certain REST client extension(firefox add-on) to be available for my test case execution.

If I run the test case locally using firefox driver it works....but how do I achieve the same thing using RemoteWebDriver?

 File profileDirectory = new File("c://mach//lib//prof");
 FirefoxProfile profile = new FirefoxProfile(profileDirectory);
 driver = new FirefoxDriver(profile);
 driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

Cheers

James Dunn
  • 8,064
  • 13
  • 53
  • 87
LearningSnippet
  • 101
  • 1
  • 1
  • 5

1 Answers1

24

After creating a FirefoxProfile instance, transfer the profile using the DesiredCapabilities API (FirefoxDriver.PROFILE = "firefox_profile"):

File profileDirectory = new File("c://mach//lib//prof");
FirefoxProfile profile = new FirefoxProfile(profileDirectory);

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);

Note: You don't have to create a profile in advance, the FirefoxProfile API offers several convenient methods ("Method Summary" section) to compose a profile. For instance, if you want to launch Firefox with an extension pre-installed, use:

FirefoxProfile firefoxProfile = new FirefoxProfile();
File extension = new File("extension.xpi");
firefoxProfile.addExtension(extension);

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);

Documentation for working with the remote web driver:

Rob W
  • 341,306
  • 83
  • 791
  • 678
  • I got this exception in line "RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Build info: version: '2.43.1', revision: – Sagar007 Jan 06 '15 at 07:07
  • You need to start selenium server to use RemoteWebDriver – Pratik G Mar 31 '15 at 05:45