Search in sources :

Example 31 with ScreenShot

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());
            }
        }
    }
}
Also used : Path(java.nio.file.Path) AVIReader(com.seleniumtests.util.video.avi.AVIReader) TestStep(com.seleniumtests.reporter.logger.TestStep) Rational(org.monte.media.math.Rational) HashMap(java.util.HashMap) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot)

Example 32 with ScreenShot

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;
    }
}
Also used : Arrays(java.util.Arrays) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) CimFieldInfo(com.atlassian.jira.rest.client.api.domain.CimFieldInfo) Priority(com.atlassian.jira.rest.client.api.domain.Priority) Issue(com.atlassian.jira.rest.client.api.domain.Issue) URISyntaxException(java.net.URISyntaxException) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) HashMap(java.util.HashMap) Snapshot(com.seleniumtests.reporter.logger.Snapshot) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) SeleniumTestsContextManager(com.seleniumtests.core.SeleniumTestsContextManager) Logger(org.apache.log4j.Logger) BugTracker(com.seleniumtests.connectors.bugtracker.BugTracker) WaitHelper(com.seleniumtests.util.helper.WaitHelper) ImmutableList(com.google.common.collect.ImmutableList) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Map(java.util.Map) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) Project(com.atlassian.jira.rest.client.api.domain.Project) URI(java.net.URI) ScenarioException(com.seleniumtests.customexception.ScenarioException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) Transition(com.atlassian.jira.rest.client.api.domain.Transition) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) JiraRestClient(com.atlassian.jira.rest.client.api.JiraRestClient) CustomFieldOption(com.atlassian.jira.rest.client.api.domain.CustomFieldOption) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder) TransitionInput(com.atlassian.jira.rest.client.api.domain.input.TransitionInput) Field(com.atlassian.jira.rest.client.api.domain.Field) Collectors(java.util.stream.Collectors) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File) SearchRestClient(com.atlassian.jira.rest.client.api.SearchRestClient) List(java.util.List) User(com.atlassian.jira.rest.client.api.domain.User) Version(com.atlassian.jira.rest.client.api.domain.Version) BasicProject(com.atlassian.jira.rest.client.api.domain.BasicProject) TestStep(com.seleniumtests.reporter.logger.TestStep) Entry(java.util.Map.Entry) Comment(com.atlassian.jira.rest.client.api.domain.Comment) BasicComponent(com.atlassian.jira.rest.client.api.domain.BasicComponent) AsynchronousJiraRestClientFactory(com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory) IssueBean(com.seleniumtests.connectors.bugtracker.IssueBean) BasicPriority(com.atlassian.jira.rest.client.api.domain.BasicPriority) Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) File(java.io.File) ScenarioException(com.seleniumtests.customexception.ScenarioException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) ScenarioException(com.seleniumtests.customexception.ScenarioException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException)

Example 33 with ScreenShot

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()));
            }
        }
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File)

Example 34 with ScreenShot

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);
}
Also used : ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot)

Example 35 with ScreenShot

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);
}
Also used : ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot)

Aggregations

ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)63 Test (org.testng.annotations.Test)45 File (java.io.File)37 GenericTest (com.seleniumtests.GenericTest)35 Snapshot (com.seleniumtests.reporter.logger.Snapshot)24 TestStep (com.seleniumtests.reporter.logger.TestStep)24 ArrayList (java.util.ArrayList)14 ScreenshotUtil (com.seleniumtests.driver.screenshots.ScreenshotUtil)10 GenericFile (com.seleniumtests.reporter.logger.GenericFile)8 GenericMultiBrowserTest (com.seleniumtests.it.driver.support.GenericMultiBrowserTest)6 BeforeMethod (org.testng.annotations.BeforeMethod)6 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)5 TestAction (com.seleniumtests.reporter.logger.TestAction)5 BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)3 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)2 User (com.atlassian.jira.rest.client.api.domain.User)2 IssueInput (com.atlassian.jira.rest.client.api.domain.input.IssueInput)2 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)2 ScenarioException (com.seleniumtests.customexception.ScenarioException)2 SnapshotTarget (com.seleniumtests.driver.screenshots.SnapshotTarget)2