How does FirefoxDriver opens the Firefox Browser?


Did you ever think,when you give a command  driver = new FirefoxDriver(); How the browser was invoked? How come it invokes the version of the browser without adding any extensions to it? If this strikes your mind,here you can see the workflow.

When the following line is executed

FirefoxDriver driver = new FirefoxDriver(); There undergoes few steps to set up and invoke the browser. 

Step 1: Grab the port
a)By default firefox attempts to grab the port 7055
b)7055-1 = 7054, This is called as locking port, which we use as a mutex to make sure only one instance of firefox is started at the time
c)Sit in a loop waiting the the locking port to become free
d)Exit loop when we can establish a connection to the server socket(A server socket waits for requests to come in over the network. It performs some operation based on that request, and then possibly returns a result to the requester.) to the locking port. This driver now has the mutex

Step 2 : Find the next free port up from the locking port
Identify the next free port above the locked one by attempting to bind to each of them in turn. Release the newly found port. For the first driver, this will be 7055.

Until this point the FirefoxDriver has created a socket and FirefoxDriver is listening at the port 7055 for the incoming commands that needs to be executed
But we have not yet launched the browser

Step 3 : Locate the Firefox profile to use. This is normally an anonymous one

Step 4 : Copy the existing profile to a temporary directory,

Step 5 : Delete the current “extensions.cache” to force Firefox to look for newly installed extensions on start up.

Step 6 : Update “user.js” with the preferences required to make WebDriver work as expected.
(This is where the Capabilities are set for the browser, Eg EnableJavascript etc)

Step 7 : Set the “webdriver_firefox_port” value to the one that we found in the step 2.

Until this point the FirefoxDriver has created a socket and FirefoxDriver is listening at the port 7055 for the incoming commands that needs to be executed
We have selected the profile(default) or the one given from code and the Desired Capabilities are set.

Step 8 : Start Firefox with the “-silent” flag and telling it to use the freshly minted directory as the profile.
Finally, we launch the Firefox Browser which we can see..!!

Step 9 : Wait until that Firefox instance has finished and the process has died.

Step 10 : Release the locking port. The mutex has now been freed.

This is how it works. Truly found this article somewhere in the internet. Thanks to that blogger.

\

Advertisements

3 thoughts on “How does FirefoxDriver opens the Firefox Browser?

    • charan163 November 1, 2015 / 9:19 am

      Thanks for sharing.We were looking for it.

      Like

  1. Anonymous January 27, 2016 / 5:21 pm

    Thanks for sharing :)

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s