Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium test in Internet Explorer in InPrivate mode

Is there any way how to run Selenium automation test in Internet Explorer 9 in InPrivate mode with IEDriverServer? I need to test 2 (two) testcases:
1. browser is closed. Open one window of IE InPrivate mode. Run test.
2. browser is opened in normal mode. Open new window of IE InPrivate mode. Run test.

How should JAVA code look for this tests?
Thank you

like image 673
sturman Avatar asked Jun 12 '13 11:06

sturman


People also ask

Can Selenium be used with Internet Explorer?

Since Selenium gives the option of running our tests in multiple browsers, Selenium with IE browser blending can be used to test any application. IE has a driver, which creates a connection between Selenium WebDriver and IE. and then executes the Selenium tests on Internet Explorer.

How do I open Selenium incognito mode?

There are two main ways to execute our selenium Test in Incognito Mode for Chrome Browser. v Right Click on Google Chrome and Select Properties. v In the “Target' field add an –incognito to the end of the program path. v Our incognito browser is now ready for execution.

Is it possible to run a Selenium test without using a real browser?

We can perform Selenium testing without a browser. This is achieved by triggering the execution in a headless mode. The headless execution can decrease the utilization of key resources and is being adopted widely.


2 Answers

public void openBrowserInPrivacyMode(boolean isBrowserActive) {
    System.setProperty("webdriver.ie.driver", "path/to/IEDriverServer_x32.exe"); 
    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();  
    capabilities.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);  
    сapabilities.setCapability(InternetExplorerDriver.IE_SWITCHES, "-private");
    InternetExplorerDriver driver = new InternetExplorerDriver(capabilities);
like image 196
sturman Avatar answered Oct 20 '22 00:10

sturman


@Roman's solution is now deprecated.

The new way to do this is as follows:

InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);
ieOptions.addCommandSwitches("-private");
InternetExplorerDriver driver = InternetExplorerDriver(ieOptions));

Also, I had problems doing this, until I set a TabProcGrowth registry value. Before doing this I got the following exception:

org.openqa.selenium.SessionNotCreatedException: Unexpected error launching Internet Explorer.
Unable to use CreateProcess() API. To use CreateProcess() with Internet Explorer 8 or higher,
the value of registry setting in
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\TabProcGrowth must be '0'.

I had this with happening with Windows 10 and Selenium 3.14. Curiously enough, setting the TabProcGrowth value also fixed this for me.

like image 36
mapto Avatar answered Oct 19 '22 23:10

mapto