Selenium-capture-video

提供:Dev Guides
移動先:案内検索

セレン-ビデオをキャプチャする

ログファイルまたはスクリーンショットの助けだけでは障害を分析できない場合があります。 時には、完全な実行をビデオとしてキャプチャするのに役立ちます。 ビデオをキャプチャする方法を理解しましょう。

この操作を実行するには、Monte Media Libraryを使用します。

設定

selenium_ide_174

  • ステップ2 *-ダウンロード後、JARファイルを現在のプロジェクトのライブラリに追加します。

selenium_ide_175

  • ステップ3 *-グラフィック構成を初期化するためにJavaのAWTパッケージを使用します。
GraphicsConfiguration gc = GraphicsEnvironment
  .getLocalGraphicsEnvironment()
  .getDefaultScreenDevice()
  .getDefaultConfiguration();
  • ステップ4 *-次のパラメーターを取るScreenRecorderのインスタンスが作成されます。
Sr.No. Parameter & Description
1

GraphicsConfiguration

サイズや解像度など、ディスプレイ画面に関する情報を提供します。

2

Video and compression format

フレーム数/秒のムービーの出力形式(AVI)。

3

Color of the mouse cursor and refresh rate

マウスカーソルの色とリフレッシュレートを指定します。

4

Audio format

「NULL」の場合、音声は記録されません。

単純なテスト実行のビデオをキャプチャします-パーセント計算。

import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.awt.*;

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.*;


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 an 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/");

     //Maximize the browser
      driver.manage().window().maximize();

     //Click on Math Calculators
      driver.findElement(By.xpath(".//*[@id = 'menu']/div[3]/a")).click();

     //Click on Percent Calculators
      driver.findElement(By.xpath(".//*[@id = 'menu']/div[4]/div[3]/a")).click();

     //Enter value 10 in the first number of the percent Calculator
      driver.findElement(By.id("cpar1")).sendKeys("10");

     //Enter value 50 in the second number of the percent Calculator
      driver.findElement(By.id("cpar2")).sendKeys("50");

     //Click Calculate Button
      driver.findElement(By.xpath(".//*[@id = 'content']/table/tbody/tr/td[2]/input")).click();

     //Get the Result Text based on its xpath
      String result =
         driver.findElement(By.xpath(".//*[@id = 'content']/p[2]/span/font/b")).getText();

      File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
      FileUtils.copyFile(screenshot, new File("D:\\screenshots\\screenshots1.jpg"));

     //Print a Log In message to the screen
      System.out.println(" The Result is " + result);

     //Close the Browser.
      driver.close();

     //Stop the ScreenRecorder
      screenRecorder.stop();
   }
}

出力

録画されたビデオは、以下に示すように「C:\ users \ << UserName >> \ Videos」フォルダに保存されます。

selenium_ide_176