Search in sources :

Example 11 with SakuliCheckedException

use of org.sakuli.exceptions.SakuliCheckedException in project sakuli by ConSol.

the class GearmanTestCaseTemplateOutputBuilderIntegrationTest method testException.

@Test
public void testException() throws Exception {
    TestCase testCase = new TestCaseExampleBuilder().withState(TestCaseState.ERRORS).withWarningTime(20).withCriticalTime(30).withStartDate(new DateTime(1970, 1, 1, 10, 36, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 23, 550).toDate()).withId("case2").withTestCaseSteps(Arrays.asList(new TestCaseStepExampleBuilder().withState(TestCaseStepState.ERRORS).withName("Test_Sahi_landing_page_(case2)").withWarningTime(5).withStartDate(new DateTime(1970, 1, 1, 10, 36, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 1, 50).toDate()).withException(new SakuliCheckedException("_highlight(_link(\"xSL Manager\")); TypeError: el is undefined Sahi.prototype._highlight@http://sahi.example.com/_s_/spr/concat.js:1210:9 @http://sahi.example.com/_s_/spr/concat.js line 3607 > eval:1:1 Sahi.prototype.ex@http://sahi.example.com/_s_/spr/concat.js:3607:9 Sahi.prototype.ex@http://sahi.example.com/_s_/spr/sakuli/inject.js:46:12 @http://sahi.example.com/_s_/spr/concat.js:3373:5  <a href='/_s_/dyn/Log_getBrowserScript?href=/root/sakuli/example_test_suites/example_xfce/case2/sakuli_demo.js&n=1210'><b>Click for browser script</b></a>")).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Calculation_(case2)").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 36, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 17, 30).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Editor_(case2)").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 36, 20).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 21, 390).toDate()).buildExample())).buildExample();
    ScreenshotDiv screenshotDiv = new ScreenshotDiv();
    screenshotDiv.setId("sakuli_screenshot243575009");
    screenshotDiv.setFormat("jpg");
    screenshotDiv.setBase64screenshot("/9j/4AAQSkZJRgABAgAAAQABAAD9k=");
    doReturn(screenshotDiv).when(screenshotDivConverter).convert(notNull(Exception.class));
    String output = testling.createOutput(testCase);
    Assert.assertEquals(output, loadExpectedOutput(TestCaseState.ERRORS.name()));
}
Also used : TestCase(org.sakuli.datamodel.TestCase) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException) ScreenshotDiv(org.sakuli.services.forwarder.ScreenshotDiv) DateTime(org.joda.time.DateTime) SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException) IOException(java.io.IOException) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) Test(org.testng.annotations.Test) IntegrationTest(org.sakuli.integration.IntegrationTest) BaseTest(org.sakuli.BaseTest)

Example 12 with SakuliCheckedException

use of org.sakuli.exceptions.SakuliCheckedException in project sakuli by ConSol.

the class Application method killAppPID.

private Application killAppPID(Integer pid) throws SakuliCheckedException {
    try {
        String cmd = String.format(Settings.isWindows() ? "Taskkill /PID %d /F" : "kill -9 %d", pid);
        CommandExecutorHelper.execute(cmd, 0);
    } catch (Exception e) {
        throw new SakuliCheckedException(e, String.format("could not kill application with PID '%d'.", pid));
    }
    return this;
}
Also used : SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException) SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException)

Example 13 with SakuliCheckedException

use of org.sakuli.exceptions.SakuliCheckedException in project sakuli by ConSol.

the class TestSuiteTest method testGetExceptionMessage.

@Test
public void testGetExceptionMessage() {
    TestSuite testSuite = new TestSuite();
    String message = "suite-exception";
    testSuite.addException(new SakuliCheckedException(message));
    assertEquals(testSuite.getExceptionMessages(false), message);
    assertEquals(testSuite.getExceptionMessages(true), message);
    TestCase tc1 = new TestCase("case1", "case1");
    String messageCase = "case-exception";
    tc1.addException(new SakuliCheckedException(messageCase));
    testSuite.addTestCase(tc1.getId(), tc1);
    assertEquals(testSuite.getExceptionMessages(false), message + "\n" + "CASE \"" + tc1.getId() + "\": " + messageCase);
    assertEquals(testSuite.getExceptionMessages(true), message + " -- CASE \"" + tc1.getId() + "\": " + messageCase);
}
Also used : SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException) Test(org.testng.annotations.Test)

