0

I am researching how to set an individual profile using RemoteWebDriver. I have been reading about it on the following thread.

http://stackoverflow.com/questions/12961037/parallel-execution-of-firefoxdriver-tests-with-profile-share-same-profile-copy

I am trying to tackle it as following:

public static RemoteWebDriver getDriver(String methodName) throws MalformedURLException {

    String SELENIUM_HUB_URL = "http://localhost:4444/wd/hub";
    ThreadLocal<RemoteWebDriver> remoteWebDriver = null;

    File currentProfileFile = new File(methodName);
    //This is where it gives the error
    FirefoxProfile currentFireFoxProfile = new FirefoxProfile(currentProfileFile);
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    capabilities.setCapability(FirefoxDriver.PROFILE, currentFireFoxProfile);       
    String proxy = System.getProperty("proxy");

    try {
        remoteWebDriver = new ThreadLocal<RemoteWebDriver>();
        remoteWebDriver.set(new RemoteWebDriver(new URL(SELENIUM_HUB_URL),
                capabilities));
        } catch (MalformedURLException e) {
            System.out.println("Please fix the RemoteDriverSetup.class");
        }

    remoteWebDriver.get().manage().window()
            .setSize(new Dimension(2880, 1524));
    remoteWebDriver.get().manage().timeouts()
            .pageLoadTimeout(10, TimeUnit.SECONDS);
    remoteWebDriver.get().manage().timeouts()
            .implicitlyWait(10, TimeUnit.SECONDS);

 return remoteWebDriver.get(); // Will return a thread-safe instance of the WebDriver

}

I am getting the following error :

Time elapsed: 1.044 sec  <<< FAILURE!
org.openqa.selenium.firefox.UnableToCreateProfileException: Given model profile directory does      
not exist: TEST001

Update : I am injecting method name in the BaseTest class below

@BeforeMethod 
public void startTest(Method testMethod) {
        LOG.info("Starting test: " + testMethod.getName());
        this.driver             = WebDriverSetup.getDriver(testMethod.getName());
}
  • How are you calling this? What is `methodName`? – SiKing Dec 22 '14 at 23:51
  • So every test has a separate profile? Are you sure all these profiles exist? – SiKing Dec 23 '14 at 02:22
  • Since all these tests are running on remote and these profiles does not exist, I want it to be created on the fly and assign it to the driver. Is it not possible to create a profile directory and assign it as a profile for each driver? – startedFromTheBottom Dec 23 '14 at 02:25
  • selenium default create a new profile then run the test. In case you do not need to "reuse" a profile, you donot need to do anything. If you want to assign a created profile, you need to create them first and use selenium to load them as you already did – Nguyen Vu Hoang Dec 23 '14 at 05:36

1 Answers1

0

If you don't want to customize anything on your Firefox profile, better to create Firefox webdriver instance by NOT providing any profile details (as mentioned by Nguyen).

If you really want to create separate profiles (may be required to install some plug-ins like Firebug), in that case, you can do that by without passing any file name as below:

   FirefoxProfile currentFireFoxProfile = new FirefoxProfile();
   //Do some customization - add extension
   currentFireFoxProfile.addExtension(pathOfextensionToInstall);

   //or Setup some Firefox config. switch values
   currentFireFoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
Surya
  • 4,446
  • 2
  • 17
  • 19
  • How would it impact the tests, if we are running multiple instances of RemoteWebdriver. Given that I do not set a profile at all, will each of the driver instance store the cookies in it's own default profile or will there be any chance of cookies being shared? If yes, then how should I prove that cookies are being shared or not? – startedFromTheBottom Dec 23 '14 at 11:34
  • Cookies are not shared! As Selenium makes "copy" of profile for each instance. You can test this by simple login test with different user credentials. – Surya Dec 23 '14 at 11:39