如何使用Chrome网络驱动程序测试Chrome浏览器的打印预览?

如何使用Chrome网络驱动程序测试Chrome浏览器的打印预览?

问题描述:

我尝试使用

    String winHandleBefore = driver.getWindowHandle();
    <code to print>
    for (String winHandle : driver.getWindowHandles())
         driver.switchTo().window(winHandle);
    driver.findElement(By.className("cancel")).click();
    driver.switchTo().window(winHandleBefore);

这会在打开打印预览页面后挂断我的测试用例执行.

This hangs my test case execution after it opens the print preview page.

也尝试过使用javascript executor方法,但是没有用.

Also tried with javascript executor method, but no use.

   JavascriptExecutor jse = (JavascriptExecutor) driver;
   jse.executeScript("window.close()", "");

请建议是否有可能.

我找到了我问题的答案.我在下面的代码段中使用过.

I have found the answer to my question. I used below code snippet.

 //Create a Region for Desktop Screen
 ScreenRegion s = new DesktopScreenRegion();
 //Find target with below Image in Desktop Screen
 Target target = new ImageTarget(new File("Image.png"));
 ScreenRegion r = s.find(target);
 // Create a mouse object
 Mouse mouse = new DesktopMouse();
 // Use the mouse object to click on the center of the target region
 mouse.click(r.getCenter());

借助此代码片段,您将能够找到printcancel并进行鼠标单击事件并继续进行硒测试.可以使用sikuli API

With the help of this snippet you would able to find the print or cancel and do the mouse click event and proceed with selenium tests. This was possible using sikuli API