InPrivate模式下Internet Explorer中的Selenium测试

问题描述 投票:8回答:2

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

JAVA代码应该如何查找此测试? 谢谢

java internet-explorer selenium selenium-webdriver
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的解决方案is now deprecated

新的方法如下:

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值也是fixed this

© www.soinside.com 2019 - 2024. All rights reserved.