I want to test my test cases in private window or incognito window.
How to do the same in various browsers:
public static void OpenBrowser() {
if (Browser.equals("Chrome")) {
System.setProperty("webdriver.chrome.driver", "E:\\Workspace\\proj\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("incognito");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
} else if (Browser.equals("IE")) {
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, false);
// if you get this exception "org.openqa.selenium.remote.SessionNotFoundException: " . uncomment the below line and comment the above line
// capabilities.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);
System.setProperty("webdriver.ie.driver", "E:\\Workspace\\proj\\IEDriverServer32.exe");capabilities.setCapability(InternetExplorerDriver.IE_SWITCHES, "-private");
driver = new InternetExplorerDriver(capabilities);
} else {
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.privatebrowsing.autostart", true);
driver = new FirefoxDriver(firefoxProfile);
}