Search in sources :

Example 41 with SeleniumRobotSnapshotServerConnector

use of com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector in project seleniumRobot by bhecquet.

the class TestSeleniumTestsReporter2 method testSnapshotComparisonSkipChangeTestResult.

/**
 * Check that when snapshot server is used, we see a tab pointing to snapshot comparison results
 * Moreover, a red bullet should be visible on summary result when comparison is KO
 * Result remains OK as behaviour is "displayOnly"
 * @throws Exception
 */
@Test(groups = { "it" })
public void testSnapshotComparisonSkipChangeTestResult() throws Exception {
    try {
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_BEHAVIOUR, "changeTestResult");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_RECORD_RESULTS, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL, "http://localhost:4321");
        SeleniumRobotSnapshotServerConnector server = configureMockedSnapshotServerConnection();
        createServerMock("GET", SeleniumRobotSnapshotServerConnector.TESTCASEINSESSION_API_URL + "15", 200, "{'testSteps': [], 'computed': true, 'isOkWithSnapshots': null, 'computingError': ['error computing']}");
        SeleniumTestsContextManager.removeThreadContext();
        executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClass" }, ParallelMode.METHODS, new String[] { "testAndSubActions" });
        // check result is OK (even with option 'changeTestResult' because comparison is skipped) and comparison result is shown through blue bullet (comparison Skipped)
        String summaryReport = readSummaryFile();
        Assert.assertTrue(summaryReport.contains("<i class=\"fas fa-circle circleSkipped\" data-toggle=\"tooltip\" title=\"snapshot comparison skipped\">"));
        Assert.assertTrue(summaryReport.contains("info=\"ok\" data-toggle=\"tooltip\""));
        String detailedReportContent = readTestMethodResultFile("testAndSubActions");
        // tabs are shown
        Assert.assertTrue(detailedReportContent.contains("<div id=\"tabs\" style=\"display: block;\" >"));
        // tab is in blue as comparison skipped
        Assert.assertTrue(detailedReportContent.contains("<a class=\"nav-link  tab-skipped \" id=\"snapshot-tab\""));
        // failed step has been added for comparison
        Assert.assertTrue(detailedReportContent.contains("<div class=\"message-error\">Comparison skipped: &quot;error computing&quot;</div>"));
        Assert.assertTrue(detailedReportContent.matches(".*<div class=\"box collapsed-box failed\">.*?<i class=\"fas fa-plus\"></i></button><span class=\"step-title\"> Snapshot comparison.*"));
        // snapshot tab not active
        Assert.assertTrue(detailedReportContent.contains("<a class=\"nav-link  tab-skipped \" id=\"snapshot-tab\" data-toggle=\"tab\" href=\"#snapshots\" role=\"tab\" aria-controls=\"profile\" aria-selected=\"false\">Snapshots</a>"));
        // iframe present with the right test case id
        Assert.assertTrue(detailedReportContent.contains("<iframe src=\"http://localhost:4321/snapshot/compare/stepList/15/?header=true\" id=\"snapshot-iframe\" frameborder=\"0\"></iframe>"));
    } finally {
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_BEHAVIOUR);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_RECORD_RESULTS);
    }
}
Also used : SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector) Test(org.testng.annotations.Test)

Example 42 with SeleniumRobotSnapshotServerConnector

use of com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector in project seleniumRobot by bhecquet.

the class TestSeleniumTestsReporter2 method testSnapshotComparisonErrorDuringTransfer.

/**
 * issue #351: Check that when snapshot server is used, but a problem occurs posting information, snapshot tab is not displayed
 * @throws Exception
 */
@Test(groups = { "it" })
public void testSnapshotComparisonErrorDuringTransfer() throws Exception {
    try {
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_BEHAVIOUR, "displayOnly");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_RECORD_RESULTS, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL, "http://localhost:4321");
        SeleniumRobotSnapshotServerConnector server = configureMockedSnapshotServerConnection();
        createServerMock("POST", SeleniumRobotSnapshotServerConnector.SESSION_API_URL, 500, "Internal Server Error", "body");
        SeleniumTestsContextManager.removeThreadContext();
        executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClass" }, ParallelMode.METHODS, new String[] { "testAndSubActions" });
        // check result is ok and comparison result is shown through green bullet
        String summaryReport = readSummaryFile();
        // no snapshot comparison has been performed
        Assert.assertFalse(summaryReport.contains("<i class=\"fas fa-circle circle"));
        Assert.assertTrue(summaryReport.contains("info=\"ok\" data-toggle=\"tooltip\""));
        String detailedReportContent = readTestMethodResultFile("testAndSubActions");
        // no snapshot tab displayed
        Assert.assertTrue(detailedReportContent.contains("<div id=\"tabs\"  style=\"display: none;\" >"));
        // message saying that error occured when contacting snapshot server
        String logs = readSeleniumRobotLogFile();
        Assert.assertTrue(logs.contains("request to http://localhost:4321 failed: Internal Server Error"));
    } finally {
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_BEHAVIOUR);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_RECORD_RESULTS);
    }
}
Also used : SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector) Test(org.testng.annotations.Test)

