有没有任何方法可以记录最小化浏览器窗口的屏幕截图



我正在使用Java和selenium编写一些测试。当测试运行时,我需要有我的屏幕记录,这会让我更容易跟踪是否出现任何错误。问题是,我需要同时运行多个测试,由于我只有一个监视器,我无法同时记录他们的所有屏幕记录,所以我必须一个接一个地运行测试。我想知道是否有任何方法可以运行我所有的测试,并实际最小化他们的浏览器窗口,但仍然记录每个最小化的chrome窗口上发生的事情。我的问题听起来可能有点奇怪,但这让我的测试速度非常快。

是的,我们当然可以拍多张屏幕截图。无论浏览器处于最小化还是最大化状态,都不会受到影响。你只需要切换新打开的窗口&在每个需要截图的方法后面添加"截图"方法。

当浏览器处于最小化或最大化条件时,截屏方法可以在这两种模式下工作。对于屏幕截图,您可以使用以下代码:

 public void getscreenshot() throws Exception 
  {
          File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
       //The below method will save the screen shot in d drive with name "screenshot.png"
          FileUtils.copyFile(scrFile, new File("D:\screenshot.png"));
  }

或者你可以选择多屏幕捕获,其代码如下:

public void GoogleAbout() throws Exception {
driver.get(baseUrl); // Enter the URL as per your choice
driver.findElement(By.linkText(Prop.getProperty("AboutLinkText"))).click(); //find the web element
MultiScreenShot multiScreens = new MultiScreenShot("C:\New\","GoogleAbout"); // Here we need to create the object which will take two arguement one is the path to save the file and second one is class name
multiScreens.multiScreenShot(driver);
driver.findElement(By.linkText("More about our philosophy")).click();
multiScreens.multiScreenShot(driver);

}

要启用多屏幕截图,您必须下载JAR文件,然后将其附加到您的项目中,然后:

import multiScreenShot.MultiScreenShot;

相关内容

最新更新