Example 14 with SakuliCheckedException

use of org.sakuli.exceptions.SakuliCheckedException in project sakuli by ConSol.

the class TestSuiteTest method testGetExceptionMessageWithErrorInStep.

@Test
public void testGetExceptionMessageWithErrorInStep() {
    TestSuite testSuite = new TestSuite();
    String message = "suite-exception";
    testSuite.addException(new SakuliCheckedException(message));
    assertEquals(testSuite.getExceptionMessages(false), message);
    assertEquals(testSuite.getExceptionMessages(true), message);
    TestCase tc1 = new TestCase("case1", "case1");
    String messageCase = "case-exception";
    tc1.addException(new SakuliCheckedException(messageCase));
    testSuite.addTestCase(tc1.getId(), tc1);
    TestCaseStep step1 = new TestCaseStepBuilder("step1").build();
    String messageStep = "step-exception";
    step1.addException(new SakuliCheckedException(messageStep));
    tc1.addStep(step1);
    assertEquals(testSuite.getExceptionMessages(false), message + "\n" + "CASE \"" + tc1.getId() + "\": " + messageCase + "\n\tSTEP \"" + step1.getId() + "\": " + messageStep);
    assertEquals(testSuite.getExceptionMessages(true), message + " -- CASE \"" + tc1.getId() + "\": " + messageCase + " - STEP \"" + step1.getId() + "\": " + messageStep);
    tc1.exception = null;
    assertEquals(testSuite.getExceptionMessages(false), message + "\n" + "CASE \"" + tc1.getId() + "\": " + "\n\tSTEP \"" + step1.getId() + "\": " + messageStep);
    assertEquals(testSuite.getExceptionMessages(true), message + " -- CASE \"" + tc1.getId() + "\": " + "STEP \"" + step1.getId() + "\": " + messageStep);
    testSuite.exception = null;
    assertEquals(testSuite.getExceptionMessages(false), "CASE \"" + tc1.getId() + "\": " + "\n\tSTEP \"" + step1.getId() + "\": " + messageStep);
    assertEquals(testSuite.getExceptionMessages(true), "CASE \"" + tc1.getId() + "\": " + "STEP \"" + step1.getId() + "\": " + messageStep);
}
Also used : SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException) TestCaseStepBuilder(org.sakuli.datamodel.builder.TestCaseStepBuilder) Test(org.testng.annotations.Test)

Example 15 with SakuliCheckedException

use of org.sakuli.exceptions.SakuliCheckedException in project sakuli by ConSol.

the class BaseActionLoaderTest method testInitNoSahiSession.

@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Test
public void testInitNoSahiSession() throws Exception {
    String testCaseId = "xyz";
    when(testSuite.getTestCase(testCaseId)).thenReturn(new TestCase("Test", testCaseId));
    when(rhinoScriptRunner.getSession()).thenReturn(null);
    when(sakuliProperties.isLoadJavaScriptEngine()).thenReturn(true);
    ArgumentCaptor<SakuliCheckedException> ac = ArgumentCaptor.forClass(SakuliCheckedException.class);
    testling.init(testCaseId, ".");
    verify(exceptionHandler).handleException(ac.capture());
    assertEquals(ac.getValue().getMessage(), "cannot init rhino script runner with sakuli custom delay variable 'sakuli-delay-active'");
    verify(session, never()).setVariable(anyString(), anyString());
}
Also used : TestCase(org.sakuli.datamodel.TestCase) SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException) Test(org.testng.annotations.Test)

Aggregations

SakuliCheckedException (org.sakuli.exceptions.SakuliCheckedException)19 Test (org.testng.annotations.Test)13 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)8 TestSuiteExampleBuilder (org.sakuli.builder.TestSuiteExampleBuilder)7 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)6 TestSuite (org.sakuli.datamodel.TestSuite)6 IOException (java.io.IOException)4 DateTime (org.joda.time.DateTime)4 BaseTest (org.sakuli.BaseTest)4 IntegrationTest (org.sakuli.integration.IntegrationTest)4 ScreenshotDiv (org.sakuli.services.forwarder.ScreenshotDiv)4 TestCase (org.sakuli.datamodel.TestCase)3 Path (java.nio.file.Path)2 Date (java.util.Date)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 ConnectException (java.net.ConnectException)1 TreeSet (java.util.TreeSet)1 Report (net.sf.sahi.ant.Report)1 TestRunner (net.sf.sahi.test.TestRunner)1