
com.infotel.seleniumrobot.grid.tasks.video.StopVideoCaptureTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of seleniumRobot-grid4 Show documentation
Show all versions of seleniumRobot-grid4 Show documentation
Selenium grid extension for mobile testing
The newest version!
package com.infotel.seleniumrobot.grid.tasks.video;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.seleniumtests.driver.CustomEventFiringWebDriver;
import com.seleniumtests.driver.DriverMode;
import com.seleniumtests.util.video.VideoRecorder;
public class StopVideoCaptureTask extends VideoCaptureTask {
private static final Logger logger = LogManager.getLogger(StopVideoCaptureTask.class);
private static Map recordedFiles = Collections.synchronizedMap(new HashMap<>());
private String sessionId;
private File videoFile;
public StopVideoCaptureTask(String sessionId) {
this.sessionId = sessionId;
}
@SuppressWarnings("unchecked")
@Override
public StopVideoCaptureTask execute() throws Exception {
logger.info("stop video capture for session: " + sessionId);
// check if some files have been cleaned and delete their reference
List keysToRemove;
synchronized(recordedFiles) {
keysToRemove = recordedFiles
.entrySet()
.stream()
.filter(entry -> !entry.getValue().exists())
.map(e -> e.getKey()).collect(Collectors.toList());
}
for (String name: keysToRemove) {
recordedFiles.remove(name);
}
VideoRecorder recorder = videoRecorders.remove(sessionId);
File knownFile = recordedFiles.get(sessionId);
if (recorder == null) {
if (knownFile == null) {
return this;
} else {
videoFile = knownFile;
}
} else {
videoFile = CustomEventFiringWebDriver.stopVideoCapture(DriverMode.LOCAL, null, recorder);
}
if (videoFile != null) {
recordedFiles.put(sessionId, videoFile);
}
logger.info("video capture stopped");
return this;
}
public File getVideoFile() {
return videoFile;
}
public static Map getRecordedFiles() {
return recordedFiles;
}
public static void setRecordedFiles(Map recordedFiles) {
StopVideoCaptureTask.recordedFiles = recordedFiles;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy