Friday, April 17, 2015

Handling Firefox Profiles & Synchronization in Selenium

What is Profile – By profile, it is meant the default setting which your browser takes while opening the webpage. For Example in your profile you can save your Favorites, your default homepage and other settings.

You can create a new Fireox profile by running the below command on your windows search bar:

Firefox.exe –profilemanager

Below is what profile manager looks like and with this you can Create a new Profile , Rename an existing Profile or even delete a Profile.



Now, how to tell Selenium, to open which Website to open on What Profile? Below is the solution for that:

Add these lines into your code:

-----------------------------------

ProfilesIni listprofiles = new ProfilesIni();
FirefoxProfile profile = listprofiles.getProfile("Selenium"); // Considering Selenium is the name of the profile to be loaded
WebDriver driver = new FirefoxDriver(profile);


---------------------------------

Opening two browsers in different profiles:
In the below code we create two Firefox profiles and respectively two driver objects as well. driver1, uses default profile and navigates to www.yahoo.com and driver uses selenium profile to navigate to www.google.com.

-----------------------------------

ProfilesIni listprofiles = new ProfilesIni();
FirefoxProfile profile = listprofiles.getProfile("Selenium"); // Considering Selenium is the name of the profile to be loaded
FirefoxProfile profile1 = listprofiles.getProfile("default");
WebDriver driver = new FirefoxDriver(profile);
WebDriver driver1 = new FirefoxDriver(profile1);
driver.get("http://www.google.com");
driver1.get("http://www.yahoo.com");


---------------------------------


Usage: This piece mostly comes in handy where you are automating a projects where in you need to download some files which you can easily configure to be different than your regular download area, so that files are easily separated and can be handled easily. Also, you can easily manage the websites where in certificates are required.

No comments:

Post a Comment