Search in sources :

Example 1 with TestRunner

use of net.sf.sahi.test.TestRunner in project sakuli by ConSol.

the class SahiConnectorTest method testGetTestRunner.

@Test
public void testGetTestRunner() throws Exception {
    when(sahiProxyProperties.getProxyPort()).thenReturn(9000);
    final TestRunner testRunner = testling.getTestRunner();
    final String s = testRunner.toString();
    assertContains(s, "sahiHost = localhost");
    assertContains(s, "port = 9000");
    assertContains(s, "threads = 1");
}
Also used : TestRunner(net.sf.sahi.test.TestRunner) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 2 with TestRunner

use of net.sf.sahi.test.TestRunner in project sakuli by ConSol.

the class SahiConnectorTest method testStartSahiTestSuiteFAILURE.

@Test
public void testStartSahiTestSuiteFAILURE() throws Throwable {
    TestRunner testRunnerMock = mock(TestRunner.class);
    doReturn(testRunnerMock).when(testling).getTestRunner();
    doReturn(SAKULI_HOME_FOLDER_PATH).when(testling).getIncludeFolderJsPath();
    when(testRunnerMock.execute()).thenReturn("FAILURE");
    when(testSuiteMock.getStopDate()).thenReturn(new Date());
    testling.startSahiTestSuite();
    verify(testRunnerMock).addReport(any(Report.class));
    verify(testRunnerMock).setInitJS(anyString());
    verify(testSuiteMock).setStopDate(any(Date.class));
    verify(sakuliExceptionHandler).handleException(any(SakuliInitException.class));
    verify(sahiProxy).shutdown();
    verify(testling, never()).reconnect(any(Exception.class));
}
Also used : Report(net.sf.sahi.ant.Report) TestRunner(net.sf.sahi.test.TestRunner) Date(java.util.Date) ConnectException(java.net.ConnectException) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 3 with TestRunner

use of net.sf.sahi.test.TestRunner in project sakuli by ConSol.

the class SahiConnectorTest method testStartSahiTestSuiteReconnect.

@Test
public void testStartSahiTestSuiteReconnect() throws Throwable {
    TestRunner testRunnerMock = mock(TestRunner.class);
    doReturn(testRunnerMock).when(testling).getTestRunner();
    when(testRunnerMock.execute()).thenThrow(new ConnectException("TEST"));
    doNothing().when(testling).reconnect(any(Exception.class));
    doReturn(SAKULI_HOME_FOLDER_PATH).when(testling).getIncludeFolderJsPath();
    testling.startSahiTestSuite();
    verify(testRunnerMock).addReport(any(Report.class));
    verify(testRunnerMock).setInitJS(anyString());
    verify(sakuliExceptionHandler, never()).handleException(any(SakuliInitException.class));
    verify(sahiProxy).shutdown();
    verify(testling).reconnect(any(Exception.class));
}
Also used : Report(net.sf.sahi.ant.Report) TestRunner(net.sf.sahi.test.TestRunner) ConnectException(java.net.ConnectException) ConnectException(java.net.ConnectException) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 4 with TestRunner

use of net.sf.sahi.test.TestRunner in project sakuli by ConSol.

the class SahiConnector method startSahiTestSuite.

/**
     * starts a specific sahi test suite in sakuli
     */
public void startSahiTestSuite() throws SakuliInitException {
    logger.info("Start Sakuli-Test-Suite from folder \"" + testSuite.getTestSuiteFolder().toAbsolutePath().toString() + "\"");
    checkTestSuiteFile();
    //        ConnectionTester.checkTestCaseInitURL(testSuite);
    //default sahi runner to play the sahi script
    TestRunner runner = getTestRunner();
    runner.setIsSingleSession(false);
    //config reporter
    runner.addReport(new Report("html", sakuliProperties.getLogFolder().toAbsolutePath().toString()));
    //add include folder property
    runner.setInitJS(getInitJSString());
    try {
        //is there to handle exceptions in the catch block from this.reconnect()
        try {
            countConnections++;
            // Script-Runner starts
            logger.info("Sahi-Script-Runner starts!\n");
            //starts the script runner with the prefilled configurations
            String output = runner.execute();
            testSuite.setStopDate(new Date());
            logger.info("test suite '" + testSuite.getId() + "' stopped at " + TestSuite.GUID_DATE_FORMATE.format(testSuite.getStopDate()));
            logger.info("Sahi-Script-Runner executed with " + output);
            //should only thrown if an exception could fetched by the backend of some reason
            if (output.equals("FAILURE")) {
                if (isSahiScriptTimout(testSuite.getException())) {
                    logger.warn("Sahi-Script-Runner timeout detected, start retry!");
                    SakuliException causingError = new SakuliException(testSuite.getException());
                    //reset all values
                    InitializingServiceHelper.invokeInitializingServcies();
                    this.reconnect(causingError);
                } else if (testSuite.getException() == null) {
                    throw new SakuliInitException("SAHI-Proxy returned 'FAILURE' ");
                }
            }
        } catch (ConnectException | IllegalMonitorStateException e) {
            //Reconnect - wait for Thread "sahiRunner"
            this.reconnect(e);
        }
    } catch (Throwable e) {
        sakuliExceptionHandler.handleException(e);
    } finally {
        logger.info("test suite finished");
        //shutdown sahi proxy!
        sahiProxy.shutdown();
    }
}
Also used : Report(net.sf.sahi.ant.Report) SakuliInitException(org.sakuli.exceptions.SakuliInitException) TestRunner(net.sf.sahi.test.TestRunner) SakuliException(org.sakuli.exceptions.SakuliException) Date(java.util.Date) ConnectException(java.net.ConnectException)

Example 5 with TestRunner

use of net.sf.sahi.test.TestRunner in project sakuli by ConSol.

the class SahiConnectorTest method testStartSahiTestSuiteOK.

@Test
public void testStartSahiTestSuiteOK() throws Throwable {
    TestRunner testRunnerMock = mock(TestRunner.class);
    doReturn(testRunnerMock).when(testling).getTestRunner();
    doReturn(SAKULI_HOME_FOLDER_PATH).when(testling).getIncludeFolderJsPath();
    when(testRunnerMock.execute()).thenReturn("OK");
    when(testSuiteMock.getStopDate()).thenReturn(new Date());
    testling.startSahiTestSuite();
    verify(testRunnerMock).addReport(any(Report.class));
    verify(testRunnerMock).setInitJS(anyString());
    verify(testSuiteMock).setStopDate(any(Date.class));
    verify(sakuliExceptionHandler, never()).handleException(any(SakuliInitException.class));
    verify(sahiProxy).shutdown();
    verify(testling, never()).reconnect(any(Exception.class));
}
Also used : Report(net.sf.sahi.ant.Report) TestRunner(net.sf.sahi.test.TestRunner) Date(java.util.Date) ConnectException(java.net.ConnectException) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Aggregations

TestRunner (net.sf.sahi.test.TestRunner)5 ConnectException (java.net.ConnectException)4 Report (net.sf.sahi.ant.Report)4 BaseTest (org.sakuli.BaseTest)4 Test (org.testng.annotations.Test)4 Date (java.util.Date)3 SakuliException (org.sakuli.exceptions.SakuliException)1 SakuliInitException (org.sakuli.exceptions.SakuliInitException)1