Example 43 with SeleniumRobotSnapshotServerConnector

use of com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector in project seleniumRobot by bhecquet.

the class TestSeleniumTestsReporter2 method testReportDoesNotContainStepReferenceWhenRecordingDisabled.

/**
 * Check reference is not get if server recording is disabled
 * @throws Exception
 */
@Test(groups = { "it" })
public void testReportDoesNotContainStepReferenceWhenRecordingDisabled() throws Exception {
    try {
        System.setProperty(SeleniumTestsContext.VIDEO_CAPTURE, "true");
        System.setProperty(SeleniumTestsContext.TEST_RETRY_COUNT, "0");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_RECORD_RESULTS, "false");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL, "http://localhost:4321");
        SeleniumRobotSnapshotServerConnector server = configureMockedSnapshotServerConnection();
        // simulate the case where a reference exists
        createServerMock("GET", SeleniumRobotSnapshotServerConnector.STEP_REFERENCE_API_URL + "17/", 200, createImageFromResource("tu/ffLogo1.png"));
        executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClassForDriverTest" }, ParallelMode.METHODS, new String[] { "testDriverShortKo" });
        // read 'testDriver' report. This contains calls to HtmlElement actions
        String detailedReportContent1 = readTestMethodResultFile("testDriverShortKo");
        // reference and current state should be displayed
        Assert.assertFalse(detailedReportContent1.matches(".* class\\=\"step-title\"> _writeSomethingOnNonExistentElement  - .*" + "at com\\.seleniumtests\\.it\\.driver\\.support\\.pages\\.DriverTestPage\\._writeSomethingOnNonExistentElement\\(DriverTestPage\\.java.*?" + "<div class\\=\"row\">" + "<div class\\=\"message-snapshot col\"><div class\\=\"text-center\">" + "<a href\\=\"#\" onclick\\=\"\\$\\('#imagepreview'\\).*" + "<img id.*" + // the current state
        "<div class\\=\"text-center\">Step beginning state</div>" + "<div class\\=\"text-center font-weight-lighter\"></div>.*" + "<div class\\=\"message-snapshot col\"><div class\\=\"text-center\">.*" + "<img id.*" + // the reference
        "<div class\\=\"text-center\">Valid-reference</div>.*"));
        // only one extraction of step state is presented (the one for failed step)
        Assert.assertEquals(StringUtils.countMatches(detailedReportContent1, "Step beginning state</div>"), 0);
    } finally {
        System.clearProperty(SeleniumTestsContext.VIDEO_CAPTURE);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_RECORD_RESULTS);
        System.clearProperty(SeleniumTestsContext.TEST_RETRY_COUNT);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_RECORD_RESULTS);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
    }
}
Also used : SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector) Test(org.testng.annotations.Test)

Example 44 with SeleniumRobotSnapshotServerConnector

use of com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector in project seleniumRobot by bhecquet.

the class TestSeleniumTestsReporter2 method testSnapshotComparisonOkDisplayOnly.

/**
 * Check that when snapshot server is used, we see a tab pointing to snapshot comparison results
 * Moreover, a green bullet should be visible on summary result when comparison is OK
 * @throws Exception
 */
@Test(groups = { "it" })
public void testSnapshotComparisonOkDisplayOnly() throws Exception {
    try {
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_BEHAVIOUR, "displayOnly");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_RECORD_RESULTS, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL, "http://localhost:4321");
        SeleniumRobotSnapshotServerConnector server = configureMockedSnapshotServerConnection();
        SeleniumTestsContextManager.removeThreadContext();
        executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClass" }, ParallelMode.METHODS, new String[] { "testAndSubActions" });
        // check result is ok and comparison result is shown through green bullet
        String summaryReport = readSummaryFile();
        Assert.assertTrue(summaryReport.contains("<i class=\"fas fa-circle circleSuccess\" data-toggle=\"tooltip\" title=\"snapshot comparison successfull\">"));
        Assert.assertTrue(summaryReport.contains("info=\"ok\" data-toggle=\"tooltip\""));
        String detailedReportContent = readTestMethodResultFile("testAndSubActions");
        // tabs are shown
        Assert.assertTrue(detailedReportContent.contains("<div id=\"tabs\" style=\"display: block;\" >"));
        // successful step has been added for comparison
        Assert.assertTrue(detailedReportContent.contains("<div class=\"message-info\">Comparison successful</div>"));
        Assert.assertTrue(detailedReportContent.matches(".*<div class=\"box collapsed-box success\">.*?<i class=\"fas fa-plus\"></i></button><span class=\"step-title\"> Snapshot comparison.*"));
        // snapshot tab not active
        Assert.assertTrue(detailedReportContent.contains("<a class=\"nav-link  tab-success \" id=\"snapshot-tab\" data-toggle=\"tab\" href=\"#snapshots\" role=\"tab\" aria-controls=\"profile\" aria-selected=\"false\">Snapshots</a>"));
        // iframe present with the right test case id
        Assert.assertTrue(detailedReportContent.contains("<iframe src=\"http://localhost:4321/snapshot/compare/stepList/15/?header=true\" id=\"snapshot-iframe\" frameborder=\"0\"></iframe>"));
    } finally {
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_BEHAVIOUR);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_RECORD_RESULTS);
    }
}
Also used : SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector) Test(org.testng.annotations.Test)

