簡體   English   中英

有沒有辦法記錄最小化瀏覽器窗口的截圖

[英]Is there any way to record the screenshots of minimized browser windows

我正在使用 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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM