Browser's Profile in Selenium WebDriver

 Browser's Profile in Selenium WebDriver


Before we start off the Selenium WebDriver, we need to clarify some basic ideas.In this article, we will discuss about Firefox browser's profile , for example, mainly a custom Firefox Profile and an Anonymous Profile.This a basic concept that most of the Internet users know about it.However, I thought that it will be helpful to start from the ground.

 A Firefox browser uses a folder that is known as Firefox profile to store users bookmarks settings, passwords as well as all other data. Any number of profiles can be created by a Firefox user with different custom settings and can use it accordingly.If you intend to see the profile folder from the browser you just open the browser and type in the address bar or navigate to Help from the browser menu; then choose Troubleshooting Information.Here check Application Basics section for Profile Directory.

To create, edit or delete any Firefox profile in Firefox please follow the instruction here -

Since I am using a Linux machine I just opened up a terminal and typed
firefox -P .This command will open up the Firefox Profile Manager and I just created a profile.Once we put the pointer on the newly created profile it shows up the profile path which we need to put into the source code to load the browser.

If you are using a Windows machine to do that you just need to press (Windows + R) keys and type in there firefox.exe -P which opens up the
Firefox Profile manager.If you are still in vague just follow this link (http://kb.mozillazine.org/Creating_a_new_Firefox_profile_on_Windows) and create one.

Once we are all done.We are ready to go.
N.B: It is recommended to have the latest versions of the browsers for testing the web applications with Selenium WebDriver.

Now I am going explain why the heck I created a Custom Firefox Profile.
What is the purpose behind it? OK, alright. Here is the deal:
When we execute a test it will create an anonymous profile each time by default it is because we did not bind any profile in our source code. So, now we may ask questions what's wrong with that?Yes, there is a problem with it.If you observe the DOM of Gmail, for instance, with an anonymous profile you will find that its DOM structure is way different from the other profile (let's say google plus profile). This will clarify in the source code in comments.By chance if we use absolute XPATH (in our code) to locate any web elements in the DOM and later use the same absolute XPATH for google plus profile(it will fail to locate since DOM is different). Another point is that if we install Firebug or any other add-ons in the browser we will be able to use them to locate web elements. Conversely, we won't be able to use Firebug if we are using an anonymous profile.
From my 2+ years Selenium experience I found that it saves a lot of time and reduces stress at the same time.

If you want I can make one more article about it including the Frozen Preferences.
Thanks and if you have anything to ask just let me know.Name is java file as OpenBrowser.java

package googleplus.firefox;
import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
public class OpenBrowser{
public static void main(String [] args){
    // anonymous profile is gonna be created by WebDriver
     WebDriver  driver = new FirefoxDriver();
    //USE THIS CODE FOR THE CUSTOM PROFILE
    /**
    String path ="C://Users//bhordupur//AppData//Roaming//Mozilla//Firefox//Profiles  //googleplus";
    FirefoxProfile customProfile = new FirefoxProfile(new File(path));
    //use the browser installed in your workstation
    // simply copy the path where your browser is
    String p = "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" ;
    File f = new File(p);
    FirefoxBinary getBinary = new FirefoxBinary(f);
    FirefoxProfile createProfile = new FirefoxProfile();
    FirefoxDriver driver = new FirefoxDriver(getBinary,createProfile);
     
    // TO USE THE CUSTOM PROFILE(googleplus)FIREFOX
    String path ="//home//bhordupur//.mozilla//firefox//wnhd6wb8.googleplus";
    FirefoxProfile customProfile = new FirefoxProfile(new File(path));
    **/
    //BROWSE TO GOOGLE.FI
    driver.get("http://google.fi/");
    // GET THE URL
    System.out.println(driver.getCurrentUrl());
    // close the browser
    driver.close();
    }
}

Comments

Popular posts from this blog

Implicitly Wait in Selenium WebDriver

Explicitly Wait in Selenium WebDriver

How to take a screenshot in Selenium WebDriver