java selenium 视频_使用Selenium实现捕捉视频

package com.demo.test;

import static org.monte.media.FormatKeys.EncodingKey;

import static org.monte.media.FormatKeys.FrameRateKey;

import static org.monte.media.FormatKeys.KeyFrameIntervalKey;

import static org.monte.media.FormatKeys.MIME_AVI;

import static org.monte.media.FormatKeys.MediaTypeKey;

import static org.monte.media.FormatKeys.MimeTypeKey;

import static org.monte.media.VideoFormatKeys.CompressorNameKey;

import static org.monte.media.VideoFormatKeys.DepthKey;

import static org.monte.media.VideoFormatKeys.ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE;

import static org.monte.media.VideoFormatKeys.QualityKey;

import java.awt.AWTException;

import java.awt.GraphicsConfiguration;

import java.awt.GraphicsEnvironment;

import java.io.File;

import java.io.IOException;

import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;

import org.monte.media.Format;

import org.monte.media.FormatKeys.MediaType;

import org.monte.media.math.Rational;

import org.monte.screenrecorder.ScreenRecorder;

import org.openqa.selenium.By;

import org.openqa.selenium.Keys;

import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

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 ChromeDriver();

// 开始捕获视频

screenRecorder.start();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.navigate().to("https://www.baidu.com/");

driver.manage().window().maximize();

for (int i = 0; i < 3; i++) {

driver.findElement(By.id("kw")).sendKeys("selenium", Keys.ENTER);

driver.navigate().forward();

driver.navigate().back();

try {

Thread.sleep(3000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

FileUtils.copyFile(screenshot, new File("D:screenshotsscreenshots1.jpg"));

// 停止捕获视频

screenRecorder.stop();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值