问题描述
我的项目包括Selenium Webdriver,JAVA,Maven,TestNG,Jenkins,Allure(报告).我有几套包含100多个测试用例的测试,并通过3种不同的浏览器进行了迭代(测试使用TestNG并行运行).
My project includes Selenium webdriver, JAVA, Maven, TestNG, Jenkins, Allure (reports). I have a few suites of tests with 100+ test cases, and I iterate them through 3 different browsers (the tests run in parallel using TestNG).
除非我实际上正在观察窗口并查看测试运行,否则无法通过一项测试.
There is one test that can't pass unless I am actually watching the window and see the test run.
我将解释:我要测试什么?我们的JS开发人员创建了一项功能,只有当用户将焦点放在窗口上时,图像幻灯片才会开始移动和更改图像.
I will explain: what am I trying to test? our JS developers created a feature that only if the user has focus on the window, then a image slideshow will start to move and change images.
在Firefox和Chrome上,它可以顺利通过-我不需要查看测试.焦点可以放在其他选项卡或浏览器上,驱动程序将模拟所有内容.在IEdriver上不是这样!
On Firefox and Chrome it pass great- I don't need to see the test. The focus can be on other tabs or browsers, and the driver will emulate everything. On IEdriver its not like that!!
我试图为驱动程序添加许多功能,但仍然一无所获(其中一些解决了我一些其他问题):
I have tried to add many capabilities to the driver and still nothing (some of them solved me some other issues):
}else if (browser.equalsIgnoreCase("ie")) {
String exeServiceIEdriver = Consts.ieDriverPath;
System.setProperty("webdriver.ie.driver", exeServiceIEdriver);
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability("nativeEvents", false);
ieCapabilities.setCapability("unexpectedAlertBehaviour", "accept");
ieCapabilities.setCapability("ignoreProtectedModeSettings", true);
ieCapabilities.setCapability("disable-popup-blocking", true);
ieCapabilities.setCapability("enablePersistentHover", true);
ieCapabilities.setCapability("ignoreZoomSetting", true);
//ieCapabilities.setCapability("version", "12"); does it work?? don't think so..
ieCapabilities.setCapability("requireWindowFocus", true);
//ieCapabilities.setCapability("browser_version", "9.0"); // Does NOT work. need user agent
ieCapabilities.setCapability("IE_ENSURE_CLEAN_SESSION", true); // Does NOT work. need user agent
ieCapabilities.setCapability("browserAttachTimeout",5000);
ieCapabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS,true);
ieCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);
ieCapabilities.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE,false);
driver = new InternetExplorerDriver(ieCapabilities);
Log.info("\n*** Starting IE Browser ***");
推荐答案
似乎您已选择添加所有与 InternetExplorerDriver
相关的功能.
Seems you have opted to add all the InternetExplorerDriver
related capabilities.
因此,首先,我们努力尽可能模拟用户.这意味着使用本机事件,而不是使用 JavaScript 模拟事件.
So first, we strive to emulate the user as closely as possible. This means using native events rather than simulating the events using JavaScript.
第二,我们不希望浏览器窗口的焦点自动实现.这意味着仅将浏览器窗口强制为前台是次优的.
Second, we want to not require focus of the browser window being automated. This means that just forcing the browser window to the foreground is sub-optimal.
另一个需要考虑的问题是,可能有多个IE实例在多个 WebDriver 实例下运行,这意味着任何此类 bring the window to the foreground
解决方案都必须以某种形式包装IE驱动程序的C ++代码中的同步构造(可能是mutex
).即使这样,例如,如果用户在将IE置于前台并执行本机事件的驱动程序之间将另一个窗口置于前台,则此代码仍将受到竞争条件的限制.
An additional consideration is the possibility of multiple IE instances running under multiple WebDriver instances, which means any such bring the window to the foreground
solution will have to be wrapped in some sort of synchronizing construct (probhably a mutex
) within the IE driver's C++ code. Even so, this code will still be subject to race conditions, if, for example, the user brings another window to the foreground between the driver bringing IE to the foreground and executing the native event.
有关驱动程序需求以及如何确定这两个相互冲突的目标的优先级的讨论正在进行中.当前流行的观点是优先考虑前者,并证明使用IE驱动程序时,您的计算机将无法执行其他任务.但是,该决定还远没有最终确定,实现该决定的代码可能相当复杂.
The discussion around the requirements of the driver and how to prioritize these two conflicting goals is ongoing. The current prevailing wisdom is to prioritize the former over the latter, and document that your machine will be unavailable for other tasks when using the IE driver. However, that decision is far from finalized, and the code to implement it is likely to be rather complicated.
解决方案
作为临时解决方案,您可以添加以下功能:
Solution
As an interim solution you can add the capability:
ieCapabilities.setCapability("requireWindowFocus", false);
这篇关于Selenium InternetExplorerDriver不在窗口上聚焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!