Launch Private Browser, With Add-ons, and With Proxy

Launch Browser in incognito or private mode
In chrome use -incognito command line switch in options:

ChromeOptions options = new ChromeOptions(); options.addArguments(“incognito”);
DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, options);

For Firefox:

FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setPreference(“browser.private.browsing.autostart”,true); For IE:
setCapability(InternetExplorerDriver.IE_SWITCHES, “-private”);

Launch browser with Add-ons (aka extension)
If you want specific add-on on a new clean browser:
For Firefox: using firebug as an example:

File file = new File(“firebug-1.8.1.xpi”);
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
firefoxProfile.setPreference(“extensions.firebug.currentVersion”, “1.8.1”);
WebDriver driver = new FirefoxDriver(firefoxProfile);

For chrome:

ChromeOptions options = new ChromeOptions();
options.addExtensions(new File(“/path/to/extension.crx”));
ChromeDriver driver = new ChromeDriver(options);

If add-on is Unpacked (directory)

ChromeOptions options = new ChromeOptions();
options.addArguments(“load-extension=/path/to/extension”);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);

Add proxy to browser

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
// Add the WebDriver proxy capability.
Proxy proxy = new Proxy(); proxy.setHttpProxy(“myhttpproxy:3337”);
capabilities.setCapability(“proxy”, proxy);
// Add ChromeDriver-specific capabilities through ChromeOptions.
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File(“/path/to/extension.crx”));
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);