Selenium test in Internet Explorer in InPrivate mode

强颜欢笑 提交于 2021-02-18 22:11:12

问题


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


回答1:


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);



回答2:


@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.



来源:https://stackoverflow.com/questions/17064512/selenium-test-in-internet-explorer-in-inprivate-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!