Most Viewed Pages

17.7.14

Using different Firefox Profiles with Selenium WebDriver

By default, there is just one firefox profile [called 'default'] for a given user which is used everytime one opens firefox, but using this default profile may not be the best option when running webdriver scripts.
Hence, it is better to create a new profile specifically to be used just by the webdriver.
Although, there are more powerful and effective ways to manage firefox profiles and preferences with WebDriver, but the one below is simple and effective too, and is enough for most cases. The only hitch with this method is that you will have to manually create the same firefox profile on every computer that you want to run your tests

Steps to create a new firefox profile -

•    Close all open sessions of the firefox browser
•    Type the following command on the Run window - "firefox -ProfileManager"
•    Here you will see just one profile initially, the 'default' one
•    Create a new profile and name it as 'webdriver'
•    Launch this profile and perform any configurations like disabling/enabling certain add-ons, maximize, etc
•    Close the firefox browser.
•    Now, whenever this profile will be opened, it will open with the configurations that you made.



Steps to use this new profile with webdriver -

    ProfilesIni profilesIni = new ProfilesIni();

    FirefoxProfile profile = profilesIni.getProfile("webdriverprofile");

    WebDriver foxdriver = new FirefoxDriver(profile);

We might also encounter issues with security certificates on firefox, so to overcome those, the following can be used

If the certificate is valid but self-signed
    profile.setAssumeUntrustedCertificateIssuer(true); //this is the default setting

If the certificate is invalid
    profile.setAssumeUntrustedCertificateIssuer(false);


Using this code above, the webdriver will open firefox with the profile specified, and not the default one.

No comments:

Post a Comment