Search in sources :

Example 26 with ScreenShot

use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.

the class TestTestStep method testTestSubSnapshotPositionAndParent.

@Test(groups = { "ut" })
public void testTestSubSnapshotPositionAndParent() throws IOException {
    TestStep step = new TestStep("step1", null, new ArrayList<>(), true);
    TestStep subStep = new TestStep("subStep1", null, new ArrayList<>(), true);
    step.addStep(subStep);
    ScreenShot screenshot = new ScreenShot();
    File tmpImgFile = File.createTempFile("img", ".png");
    File tmpHtmlFile = File.createTempFile("html", ".html");
    screenshot.setOutputDirectory(tmpImgFile.getParent());
    screenshot.setLocation("http://mysite.com");
    screenshot.setTitle("mysite");
    screenshot.setImagePath(tmpImgFile.getName());
    screenshot.setHtmlSourcePath(tmpHtmlFile.getName());
    Snapshot snapshot = new Snapshot(screenshot, "main", SnapshotCheckType.TRUE);
    step.addSnapshot(snapshot, 0, null);
    Assert.assertEquals(snapshot.getPosition(), 0);
    Assert.assertEquals(snapshot.getParent(), step);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File) GenericFile(com.seleniumtests.reporter.logger.GenericFile) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 27 with ScreenShot

use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.

the class JiraConnector method formatUpdateDescription.

/**
 * Create description for issue update
 * @param messageUpdate
 * @param screenShots
 * @param lastFailedStep
 * @return
 */
private StringBuilder formatUpdateDescription(String messageUpdate, List<ScreenShot> screenShots, TestStep lastFailedStep) {
    StringBuilder fullDescription = new StringBuilder(messageUpdate + "\n");
    if (SeleniumTestsContextManager.getThreadContext().getStartedBy() != null) {
        fullDescription.append(String.format("*Started by:* %s\n", SeleniumTestsContextManager.getThreadContext().getStartedBy()));
    }
    if (lastFailedStep != null) {
        fullDescription.append(String.format("*" + STEP_KO_PATTERN + "%s*\n", lastFailedStep.getPosition(), lastFailedStep.getName().trim()));
        fullDescription.append(String.format("{code:java}%s{code}\n\n", lastFailedStep.toString()));
    }
    // add snapshots to comment
    for (ScreenShot screenshot : screenShots) {
        fullDescription.append(String.format("!%s|thumbnail!\n", new File(screenshot.getFullImagePath()).getName()));
    }
    return fullDescription;
}
Also used : ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File)

Example 28 with ScreenShot

use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.

the class BugTracker method createIssueBean.

/**
 * Create an issue object
 * @param testName			method name (name of scenario)
 * @param description		Description of the test. May be null
 * @param testSteps			Test steps of the scenario
 * @param issueOptions		options for the new issue
 * @return
 */
