Search in sources :

Example 66 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class TestErrorCauseFinder method testSearchInLastStepErrorMessageWithException.

/**
 * Check error is only logged when something goes wrong while analyzing picture
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testSearchInLastStepErrorMessageWithException() throws Exception {
    ITestResult testResult = Reporter.getCurrentTestResult();
    TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
    SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, lastStep));
    PowerMockito.whenNew(ImageFieldDetector.class).withArguments(new File(lastStep.getSnapshots().get(0).getScreenshot().getFullImagePath()), (double) 1, FieldType.ERROR_MESSAGES_AND_FIELDS).thenReturn(imageFieldDetector);
    List<Label> labels = new ArrayList<>();
    labels.add(new Label(0, 100, 20, 50, "il y a eu un gros problème"));
    labels.add(new Label(0, 100, 100, 120, "some error"));
    List<Field> fields = new ArrayList<>();
    fields.add(new Field(0, 100, 0, 20, "", "field"));
    fields.add(new Field(0, 100, 200, 220, "", "field"));
    when(imageFieldDetector.detectFields()).thenThrow(new ConfigurationException("error"));
    when(imageFieldDetector.detectLabels()).thenReturn(labels);
    List<ErrorCause> causes = new ErrorCauseFinder(testResult).findErrorInLastStepSnapshots();
    Assert.assertEquals(causes.size(), 0);
    Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInLastStep(testResult));
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Label(com.seleniumtests.connectors.selenium.fielddetector.Label) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Aggregations

ConfigurationException (com.seleniumtests.customexception.ConfigurationException)66 ArrayList (java.util.ArrayList)19 File (java.io.File)18 IOException (java.io.IOException)14 HashMap (java.util.HashMap)13 Test (org.testng.annotations.Test)13 Matcher (java.util.regex.Matcher)9 List (java.util.List)8 UnirestException (kong.unirest.UnirestException)8 GenericTest (com.seleniumtests.GenericTest)7 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ScenarioException (com.seleniumtests.customexception.ScenarioException)5 BrowserType (com.seleniumtests.driver.BrowserType)5 Map (java.util.Map)5 Pattern (java.util.regex.Pattern)5 Collectors (java.util.stream.Collectors)5 Win32Exception (com.sun.jna.platform.win32.Win32Exception)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Files (java.nio.file.Files)4