Monday, May 30, 2016

Using an user defined firefox profile during webdriver test

You must have observed that we we run our test using webdriver, firefox driver open an instance of browser where there are no addons, bookmarks or any other things available. This is because it uses a instance with blank/new profile every time. But what if we need to test in a predefined profile like, any test case prerequisite is that , any addon must be installed in browser, book marks , or any other setting. 

We can do this by using user defined profile. To do so, follow below steps:

1- Close you browser.
2- In start go to run and type "firefox.exe -p" 
3- This will open a window where your profile are listed. Here we can create , modify , delete ect profiles.
4- If you see there will a default profile. we can use that as well for our test.
5- If you need, create a specific profile as required.

Now see how we can use any profile in webdriver.

package practiceTestNG;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;

public class fireforxProfile {

    public static void main(String[] args)
    {
        ProfilesIni p = new ProfilesIni();
        FirefoxProfile fp = p.getProfile("default");
        WebDriver driver = new FirefoxDriver(fp);
        driver.get("https://www.vishalsachan.blogspot.com");
    }

}

 
In above code, you see we have used 'default' profile in our webdriver. now when you run this , you test will be open in a browser where u can see your addons, bookmarks ect.
 

No comments :

Post a Comment