What is Firefox profile, Need of Firefox profile?

What is Firefox Profile?
When we install Mozilla Firefox, Firefox creates a default profile, it contains a collection of bookmarks, extensions, passwords, history, preferred home page when you open browser, and another browser setting etc. …,
                We can customize this Firefox profile as per our automation testing need.  So, one can say like Firefox profile is nothing but different user is using Firefox.
Why do we need to Set Firefox Profile in Selenium WebDriver? 
Default Firefox contains a collection of bookmarks, browser settings, extensions, passwords, and history; in short, all of your personal settings.
When you trigger selenium with this browser you test become slow and unreliable. To make it lighter we generally create a custom profile which loads only required plugins and extensions with predefined settings.
In order to run all test successful, we need a browser which –
  • Loads easily (very lightweight profile
  • Proxy setting (if required)
  • SSL certifications handling (if required)
  • Company specific username and password to start browser (if required)
How to create Firefox Profile in Selenium WebDriver?
Let us assume that you wanted to have google as the startup page for Firefox. To do this we will need to update the “browser.startup.homepage” preference.
Follow below steps to add a website as your homepage:
1. Let’s first start by creating the FirefoxProfile object.
2. Now we will set the preference by using the below method.
3. To get the profile to be used, we need to pass it in to the driver. To do this, we need
to do the following:
FirefoxProfile ffprofile= new FirefoxProfile();

profile.setPreference("browser.startup.homepage","http://www.google.com");

WebDriver driver = new FirefoxDriver(ffprofile);

That’s it, this is all we can set Firefox profile.

Let us see some examples where we can use this Firefox Profile setting.

Below two articles explain the real time use of Firefox profile –

How to handle proxy setting using selenium Webdriver? 

How to Handle SSL Untrusted Connection in Selenium WebDriver ?

How to handle proxy setting using selenium Webdriver?

 In this article, i will talk about How to handle proxy setting using selenium Webdriver?
Suggested Article to read: What is Firefox profile, Need of Firefox profile?

If we try to access some secure application, we get proxy related error many times and manually we need to update the proxy there. But what if we are automating that secure application? Our automation code should handle this.

Some applications have also issues related to SSL certification error. We again do that manually by accepting & confirming the certificate. But again, what if this encounter when we automate application using selenium Webdriver?
In this post, let’s talk about how to handle proxy setting using selenium Webdriver?
While setting up the proxy, note that there are different values for network.proxy.type , which we need to set based on our need. Here are some values –
0 – Direct connection (or) no proxy.
1 – Manual proxy configuration
2 – Proxy auto-configuration (PAC).
4 – Auto-detect proxy settings.
5 – Use system proxy settings.
Below 4 steps explain how can we handle proxy setting via selenium
Step1: Create the FirefoxProfile object.
Step2: Set preference for network.proxy.type
Step3: Set preference for network.proxy.http
Step4: network.proxy.http_port
    FirefoxProfile profile = new FirefoxProfile();

    profile.setPreference("network.proxy.type", 1);

    profile.setPreference("network.proxy.http", "proxy.domain.example.com");

    profile.setPreference("network.proxy.http_port", 8080);

    profile.setPreference("network.proxy.ssl", "proxy.domain.example.com");

    profile.setPreference("network.proxy.ssl_port", 8080);

    WebDriver driver = new FirefoxDriver(profile);

That’s it, this should handle the updated proxy in code.

Hope this helps. Drop your comments.

How to Handle SSL Untrusted Connection in Selenium WebDriver ?

In this article, i will talk about how to handle SSL Untrusted connection in selenium webdriver.
Suggested Article to read: What is Firefox profile, Need of Firefox profile?

Handling SSL Untrusted Connection in Selenium WebDriver

Some applications have issues related to SSL certification error. We again do that manually by accepting & confirming the certificate. But again, what if this encounter when we automate application using selenium Webdriver?
Using profiles in Firefox we can handle accept the SSL untrusted connection certificate. Profiles are basically set of user preferences stored in a file.
Let’s consider the Firefox browser to create a new profile and set the following:
Handle Untrusted certificate (SSL Certificate error) in Firefox
FirefoxProfile profile = new FirefoxProfile();

profile.setAcceptUntrustedCertificates(true); 

profile.setAssumeUntrustedCertificateIssuer(false);

WebDriver driver = new FirefoxDriver(profile);

Handle Untrusted certificate (SSL Certificate error) in Chrome
To Handle SSL certification error in chrome, we need to Create object of DesiredCapabilities class. Basically, the DesiredCapabilities help to set properties for the WebDriver. The DesiredCapabilities class tells the Webdriver which environment we are going to use for test execution.
DesiredCapabilities cap=DesiredCapabilities.chrome();

// Set ACCEPT_SSL_CERTS  variable to true

cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

// Set the driver path

System.setProperty("webdriver.chrome.driver","Chrome driver path");

// Open browser with capability

WebDriver driver=new ChromeDriver(cap);

Handle Untrusted certificate (SSL Certificate error) in IE

// Create object of DesiredCapabilities class

DesiredCapabilities cap=DesiredCapabilities.internetExplorer();

// Set ACCEPT_SSL_CERTS  variable to true

cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

// Set the driver path

System.setProperty("webdriver.ie.driver","IE driver path");

// Open browser with capability

WebDriver driver=newInternetExplorerDriver(cap);

Hope this helps ….