use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class VideoUtils method extractReferenceForSteps.
/**
* Extract the picture associated to the beginning of a step to <output_dir>/video
* @param videoFile
* @param testSteps
* @param outputDirectory
*/
public static void extractReferenceForSteps(File videoFile, List<TestStep> testSteps, Path outputDirectory) {
// create output
Path videoOutputDirectory = outputDirectory.resolve(VIDEO_DIR);
videoOutputDirectory.toFile().mkdirs();
AVIReader in = null;
try {
// Create the reader
in = new AVIReader(videoFile);
// Look for the first video track
int trackId = 0;
while (trackId < in.getTrackCount() && in.getFormat(trackId).get(MediaTypeKey) != MediaType.VIDEO) {
trackId++;
}
Map<Long, TestStep> samples = new HashMap<>();
for (TestStep testStep : testSteps) {
if (!testStep.isTestEndStep()) {
// timestamp outside of video, do not try to extract as we would get the last picture
if (testStep.getVideoTimeStamp() / 1000 * in.getTimeScale(trackId) > in.getChunkCount(0)) {
continue;
}
samples.put(min(in.timeToSample(trackId, new Rational(testStep.getVideoTimeStamp(), 1000)), in.getChunkCount(trackId) - 1), testStep);
}
}
// Read images from the track
BufferedImage img = null;
// read video and extract requested images
long i = 0;
int j = 0;
do {
img = in.read(trackId, img);
if (samples.containsKey(i)) {
Path extractedPicture = videoOutputDirectory.resolve(String.format("video-%d.jpg", j));
FileUtility.writeImage(extractedPicture.toString(), img);
Snapshot snapshot = new Snapshot(new ScreenShot(outputDirectory.relativize(extractedPicture).toString()), "Step beginning state", SnapshotCheckType.REFERENCE_ONLY);
// by default, reference snapshot won't be displayed in report. This flag will be set to "true" only if step fails and we have a reference picture from server
snapshot.setDisplayInReport(false);
samples.get(i).addSnapshot(snapshot, j, null);
j++;
}
i++;
} while (img != null);
} catch (IOException e) {
logger.error("Cannot extract step reference " + e.getMessage());
} finally {
// Close the reader
if (in != null) {
try {
in.close();
} catch (IOException e) {
logger.error("Cannot close video reader " + e.getMessage());
}
}
}
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class JiraConnector method updateIssue.
@Override
public void updateIssue(String issueId, String messageUpdate, List<ScreenShot> screenShots, TestStep lastFailedStep) {
IssueRestClient issueClient = restClient.getIssueClient();
Issue issue;
try {
issue = issueClient.getIssue(issueId).claim();
} catch (RestClientException e) {
throw new ScenarioException(String.format("Jira issue %s does not exist, cannot update it", issueId));
}
try {
if (!screenShots.isEmpty()) {
issueClient.addAttachments(issue.getAttachmentsUri(), screenShots.stream().peek(s -> logger.info("file ->" + s.getFullImagePath())).map(s -> new File(s.getFullImagePath())).collect(Collectors.toList()).toArray(new File[] {}));
}
// add comment
issueClient.addComment(issue.getCommentsUri(), Comment.valueOf(formatUpdateDescription(messageUpdate, screenShots, lastFailedStep).toString()));
logger.info(String.format("Jira %s updated", issueId));
} catch (Exception e) {
logger.error(String.format("Jira %s not modified: %s", issueId, e.getMessage()));
throw e;
}
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class JiraConnector method formatDescription.
/**
* Format description of the issue
*/
@Override
protected void formatDescription(String testName, List<TestStep> failedSteps, TestStep lastTestStep, String description, StringBuilder fullDescription) {
fullDescription.append(String.format("*Test:* %s\n", testName));
if (description != null) {
fullDescription.append(String.format("*Description:* %s\n", description.replace("Test goal:", "*Test goal:*")));
}
if (SeleniumTestsContextManager.getThreadContext().getStartedBy() != null) {
fullDescription.append(String.format("*Started by:* %s\n", SeleniumTestsContextManager.getThreadContext().getStartedBy()));
}
for (TestStep failedStep : failedSteps) {
fullDescription.append(String.format("*Error step #%d (%s):* *{color:#de350b}%s{color}*\n", failedStep.getPosition(), failedStep.getName(), failedStep.getActionException()));
}
formatFailedStep(failedSteps, fullDescription);
fullDescription.append("h2. Last logs\n");
if (lastTestStep != null) {
fullDescription.append(String.format("{code:java}%s{code}", lastTestStep.toString()));
fullDescription.append("\n\nh2. Associated screenshots\n");
List<ScreenShot> screenshots = lastTestStep.getSnapshots().stream().map(Snapshot::getScreenshot).collect(Collectors.toList());
for (ScreenShot screenshot : screenshots) {
if (screenshot.getFullImagePath() != null && new File(screenshot.getFullImagePath()).exists()) {
fullDescription.append(String.format("!%s|thumbnail!\n", new File(screenshot.getFullImagePath()).getName()));
}
}
}
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class PageObject method captureViewportSnapshot.
/**
* Capture a page snapshot for storing in test step
* @param snapshotName the snapshot name
* @param checkSnapshot if true, will send snapshot to server (when seleniumRobot is configured for this) for comparison
*/
public void captureViewportSnapshot(String snapshotName, SnapshotCheckType checkSnapshot) {
ScreenShot screenShot = screenshotUtil.capture(SnapshotTarget.VIEWPORT, ScreenShot.class);
// check SnapshotCheckType configuration is compatible with the snapshot
checkSnapshot.check(SnapshotTarget.VIEWPORT);
storeSnapshot(snapshotName, screenShot, checkSnapshot);
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class PageObject method capturePageSnapshot.
/**
* Capture a page snapshot for storing in test step
* @param snapshotName the snapshot name
* @param checkSnapshot if true, will send snapshot to server (when seleniumRobot is configured for this) for comparison
*/
public void capturePageSnapshot(String snapshotName, SnapshotCheckType checkSnapshot) {
ScreenShot screenShot = screenshotUtil.capture(SnapshotTarget.PAGE, ScreenShot.class, computeScrollDelay(checkSnapshot));
// check SnapshotCheckType configuration is compatible with the snapshot
checkSnapshot.check(SnapshotTarget.PAGE);
storeSnapshot(snapshotName, screenShot, checkSnapshot);
}
Aggregations