use of com.seleniumtests.reporter.logger.Snapshot in project seleniumRobot by bhecquet.
the class ScenarioLogger method logScreenshot.
/**
* Log screenshot. Should not be directly used inside tests
*
* @param screenshot screenshot to log
* @param screenshotName name of the snapshot, user wants to display
* @param driverName the name of the driver that did the screenshot
* @param checkSnapshot If true, check if we should compare snapshot on selenium server
*/
public void logScreenshot(ScreenShot screenshot, String screenshotName, String driverName, SnapshotCheckType checkSnapshot) {
try {
TestStep runningStep = TestStepManager.getParentTestStep();
if (runningStep == null) {
runningStep = TestStepManager.getCurrentOrPreviousStep();
}
if (runningStep != null) {
try {
String displayedScreenshotName = screenshotName == null ? "" : "-" + screenshotName;
runningStep.addSnapshot(new Snapshot(screenshot, String.format("drv:%s%s", driverName, displayedScreenshotName), checkSnapshot), SeleniumTestsContextManager.getContextForCurrentTestState().get(0).getTestStepManager().getTestSteps().size(), screenshotName);
} catch (NullPointerException e) {
super.error("screenshot is null");
}
}
} catch (IndexOutOfBoundsException e) {
// do nothing, no context has been created which is the case if we try to log message in @BeforeSuite / @BeforeGroup
}
}
use of com.seleniumtests.reporter.logger.Snapshot in project seleniumRobot by bhecquet.
the class TestJiraConnector method init.
@BeforeMethod(groups = { "no-ti" })
public void init() throws IOException {
File tmpImg = File.createTempFile("img", ".png");
File tmpHtml = File.createTempFile("html", ".html");
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);
step2 = new TestStep("step 2", null, new ArrayList<>(), false);
step2.setFailed(true);
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);
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);
}
use of com.seleniumtests.reporter.logger.Snapshot in project seleniumRobot by bhecquet.
the class TestSeleniumRobotSnapshotServerConnector method testCreateSnapshot.
/**
* create a snapshot
* @throws IOException
*/
@Test(groups = { "it" })
public void testCreateSnapshot() throws IOException {
Integer sessionId = connector.createSession("Session1");
Integer testCaseId = connector.createTestCase("Test 2");
Integer testCaseInSessionId = connector.createTestCaseInSession(sessionId, testCaseId, "Test 2");
Integer testStepId = connector.createTestStep("Step 1", testCaseInSessionId);
Integer stepResultId = connector.recordStepResult(true, "logs", 1, sessionId, testCaseInSessionId, testStepId);
File image = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), "img.png").toFile();
image.deleteOnExit();
FileUtils.copyInputStreamToFile(getClass().getClassLoader().getResourceAsStream("tu/images/ffLogoConcat.png"), image);
ScreenShot screenshot = new ScreenShot();
screenshot.setImagePath(image.getName());
Snapshot snapshot = new Snapshot(screenshot, "img", SnapshotCheckType.TRUE);
Integer snapshotId = connector.createSnapshot(snapshot, sessionId, testCaseInSessionId, stepResultId);
Assert.assertNotNull(snapshotId);
}
use of com.seleniumtests.reporter.logger.Snapshot in project seleniumRobot by bhecquet.
the class TestScreenshotUtil method testScreenshotDurationIsLogged.
/**
* check that duration of screenshots is logged into TestStep
* @param testContext
* @throws Exception
*/
@Test(groups = { "it" })
public void testScreenshotDurationIsLogged(ITestContext testContext) throws Exception {
executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClassForDriverTest" }, ParallelMode.METHODS, new String[] { "testDriverShort" });
for (ISuite suite : SeleniumRobotTestListener.getSuiteList()) {
for (ISuiteResult suiteResult : suite.getResults().values()) {
for (ITestResult testResult : suiteResult.getTestContext().getPassedTests().getAllResults()) {
List<TestStep> steps = TestNGResultUtils.getSeleniumRobotTestContext(testResult).getTestStepManager().getTestSteps();
for (TestStep step : steps) {
List<Snapshot> snapshots = step.getSnapshots();
if (!snapshots.isEmpty()) {
Assert.assertTrue(step.getDurationToExclude() > 0);
Assert.assertEquals(snapshots.get(0).getScreenshot().getDuration(), step.getDurationToExclude());
}
}
}
}
}
}
use of com.seleniumtests.reporter.logger.Snapshot in project seleniumRobot by bhecquet.
the class StubTestClass method testAndSubActions.
@Test(groups = "stub", description = "a test with steps")
public void testAndSubActions() throws IOException {
TestStep step1 = new TestStep("step 1", Reporter.getCurrentTestResult(), new ArrayList<>(), maskPassword);
step1.addAction(new TestAction("click button", false, new ArrayList<>()));
step1.addAction(new TestAction("sendKeys to text field", true, new ArrayList<>()));
File tmpImg = File.createTempFile("img", "_with_very_very_very_long_name_to_be_shortened.png");
File tmpHtml = File.createTempFile("html", "_with_very_very_very_long_name_to_be_shortened.html");
ScreenShot 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.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
ScreenShot screenshot2 = new ScreenShot();
screenshot2.setImagePath("screenshot/" + tmpImg.getName());
screenshot2.setHtmlSourcePath("htmls/" + tmpHtml.getName());
FileUtils.moveFile(tmpImg, new File(screenshot2.getFullImagePath()));
FileUtils.moveFile(tmpHtml, new File(screenshot2.getFullHtmlPath()));
step1.addSnapshot(new Snapshot(screenshot2, null, SnapshotCheckType.FULL), 1, null);
step1.setActionException(new WebDriverException("driver exception"));
TestStep subStep1 = new TestStep("step 1.3: open page", Reporter.getCurrentTestResult(), new ArrayList<>(), maskPassword);
subStep1.addAction(new TestAction("click link", false, new ArrayList<>()));
subStep1.addMessage(new TestMessage("a message", MessageType.LOG));
subStep1.addAction(new TestAction("sendKeys to password field", false, new ArrayList<>()));
step1.addAction(subStep1);
WaitHelper.waitForSeconds(3);
step1.setDuration(1230L);
TestStep step2 = new TestStep("step 2", Reporter.getCurrentTestResult(), new ArrayList<>(), maskPassword);
step2.setDuration(14030L);
TestStepManager.logTestStep(step1);
TestStepManager.logTestStep(step2);
tmpImg.deleteOnExit();
tmpHtml.deleteOnExit();
}
Aggregations