【发布时间】:2018-11-02 23:27:25
【问题描述】:
我在 Selenium Webriver 自动化中创建了下一个录制视频的类。
首先,为此我使用的是 Monte Media jar(POM 中的依赖项):
<dependency>
<groupId>com.github.stephenc.monte</groupId>
<artifactId>monte-screen-recorder</artifactId>
<version>0.7.7.0</version>
</dependency>
我创建的类是下一个:
public class Video {
private static final Logger logger = LogManager.getLogger(Video.class);
private Properties prop = null;
private String path = "";
private String prefix = "";
private String extension = "";
private String time = "";
private static ScreenRecorder screenRecorder;
public void setUp() throws Exception {
//Crea una instancia de GraphicsConfiguration para obener la configuración gráfica.
//de la pantalla.
GraphicsConfiguration gc = GraphicsEnvironment//
.getLocalGraphicsEnvironment()//
.getDefaultScreenDevice()//
.getDefaultConfiguration();
//Crea la instancia del grabador de video con la configuración necesaria.
ScreenRecorder screenRecorder = new ScreenRecorder(gc,
new Format(MediaTypeKey, FormatKeys.MediaType.FILE, MimeTypeKey, MIME_AVI),
new Format(MediaTypeKey, FormatKeys.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);
}
public static void iniciaGrabacion(InternetExplorerDriver driver)throws Exception{
//Método para comenzar de la grabación.
screenRecorder.start();
}
public static void finalizaGrabacion(InternetExplorerDriver driver)throws Exception{
//Método para finalizar de la grabación.
screenRecorder.stop();
}
private void prepareVariables() {
try {
prop = AppConfigUtil.getInstance().getProperties();
} catch (AppConfigException e) {
logger.error(e);
}
path = (String) prop.get("video.path");
prefix = (String) prop.get("video.prefix");
extension = (String) prop.get("video.extension");
LocalDateTime localDateTime = LocalDateTime.now();
time = "" + localDateTime.getYear() + localDateTime.getMonthValue() + localDateTime.getDayOfMonth() + localDateTime.getHour() + localDateTime.getMinute() + localDateTime.getSecond() + localDateTime.getNano();
}
我想要做的是调用静态 void 方法来开始录制 (iniciaGrabacion) 并从任何其他类中停止录制 (finalizaGrabacion),而不是在我发布的同一类中。
public static void iniciaGrabacion(InternetExplorerDriver driver)throws Exception{
//Método para comenzar de la grabación.
screenRecorder.start();
}
public static void finalizaGrabacion(InternetExplorerDriver driver)throws Exception{
//Método para finalizar de la grabación.
screenRecorder.stop();
我运行任何其他类,用这些行调用这些方法:
Video.iniciaGrabacion((InternetExplorerDriver)driver);
关闭:
Video.finalizaGrabacion((InternetExplorerDriver)driver);
但我面临下一个问题:
java.lang.NullPointerException
at cl.chilito.util.report.Video.iniciaGrabacion(Video.java:63)
at cl.chile.automatizacion.casos.prestamos.PrestamoNuevoK.PrestamoNuevoK(PrestamoNuevoK.java:97)
at cl.chile.automatizacion.casos.prestamos.PrestamoNuevoK.testPrestamoNuevoK(PrestamoNuevoK.java:78)
有人可以帮我解决这个问题吗?
【问题讨论】:
-
本题重点是录屏,NullPointException就是结果。
标签: java selenium-webdriver video screen-recording