Selenium InternetExplorerDriver不关注风

2024-05-02 08:37:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我的项目包括Selenium webdriver、JAVA、Maven、TestNG、Jenkins、Allure(报告)。我有几个测试套件,有100多个测试用例,我在3个不同的浏览器中迭代它们(测试使用TestNG并行运行)。在

有一个测试不能通过,除非我真的在观察窗口并看到测试运行。在

我会解释:我想测试什么?我们的JS开发人员创建了一个功能,只有当用户将焦点放在窗口上时,图像幻灯片才会开始移动和更改图像。在

在Firefox和Chrome上,它通过得很好-我不需要看测试。焦点可以放在其他选项卡或浏览器上,驱动程序将模拟一切。不是那个司机!!在

我尝试为驱动程序添加许多功能,但仍然没有效果(其中一些功能解决了我一些其他问题):

}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 ***");

Tags: 图像功能browsertruedriver驱动程序浏览器ie
1条回答
网友
1楼 · 发布于 2024-05-02 08:37:15

似乎您已经选择添加所有的InternetExplorerDriver相关功能。在

^{}

The challenge is that IE itself appears to not fully respect the Windows messages we send to the IE browser window (WM_MOUSEDOWN and WM_MOUSEUP) if the window doesn't have the focus. Specifically, the element being clicked on will receive a focus window around it, but the click will not be processed by the element. Arguably, we shouldn't be sending messages at all; rather, we should be using the SendInput() API, but that API explicitly requires the window to have the focus. We have two conflicting goals with the WebDriver project.

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.

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.

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.

解决方案

作为临时解决方案,您可以添加以下功能:

ieCapabilities.setCapability("requireWindowFocus", false);

相关问题 更多 >