【问题标题】:Is there any way to record the screenshots of minimized browser windows有没有办法记录最小化浏览器窗口的截图
【发布时间】:2016-08-27 11:58:22
【问题描述】:

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

【问题讨论】:

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


    【解决方案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;
    

    【讨论】:

    猜你喜欢
    • 2018-10-13
    • 1970-01-01
    • 2017-07-27
    • 2010-09-09
    • 2014-11-25
    • 1970-01-01
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    相关资源
    最近更新 更多