有時(shí)候我們未必能夠分析故障只需用日志文件或截圖的幫助。有時(shí)捕獲完整的執(zhí)行視頻幫助。讓我們了解如何捕捉視頻。
我們將利用Monte媒體庫的執(zhí)行相同。
第1步:導(dǎo)航到URL - http://www.randelshofer.ch/monte/index.htmll和下載屏幕記錄JAR,如下圖所示。
第2步:下載后,添加JAR文件添加到當(dāng)前項(xiàng)目的庫。
第3步:我們會利用Java的AWT包來初始化顯卡配置。
GraphicsConfiguration gc = GraphicsEnvironment .getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration();
第4步:它采用下列參數(shù)創(chuàng)建ScreenRecorder的一個(gè)實(shí)例。
| 參數(shù) | 描述 |
|---|---|
| 顯卡配置 | 提供了有關(guān)顯示畫面,例如大小和分辨率信息。 |
| 視頻壓縮格式 | 電影與幀/秒的數(shù)字輸出格式(AVI)。 |
| 鼠標(biāo)光標(biāo)和刷新速率的顏色 | 指定的鼠標(biāo)光標(biāo)的顏色和刷新速率 |
| 音頻格式 | 如果'NULL'音頻不會被記錄。 |
我們將捕獲簡單的測試執(zhí)行視頻 - 百分比計(jì)算。
import java.io.File; import java.io.IOException; import java.util.concurrent.TimeUnit; import org.apache.commons.io.FileUtils; import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.WebDriver; import org.openqa.selenium.By; import org.monte.media.math.Rational; import org.monte.media.Format; import org.monte.screenrecorder.ScreenRecorder; import static org.monte.media.AudioFormatKeys.*; import static org.monte.media.VideoFormatKeys.*; import java.awt.*; public class webdriverdemo { private static ScreenRecorder screenRecorder; public static void main(String[] args) throws IOException, AWTException { GraphicsConfiguration gconfig = GraphicsEnvironment .getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration(); screenRecorder = new ScreenRecorder(gconfig, new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI), new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, CompressorNameKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, DepthKey, (int)24, FrameRateKey, Rational.valueOf(15), QualityKey, 1.0f, KeyFrameIntervalKey, (int) (15 * 60)), new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey,"black", FrameRateKey, Rational.valueOf(30)), null); WebDriver driver = new FirefoxDriver(); // Start Capturing the Video screenRecorder.start(); //Puts a Implicit wait, Will wait for 10 seconds before throwing exception driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //Launch website driver.navigate().to("http://www.calculator.net/"上一篇:Selenium IDE測試創(chuàng)建下一篇:Selenium 環(huán)境安裝設(shè)置