Wednesday, February 4, 2015

How FirefoxDriver opens the firefox browser?

When the following line is executed

FirefoxDriver driver = new FirefoxDriver();

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

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

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

4)Copy the existing profile to a temporary directory,

5)Delete the current "extensions.cache" to force Firefox to look for newly installed extensions on start up.

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)

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

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..!!

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

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

Handle Race Condition in Alerts with Webdriver 
A beta features which makes Firefox Faster 
Enable Firebug in Session started by FirefoxDriver  
How FirefoxDriver Executes the Selenium Commands 

1 comment: