在InPrivate模式下使用Internet Explorer进行Selenium测试

8

有没有办法在使用IEDriverServer时在Internet Explorer 9的InPrivate模式下运行Selenium自动化测试? 我需要测试两个测试用例:
1. 浏览器关闭。 打开一个IE InPrivate模式窗口。 运行测试。
2. 浏览器以正常模式打开。 打开新的IE InPrivate模式窗口。 运行测试。

这些测试的JAVA代码应该怎么写呢?
谢谢

2个回答

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

1

@Roman的解决方案现已不建议使用

现在的做法是:

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

另外,我在进行这个操作时遇到了问题,直到我设置了TabProcGrowth注册表值。在此之前,我得到了以下异常:

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

我在使用Windows 10和Selenium 3.14时也遇到了这个问题。有趣的是,设置TabProcGrowth值同样解决了我的问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接