Search in sources :

Example 46 with SeleniumRobotSnapshotServerConnector

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

the class TestSeleniumTestsReporter2 method testReportDoesNotContainReferenceStep.

/**
 * In case test is OK, no reference image is displayed in report
 * @throws Exception
 */
@Test(groups = { "it" })
public void testReportDoesNotContainReferenceStep() 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[] { "testDriverShort" });
        // read 'testDriver' report. This contains calls to HtmlElement actions
        String detailedReportContent1 = readTestMethodResultFile("testDriverShort");
        // reference and current state should be displayed
        Assert.assertFalse(detailedReportContent1.matches(".*<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 47 with SeleniumRobotSnapshotServerConnector

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

the class TestSeleniumTestsReporter2 method testSnapshotComparisonSkipDisplayOnly.

@Test(groups = { "it" })
public void testSnapshotComparisonSkipDisplayOnly() 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("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 and comparison result is shown through red bullet (comparison KO)
        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 48 with SeleniumRobotSnapshotServerConnector

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

the class TestSeleniumTestsReporter2 method testSnapshotComparisonKoDisplayOnly.

/**
 * 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 testSnapshotComparisonKoDisplayOnly() 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("GET", SeleniumRobotSnapshotServerConnector.TESTCASEINSESSION_API_URL + "15", 200, "{'testSteps': [], 'computed': true, 'isOkWithSnapshots': false, 'computingError': []}");
        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 red bullet (comparison KO)
        String summaryReport = readSummaryFile();
        Assert.assertTrue(summaryReport.contains("<i class=\"fas fa-circle circleFailed\" data-toggle=\"tooltip\" title=\"snapshot comparison failed\">"));
        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;\" >"));
        // failed step has been added for comparison
        Assert.assertTrue(detailedReportContent.contains("<div class=\"message-error\">Comparison failed: </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-failed \" 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 49 with SeleniumRobotSnapshotServerConnector

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

the class TestJUnitReporter method testSnapshotComparisonKoAddTestResult.

/**
 * Check that when snapshot server is used with behavior "addTestResult" 2 results should be presented: one with the result of selenium test, a second one with the result of snapshot comparison.
 * Both are the same but second test is there for integration with junit parser so that we can differentiate navigation result from GUI result.
 * @throws Exception
 */
@Test(groups = { "it" })
public void testSnapshotComparisonKoAddTestResult() throws Exception {
    try {
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT_BEHAVIOUR, "addTestResult");
        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': false}");
        SeleniumTestsContextManager.removeThreadContext();
        List<String> testList = executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClass" }, ParallelMode.METHODS, new String[] { "testAndSubActions" });
        // check there are 2 results. first one is the selenium test (OK) and second one is the snapshot comparison (KO)
        String outDir = new File(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory()).getAbsolutePath();
        String result = FileUtils.readFileToString(Paths.get(outDir, "junitreports", String.format("TEST-%s.xml", testList.get(0))).toFile());
        Assert.assertTrue(result.contains("tests=\"2\""));
        Assert.assertTrue(result.contains("errors=\"1\""));
        Assert.assertTrue(result.contains("<error type=\"com.seleniumtests.customexception.ScenarioException\" message=\"Snapshot comparison failed\">"));
    } 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) File(java.io.File) Test(org.testng.annotations.Test)

Example 50 with SeleniumRobotSnapshotServerConnector

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

the class TestJUnitReporter method testSnapshotComparisonKoChangeTestResult.

/**
 * Check that when snapshot server is used with behavior "addTestResult" 2 results should be presented: one with the result of selenium test, a second one with the result of snapshot comparison.
 * Both are the same but second test is there for integration with junit parser so that we can differentiate navigation result from GUI result.
 * @throws Exception
 */
@Test(groups = { "it" })
public void testSnapshotComparisonKoChangeTestResult() 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': false}");
        SeleniumTestsContextManager.removeThreadContext();
        List<String> testList = executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClass" }, ParallelMode.METHODS, new String[] { "testAndSubActions" });
        // check there are 2 results. first one is the selenium test (OK) and second one is the snapshot comparison (KO)
        String outDir = new File(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory()).getAbsolutePath();
        String result = FileUtils.readFileToString(Paths.get(outDir, "junitreports", String.format("TEST-%s.xml", testList.get(0))).toFile());
        Assert.assertTrue(result.contains("tests=\"1\""));
        Assert.assertTrue(result.contains("errors=\"1\""));
        Assert.assertTrue(result.contains("<error type=\"com.seleniumtests.customexception.ScenarioException\" message=\"Snapshot comparison failed\">"));
    } 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) File(java.io.File) 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