use of com.seleniumtests.reporter.logger.Snapshot 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();
}
use of com.seleniumtests.reporter.logger.Snapshot 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");
}
use of com.seleniumtests.reporter.logger.Snapshot 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.reporter.logger.Snapshot in project seleniumRobot by bhecquet.
the class TestSeleniumRobotServerTestRecorder method testReportGeneration.
/**
* In this test, everything is fine with seleniumrobot server
* @throws Exception
*/
// TODO: check that record is not done when compareSnapshot & resultRecord are false
// TODO: check that record is not done when seleniumRobotServer is not active (by params)
@Test(groups = { "it" })
public void testReportGeneration() throws Exception {
try {
System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE, "true");
System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT, "true");
System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_RECORD_RESULTS, "true");
System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL, "http://localhost:1234");
initMocks();
executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClass" }, ParallelMode.METHODS, new String[] { "testAndSubActions", "testInError", "testWithException", "testSkipped" });
// check server has been called for all aspects of test (app, version, ...)
// they may be called for each test but server is responsible for uniqueness of the value
verify(serverConnector, atLeastOnce()).createSession(anyString());
// issue #331: check all test cases are created, call MUST be done only once to avoid result to be recorded several times
verify(serverConnector).createTestCase("testAndSubActions");
verify(serverConnector).createTestCase("testInError");
verify(serverConnector).createTestCase("testWithException");
verify(serverConnector).createTestCase("testSkipped");
verify(serverConnector, times(4)).addLogsToTestCaseInSession(anyInt(), anyString());
verify(serverConnector).createTestCaseInSession(anyInt(), anyInt(), eq("testAndSubActions"));
verify(serverConnector).createTestCaseInSession(anyInt(), anyInt(), eq("testInError"));
verify(serverConnector).createTestCaseInSession(anyInt(), anyInt(), eq("testWithException"));
verify(serverConnector).createTestCaseInSession(anyInt(), anyInt(), eq("testSkipped"));
verify(serverConnector, times(3)).createTestStep(eq("step 1"), anyInt());
verify(serverConnector).createTestStep(eq("step 2"), anyInt());
// two snapshots but only once is sent because the other has no name
verify(serverConnector).createSnapshot(any(Snapshot.class), anyInt(), anyInt(), anyInt());
verify(serverConnector, never()).createExcludeZones(any(Rectangle.class), anyInt());
String logs = readSeleniumRobotLogFile();
// one snapshot has no name, error message is displayed
Assert.assertTrue(logs.contains("Snapshot hasn't any name, it won't be sent to server"));
// check that screenshot information are removed from logs (the pattern "Output: ...")
verify(serverConnector).recordStepResult(eq(true), contains("step 1.3: open page"), eq(1230L), anyInt(), anyInt(), anyInt());
} finally {
System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT);
System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_RECORD_RESULTS);
}
}
use of com.seleniumtests.reporter.logger.Snapshot in project seleniumRobot by bhecquet.
the class TestNGResultUtils method changeTestResultWithSnapshotComparison.
/**
* Change the test result when snapshot comparison fails
* @param testResult
*/
public static void changeTestResultWithSnapshotComparison(final ITestResult testResult) {
if (// test is already failed
testResult.getStatus() == ITestResult.FAILURE || !Boolean.TRUE.equals(SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerActive()) || // as the comparison result is only displayed, do not retry
SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerCompareSnapshotBehaviour() == SnapshotComparisonBehaviour.DISPLAY_ONLY || // complicated to set the test failed, and then success again
SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerCompareSnapshotBehaviour() == SnapshotComparisonBehaviour.ADD_TEST_RESULT || !SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerCompareSnapshot()) {
return;
}
SeleniumRobotSnapshotServerConnector serverConnector = SeleniumRobotSnapshotServerConnector.getInstance();
List<TestStep> testSteps = getSeleniumRobotTestContext(testResult).getTestStepManager().getTestSteps();
if (testSteps == null) {
return;
}
for (TestStep testStep : testSteps) {
for (Snapshot snapshot : new ArrayList<>(testStep.getSnapshots())) {
if (snapshot.getCheckSnapshot().recordSnapshotOnServerForComparison()) {
if (snapshot.getName() == null || snapshot.getName().isEmpty()) {
logger.warn("Snapshot hasn't any name, it won't be sent to server");
continue;
}
try {
SnapshotComparisonResult comparisonResult = serverConnector.checkSnapshotHasNoDifferences(snapshot, CommonReporter.getTestCaseName(testResult), testStep.getName());
if (comparisonResult == SnapshotComparisonResult.KO) {
testResult.setStatus(ITestResult.FAILURE);
testResult.setThrowable(new ScenarioException("Snapshot comparison failed"));
// move test from passedTests to failedTests if test is not already in failed tests
if (testResult.getTestContext().getPassedTests().getAllMethods().contains(testResult.getMethod())) {
testResult.getTestContext().getPassedTests().removeResult(testResult);
testResult.getTestContext().getFailedTests().addResult(testResult, testResult.getMethod());
}
return;
}
} catch (SeleniumRobotServerException e) {
logger.error("Could not create snapshot on server", e);
}
}
}
}
}
Aggregations