public IssueBean createIssueBean(String summary, String testName, String description, List<TestStep> testSteps, Map<String, String> issueOptions) {
    TestStep lastTestStep = null;
    List<TestStep> failedSteps = new ArrayList<>();
    for (TestStep testStep : testSteps) {
        // "Test end" step should never be considered as failed, because it reflects the overall test result
        if (Boolean.TRUE.equals(testStep.getFailed()) && !testStep.isTestEndStep() && // if the step has the flag disabling bugtracker, do not count it as failed step
        !testStep.isDisableBugtracker()) {
            failedSteps.add(testStep);
        }
        if (testStep.isTestEndStep()) {
            lastTestStep = testStep;
            break;
        }
    }
    // don't create issue if no failed step is present
    if (failedSteps.isEmpty()) {
        logger.info("No failed steps. It may be due to a failed step marked as disabled for bugtracker");
        return null;
    }
    // don't create issue if test has not been executed or not completed
    if (lastTestStep == null) {
        return null;
    }
    List<ScreenShot> screenShots = lastTestStep.getSnapshots().stream().map(Snapshot::getScreenshot).collect(Collectors.toList());
    StringBuilder fullDescription = new StringBuilder();
    formatDescription(testName, failedSteps, lastTestStep, description, fullDescription);
    File zipFile = null;
    // provide detailedResult.zip file only when 'startedBy' is not present. This prevent from sending big reports to bugtracker
    if (SeleniumTestsContextManager.getThreadContext().getStartedBy() == null) {
        fullDescription.append("\n\nFor more details, see attached .zip file");
        zipFile = createDetailedResultReport(testName);
    }
    String assignee = issueOptions.get("assignee");
    String reporter = issueOptions.get("reporter");
    return createIssueBean(summary, fullDescription.toString(), testName, // take the last failed step as step we will show as failed even if there are several
    failedSteps.isEmpty() ? lastTestStep : failedSteps.get(failedSteps.size() - 1), assignee, reporter, screenShots, zipFile, issueOptions);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ArrayList(java.util.ArrayList) File(java.io.File)

Example 29 with ScreenShot

use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.

the class TestBugTracker method init.

@BeforeMethod(groups = { "ut" })
public void init() throws IOException {
    File tmpImg = File.createTempFile("img", ".png");
    tmpImg.deleteOnExit();
    File tmpHtml = File.createTempFile("html", ".html");
    tmpHtml.deleteOnExit();
    screenshot = new ScreenShot();
    screenshot.setImagePath("screenshot/" + tmpImg.getName());
    screenshot.setHtmlSourcePath("htmls/" + tmpHtml.getName());
    FileUtils.copyFile(tmpImg, new File(screenshot.getFullImagePath()));
    FileUtils.copyFile(tmpHtml, new File(screenshot.getFullHtmlPath()));
    step1 = new TestStep("step 1", null, new ArrayList<>(), false);
    step1.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
    step1.setPosition(0);
    step2 = new TestStep("step 2", null, new ArrayList<>(), false);
    step2.setFailed(true);
    step2.setActionException(new NullPointerException("Error clicking"));
    step2.addAction(new TestAction("action1", false, new ArrayList<>()));
    step2.addAction(new TestAction("action2", false, new ArrayList<>()));
    step2.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
    step2.setPosition(1);
    stepFailedWithDisabledBugtracker = new TestStep("step 2", null, new ArrayList<>(), false, RootCause.NONE, "", true);
    stepFailedWithDisabledBugtracker.setFailed(true);
    stepFailedWithDisabledBugtracker.setActionException(new NullPointerException("Error clicking"));
    stepFailedWithDisabledBugtracker.addAction(new TestAction("action1", false, new ArrayList<>()));
    stepFailedWithDisabledBugtracker.addAction(new TestAction("action2", false, new ArrayList<>()));
    stepFailedWithDisabledBugtracker.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
    stepFailedWithDisabledBugtracker.setPosition(1);
    stepEnd = new TestStep("Test end", null, new ArrayList<>(), false);
    stepEnd.addSnapshot(new Snapshot(screenshot, "end", SnapshotCheckType.FULL), 1, null);
    stepEnd.addSnapshot(new Snapshot(screenshot, "end2", SnapshotCheckType.FULL), 1, null);
    stepEnd.setPosition(2);
    issueOptions.put("reporter", "you");
    issueOptions.put("assignee", "me");
    BugTracker.resetBugTrackerInstances();
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ArrayList(java.util.ArrayList) File(java.io.File) TestAction(com.seleniumtests.reporter.logger.TestAction) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 30 with ScreenShot

use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.

the class TestJiraConnector method initJira.

@BeforeMethod(groups = { "ut" })
public void initJira() throws Exception {
    Map<String, URI> avatars = new HashMap<>();
    avatars.put("48x48", new URI("http://foo/bar/a"));
    user = new User(new URI("http://foo/bar/u"), "user1", "user 1", "1", "user1@company.com", true, null, avatars, "UTC");
    // create test steps
    File tmpImg = File.createTempFile("img", "123456.png");
    tmpImg.deleteOnExit();
    File tmpHtml = File.createTempFile("html", "123456.html");
    tmpHtml.deleteOnExit();
    screenshot = new ScreenShot();
    screenshot.setImagePath("screenshot/" + tmpImg.getName());
    screenshot.setHtmlSourcePath("htmls/" + tmpHtml.getName());
    FileUtils.copyFile(tmpImg, new File(screenshot.getFullImagePath()));
    FileUtils.copyFile(tmpHtml, new File(screenshot.getFullHtmlPath()));
    step1 = new TestStep("step 1", null, new ArrayList<>(), false);
    step1.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
    step1.setPosition(0);
    step2 = new TestStep("step 2", null, new ArrayList<>(), false);
    step2.setFailed(true);
    step2.setActionException(new NullPointerException("Error clicking"));
    step2.addAction(new TestAction("action1", false, new ArrayList<>()));
    step2.addAction(new TestAction("action2", false, new ArrayList<>()));
    step2.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
    step2.setPosition(1);
    stepWithErrorCauseAndDetails = new TestStep("step 3", null, new ArrayList<>(), false, RootCause.REGRESSION, "Check  your script", false);
    stepWithErrorCauseAndDetails.setFailed(true);
    stepWithErrorCauseAndDetails.setActionException(new NullPointerException("Error clicking"));
    stepWithErrorCauseAndDetails.addAction(new TestAction("action1", false, new ArrayList<>()));
    stepWithErrorCauseAndDetails.addAction(new TestAction("action2", false, new ArrayList<>()));
    stepWithErrorCauseAndDetails.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
    stepWithErrorCauseAndDetails.setPosition(1);
    stepWithErrorCause = new TestStep("step 4", null, new ArrayList<>(), false, RootCause.REGRESSION, "", false);
    stepWithErrorCause.setFailed(true);
    stepWithErrorCause.setActionException(new NullPointerException("Error clicking"));
    stepWithErrorCause.addAction(new TestAction("action1", false, new ArrayList<>()));
    stepWithErrorCause.addAction(new TestAction("action2", false, new ArrayList<>()));
    stepWithErrorCause.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
    stepWithErrorCause.setPosition(1);
    stepEnd = new TestStep("Test end", null, new ArrayList<>(), false);
    stepEnd.addSnapshot(new Snapshot(screenshot, "end", SnapshotCheckType.FULL), 1, null);
    stepEnd.addSnapshot(new Snapshot(screenshot, "end2", SnapshotCheckType.FULL), 1, null);
    stepEnd.setPosition(2);
    // mock all clients
    PowerMockito.whenNew(AsynchronousJiraRestClientFactory.class).withNoArguments().thenReturn(restClientFactory);
    when(restClientFactory.createWithBasicHttpAuthentication(any(URI.class), eq("user"), eq("password"))).thenReturn(restClient);
    when(restClient.getProjectClient()).thenReturn(projectRestClient);
    when(projectRestClient.getProject(anyString())).thenReturn(promiseProject);
    when(promiseProject.claim()).thenReturn(project);
    when(project.getComponents()).thenReturn(Arrays.asList(component1, component2));
    when(project.getIssueTypes()).thenReturn(new OptionalIterable(Arrays.asList(issueType1, issueType2)));
    when(project.getVersions()).thenReturn(Arrays.asList(version1, version2));
    when(project.getKey()).thenReturn(PROJECT_KEY);
    when(projectRestClient.getAllProjects()).thenReturn(promiseAllProjects);
    when(promiseAllProjects.claim()).thenReturn(Arrays.asList(project1, project2));
    when(restClient.getMetadataClient()).thenReturn(metadataRestClient);
    when(metadataRestClient.getPriorities()).thenReturn(promisePriorities);
    when(promisePriorities.claim()).thenReturn(Arrays.asList(priority1, priority2));
    when(metadataRestClient.getFields()).thenReturn(promiseFields);
    when(promiseFields.claim()).thenReturn(Arrays.asList(fieldApplication, fieldEnvironment, fieldStep));
    when(restClient.getSearchClient()).thenReturn(searchRestClient);
    when(searchRestClient.searchJql(anyString())).thenReturn(promiseSearch);
    when(restClient.getUserClient()).thenReturn(userRestClient);
    doThrow(RestClientException.class).when(userRestClient).findUsers(anyString());
    doReturn(promiseUsers).when(userRestClient).findUsers("me");
    when(promiseUsers.claim()).thenReturn(Arrays.asList(user));
    when(restClient.getIssueClient()).thenReturn(issueRestClient);
    when(issueRestClient.createIssue(any(IssueInput.class))).thenReturn(promiseBasicIssue);
    when(promiseBasicIssue.claim()).thenReturn(new BasicIssue(new URI("http://foo/bar/i"), "ISSUE-1", 1L));
    when(issueRestClient.getIssue(anyString())).thenReturn(promiseIssueEmpty);
    when(issueRestClient.getIssue("ISSUE-1")).thenReturn(promiseIssue);
    when(promiseIssue.claim()).thenReturn(issue1);
    when(promiseIssueEmpty.claim()).thenThrow(RestClientException.class);
    when(issueRestClient.getCreateIssueMetaFields(anyString(), anyString(), any(), any())).thenReturn(promiseFieldInfo);
    when(promiseFieldInfo.claim()).thenReturn(fieldInfos);
    when(fieldInfos.getValues()).thenReturn(Arrays.asList(fieldInfo1, fieldInfo2, fieldInfo3));
    when(issueRestClient.getTransitions(issue1)).thenReturn(promiseTransitions);
    when(promiseTransitions.claim()).thenReturn(Arrays.asList(transition1, transition2));
    when(issueRestClient.addAttachments(any(), any(File.class))).thenReturn(promiseVoid);
    when(issue1.getKey()).thenReturn("ISSUE-1");
    when(issue1.getDescription()).thenReturn("jira issue 1");
    when(issue1.getAttachmentsUri()).thenReturn(new URI("http://foo/bar/i/1/attachments"));
    when(issue1.getCommentsUri()).thenReturn(new URI("http://foo/bar/i/1/comments"));
    when(issue2.getKey()).thenReturn("ISSUE-2");
    when(issue2.getDescription()).thenReturn("jira issue 2");
    when(issue2.getAttachmentsUri()).thenReturn(new URI("http://foo/bar/i/2/attachments"));
    when(issue2.getCommentsUri()).thenReturn(new URI("http://foo/bar/i/2/comments"));
    detailedResult = File.createTempFile("detailed", ".zip");
    detailedResult.deleteOnExit();
    jiraOptions.put("jira.openStates", "Open,To Do");
    jiraOptions.put("jira.closeTransition", "close");
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) OptionalIterable(com.atlassian.jira.rest.client.api.OptionalIterable) User(com.atlassian.jira.rest.client.api.domain.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) URI(java.net.URI) TestAction(com.seleniumtests.reporter.logger.TestAction) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) File(java.io.File) BeforeMethod(org.testng.annotations.BeforeMethod)

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