Search in sources :

Example 16 with Snapshot

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
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Snapshot(com.seleniumtests.reporter.logger.Snapshot)

Example 17 with Snapshot

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);
}
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 18 with Snapshot

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);
}
Also used : Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 19 with Snapshot

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());
                    }
                }
            }
        }
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ITestResult(org.testng.ITestResult) ISuite(org.testng.ISuite) ISuiteResult(org.testng.ISuiteResult) Test(org.testng.annotations.Test) ReporterTest(com.seleniumtests.it.reporter.ReporterTest)

Example 20 with Snapshot

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();
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ArrayList(java.util.ArrayList) TestMessage(com.seleniumtests.reporter.logger.TestMessage) File(java.io.File) TestAction(com.seleniumtests.reporter.logger.TestAction) WebDriverException(org.openqa.selenium.WebDriverException) Test(org.testng.annotations.Test)

Aggregations

Snapshot (com.seleniumtests.reporter.logger.Snapshot)29 ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)23 TestStep (com.seleniumtests.reporter.logger.TestStep)22 File (java.io.File)18 Test (org.testng.annotations.Test)18 GenericTest (com.seleniumtests.GenericTest)15 ArrayList (java.util.ArrayList)11 GenericFile (com.seleniumtests.reporter.logger.GenericFile)8 TestAction (com.seleniumtests.reporter.logger.TestAction)5 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 Matcher (java.util.regex.Matcher)3 Field (com.seleniumtests.connectors.selenium.fielddetector.Field)2 Label (com.seleniumtests.connectors.selenium.fielddetector.Label)2 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Rectangle (org.openqa.selenium.Rectangle)2