I want to test my test cases in private window or incognito window.
How to do the same in various browsers:
How to achieve it?
The easiest way to open an Incognito window is with the keyboard shortcut combination Ctrl-Shift-N (Windows) or Command-Shift-N (macOS). Another way is to click on the menu on the upper right - it's the three vertical dots - and select New Incognito Window from the list.
We can open a browser window in incognito/private mode with Selenium webdriver in Python using the ChromeOptions class.
In Incognito, none of your browsing history, cookies and site data, or information entered in forms are saved on your device. This means your activity doesn't show up in your Chrome browser history, so people who also use your device won't see your activity.
To open an incognito tab in Chrome Browser, one has to tap on the three dots at the corner of the screen and then select the New incognito tab option. A new window with an incognito tab will open in front of you, further to open multiple incognito tabs tap on the plus icon present at the side of the tab.
Chrome:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("incognito");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
FireFox:
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.privatebrowsing.autostart", true);
Internet Explorer:
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);
capabilities.setCapability(InternetExplorerDriver.IE_SWITCHES, "-private");
Opera:
DesiredCapabilities capabilities = DesiredCapabilities.operaBlink();
OperaOptions options = new OperaOptions();
options.addArguments("private");
capabilities.setCapability(OperaOptions.CAPABILITY, options);
In chrome you can try using -incognito
command line switch in options, not sure if there will be a problem with automation extension but worth a try.
ChromeOptions options = new ChromeOptions();
options.addArguments("incognito");
For FireFox, a special flag in the profile can be used for the purpose
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.private.browsing.autostart",true);
For IE
setCapability(InternetExplorerDriver.IE_SWITCHES, "-private");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With