Search in sources :

Example 1 with SeleniumRobotSnapshotServerConnector

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

the class SeleniumRobotServerTestRecorder method recordResults.

private void recordResults(SeleniumRobotSnapshotServerConnector serverConnector, Map<ITestContext, Set<ITestResult>> resultSet) {
    for (Entry<ITestContext, Set<ITestResult>> entry : resultSet.entrySet()) {
        List<ITestResult> methodResults = entry.getValue().stream().sorted((r1, r2) -> Long.compare(r1.getStartMillis(), r2.getStartMillis())).collect(Collectors.toList());
        // test case in seleniumRobot naming
        for (ITestResult testResult : methodResults) {
            // do not record this result twice if it's already recorded
            if (TestNGResultUtils.isSeleniumServerReportCreated(testResult) || // NoMoreRetry is set to false when test is being retried => we do not want to record a temp result, only the last one
            (TestNGResultUtils.getNoMoreRetry(testResult) != null && !TestNGResultUtils.getNoMoreRetry(testResult))) {
                continue;
            }
            // issue #81: recreate test context from this context (due to multithreading, this context may be null if parallel testing is used)
            SeleniumTestsContextManager.setThreadContextFromTestResult(entry.getKey(), testResult);
            // skipped tests has never been executed and so attribute (set in TestListener) has not been applied
            String testName = getTestCaseName(testResult);
            // get sessionId from context
            Integer sessionId = TestNGContextUtils.getTestSessionCreated(entry.getKey());
            // record test case
            Integer testCaseId = serverConnector.createTestCase(testName);
            Integer testCaseInSessionId = serverConnector.createTestCaseInSession(sessionId, testCaseId, getTestName(testResult));
            serverConnector.addLogsToTestCaseInSession(testCaseInSessionId, generateExecutionLogs(testResult).toString());
            List<TestStep> testSteps = TestNGResultUtils.getSeleniumRobotTestContext(testResult).getTestStepManager().getTestSteps();
            if (testSteps == null) {
                continue;
            }
            recordSteps(serverConnector, sessionId, testCaseInSessionId, testSteps, testResult);
            logger.info(String.format("Snapshots has been recorded with TestCaseSessionId: %d", testCaseInSessionId));
            TestNGResultUtils.setSnapshotTestCaseInSessionId(testResult, testCaseInSessionId);
            TestNGResultUtils.setSeleniumServerReportCreated(testResult, true);
        }
    }
}
Also used : ExceptionUtility(com.seleniumtests.util.ExceptionUtility) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ITestResult(org.testng.ITestResult) ArrayList(java.util.ArrayList) SeleniumTestsContextManager(com.seleniumtests.core.SeleniumTestsContextManager) JSONObject(org.json.JSONObject) IReporter(org.testng.IReporter) SeleniumRobotLogger(com.seleniumtests.util.logging.SeleniumRobotLogger) TestNGResultUtils(com.seleniumtests.core.utils.TestNGResultUtils) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Map(java.util.Map) Path(java.nio.file.Path) ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil) ITestContext(org.testng.ITestContext) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File) List(java.util.List) Paths(java.nio.file.Paths) Rectangle(org.openqa.selenium.Rectangle) TestStep(com.seleniumtests.reporter.logger.TestStep) Entry(java.util.Map.Entry) SnapshotCheckType(com.seleniumtests.driver.screenshots.SnapshotCheckType) TestNGContextUtils(com.seleniumtests.core.utils.TestNGContextUtils) TestStep(com.seleniumtests.reporter.logger.TestStep) Set(java.util.Set) ITestResult(org.testng.ITestResult) ITestContext(org.testng.ITestContext)

Example 2 with SeleniumRobotSnapshotServerConnector

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

the class SeleniumRobotServerTestRecorder method recordTestSession.

public void recordTestSession(ITestContext testContext) {
    SeleniumRobotSnapshotServerConnector serverConnector = getServerConnector();
    if (TestNGContextUtils.getTestSessionCreated(testContext) == null) {
        Integer sessionId = serverConnector.createSession(testContext.getName());
        TestNGContextUtils.setTestSessionCreated(testContext, sessionId);
    }
}
Also used : SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector)

Example 3 with SeleniumRobotSnapshotServerConnector

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

the class TestSeleniumRobotSnapshotServerConnector method testCreateSnapshotNull3.

@Test(groups = { "ut" }, expectedExceptions = SeleniumRobotServerException.class)
public void testCreateSnapshotNull3() throws UnirestException {
    SeleniumRobotSnapshotServerConnector connector = spy(configureMockedSnapshotServerConnection());
    Integer sessionId = connector.createSession("Session1");
    Integer testCaseId = connector.createTestCase("Test 1");
    Integer testCaseInSessionId = connector.createTestCaseInSession(sessionId, testCaseId, "Test 1");
    Integer testStepId = connector.createTestStep("Step 1", testCaseInSessionId);
    Integer stepResultId = connector.recordStepResult(true, "", 1, sessionId, testCaseInSessionId, testStepId);
    when(screenshot.getFullImagePath()).thenReturn(null);
    connector.createSnapshot(snapshot, sessionId, testCaseInSessionId, stepResultId);
}
Also used : SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with SeleniumRobotSnapshotServerConnector

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

the class TestSeleniumRobotSnapshotServerConnector method testCreateSnapshotNull2.

@Test(groups = { "ut" }, expectedExceptions = SeleniumRobotServerException.class)
public void testCreateSnapshotNull2() throws UnirestException {
    SeleniumRobotSnapshotServerConnector connector = spy(configureMockedSnapshotServerConnection());
    Integer sessionId = connector.createSession("Session1");
    Integer testCaseId = connector.createTestCase("Test 1");
    Integer testCaseInSessionId = connector.createTestCaseInSession(sessionId, testCaseId, "Test 1");
    Integer testStepId = connector.createTestStep("Step 1", testCaseInSessionId);
    Integer stepResultId = connector.recordStepResult(true, "", 1, sessionId, testCaseInSessionId, testStepId);
    when(snapshot.getScreenshot()).thenReturn(null);
    connector.createSnapshot(snapshot, sessionId, testCaseInSessionId, stepResultId);
}
Also used : SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with SeleniumRobotSnapshotServerConnector

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

the class TestSeleniumRobotSnapshotServerConnector method testServerNotActive.

@Test(groups = { "ut" })
public void testServerNotActive() {
    SeleniumRobotSnapshotServerConnector connector = new SeleniumRobotSnapshotServerConnector(false, SERVER_URL);
    Assert.assertFalse(connector.getActive());
}
Also used : SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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