ADDING ADD-ON IN FIREFOX AND CHROME USING WEBDRIVER

Title sounds interesting. But think once again if you are told to start testing on instance of Firefox or Chrome installed with certain add-on then might be this article would favorably help you in time of need.
Let me do the operation on Firefox..so are you ready !!!
Steps:1-  For this we need to create one profile
FirefoxProfile firefoxprofile = new FirefoxProfile();
2- Now go to add-on’s binary download page and download the add-on with .xpi extension and save it in Default Download location.Suppose taking path of .xpi file is c:/add-on
oh still you are thinking what we need to do then
3- Read the file location by using File class that we normally use for creation of files and directories, file searching, file deletion etc.
File addonpath = new File("path of .xpi file");
4-  Now time has came to call the addExtension() of FirefoxProfile class.This method will install add-on in new profile created with new Instance of Firefox.
firefoxprofile.addExtension(addonpath);
Now pass this profile in to new instance of FirefoxDriver
As a whole this code will look like this in Eclipse to install add-on in Firefox using WebDriver

FirefoxProfile firefoxprofile = new FirefoxProfile();
File addonpath = new File("path of .xpi file");
firefoxprofile.addExtension(addonpath);
WebDriver driver = new WebDriver(firefoxprofile)
So now task is complete for Firefox but still we need to do the same for Chrome.
But don’t think that same step we are going to follow again. Because in Chrome we need to create instance of ChromeOption class . This class has many methods like addExtension()- This method is used to install add-on in new instance of Chrome, setBinary()- This method is used to Sets the path to the Chrome executable, setArguments()- Adds additional command line arguments to be used when starting Chrome.
Steps for Chrome:
1- 
Download the add-on in default location and read it using File Class again like above
File addonpath = new File("path of .crx file");
2- Now create instance of ChromeOptions
ChromeOptions chrome = new ChromeOptions();
chrome.addExtensions(addonpath);
WebDriver driver = new ChromeDriver(options);
Now we are done with both Chrome and Firefox.Hope you would like this article.