有没有办法记录最小化浏览器窗口的屏幕截图

时间:2016-05-02 16:31:11

标签: java selenium selenium-webdriver selenium-chromedriver screen-recording

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

1 个答案:

答案 0 :(得分:1)

是的,我们绝对可以拍多张截图。浏览器是在最小化还是最大化条件下没有影响。只需要切换新打开的窗口&在每个需要截屏的方法之后添加“截屏”方法。

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

 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;
相关问题