Example 45 with SeleniumRobotSnapshotServerConnector

use of com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector in project seleniumRobot by bhecquet.

the class TestSeleniumTestsReporter2 method testReportContainsStepReferenceForFailedStep.

/**
 * Check reference image for step is displayed when "recordResult" option is set and video capture is enabled
 * This reference is only shown when test fails
 *
 * @throws Exception
 */
@Test(groups = { "it" })
public void testReportContainsStepReferenceForFailedStep() throws Exception {
    try {
        System.setProperty(SeleniumTestsContext.VIDEO_CAPTURE, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_RECORD_RESULTS, "true");
        System.setProperty(SeleniumTestsContext.TEST_RETRY_COUNT, "0");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_RECORD_RESULTS, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL, "http://localhost:4321");
        SeleniumRobotSnapshotServerConnector server = configureMockedSnapshotServerConnection();
        // simulate the case where a reference exists
        createServerMock("GET", SeleniumRobotSnapshotServerConnector.STEP_REFERENCE_API_URL + "17/", 200, createImageFromResource("tu/ffLogo1.png"));
        executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClassForDriverTest" }, ParallelMode.METHODS, new String[] { "testDriverShortKo" });
        // read 'testDriver' report. This contains calls to HtmlElement actions
        String detailedReportContent1 = readTestMethodResultFile("testDriverShortKo");
        // reference and current state should be displayed
        Assert.assertTrue(detailedReportContent1.matches(".* class\\=\"step-title\"> _writeSomethingOnNonExistentElement  - .*" + "at com\\.seleniumtests\\.it\\.driver\\.support\\.pages\\.DriverTestPage\\._writeSomethingOnNonExistentElement\\(DriverTestPage\\.java.*?" + "<div class\\=\"row\">" + "<div class\\=\"message-snapshot col\"><div class\\=\"text-center\">" + "<a href\\=\"#\" onclick\\=\"\\$\\('#imagepreview'\\).*" + "<img id.*" + // the current state
        "<div class\\=\"text-center\">Step beginning state</div>" + "<div class\\=\"text-center font-weight-lighter\"></div>.*" + "<div class\\=\"message-snapshot col\"><div class\\=\"text-center\">.*" + "<img id.*" + // the reference
        "<div class\\=\"text-center\">Valid-reference</div>.*"));
        // only one extraction of step state is presented (the one for failed step)
        Assert.assertEquals(StringUtils.countMatches(detailedReportContent1, "Step beginning state</div>"), 1);
        // check step beginning state is present with valid path
        Assert.assertTrue(detailedReportContent1.contains("src=\"screenshots/testDriverShortKo_4-1__writeSomethingOnNonExistent-ideo-1.jpg\""));
        // check no picture extracted from video is kept
        Assert.assertEquals(Paths.get(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory(), "testDriverShortKo", "video").toFile().listFiles().length, 0);
    } finally {
        System.clearProperty(SeleniumTestsContext.VIDEO_CAPTURE);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_RECORD_RESULTS);
        System.clearProperty(SeleniumTestsContext.TEST_RETRY_COUNT);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_RECORD_RESULTS);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
    }
}
Also used : SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector) Test(org.testng.annotations.Test)

Aggregations

SeleniumRobotSnapshotServerConnector (com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector)113 Test (org.testng.annotations.Test)106 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)86 ConnectorsTest (com.seleniumtests.ConnectorsTest)84 HttpRequest (kong.unirest.HttpRequest)15 SnapshotComparisonResult (com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector.SnapshotComparisonResult)6 File (java.io.File)6 Rectangle (org.openqa.selenium.Rectangle)5 MultipartBody (kong.unirest.MultipartBody)4 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)3 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)2 ReporterTest (com.seleniumtests.it.reporter.ReporterTest)2 StubTestClassForDriverParallelTest (com.seleniumtests.it.stubclasses.StubTestClassForDriverParallelTest)2 Snapshot (com.seleniumtests.reporter.logger.Snapshot)2 TestStep (com.seleniumtests.reporter.logger.TestStep)2 ArrayList (java.util.ArrayList)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ITestContext (org.testng.ITestContext)2 ITestResult (org.testng.ITestResult)2 XmlTest (org.testng.xml.XmlTest)2