Search in sources :

Example 36 with ErrorCause

use of com.seleniumtests.core.testanalysis.ErrorCause in project seleniumRobot by bhecquet.

the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceErrorInComparison.

/**
 * If any error occurs in comparison, continue
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceErrorInComparison() throws Exception {
    ITestResult testResult = Reporter.getCurrentTestResult();
    TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
    SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, stepFailed, lastStep));
    // comparison successful
    PowerMockito.whenNew(StepReferenceComparator.class).withArguments(new File(stepFailed.getSnapshots().get(0).getScreenshot().getFullImagePath()), referenceImgStep2).thenReturn(stepReferenceComparatorStep2);
    when(stepReferenceComparatorStep2.compare()).thenThrow(new ConfigurationException("error on init"));
    List<ErrorCause> causes = new ErrorCauseFinder(testResult).compareStepInErrorWithReference();
    Assert.assertEquals(causes.size(), 0);
    Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInReferencePicture(testResult));
}
Also used : ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 37 with ErrorCause

use of com.seleniumtests.core.testanalysis.ErrorCause in project seleniumRobot by bhecquet.

the class TestErrorCauseFinder method testSearchInLastStepDetectedErrorField.

/**
 * In case an error_field is found, check we show it as an error
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testSearchInLastStepDetectedErrorField() 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, "ok"));
    labels.add(new Label(0, 100, 100, 120, "nothing"));
    List<Field> fields = new ArrayList<>();
    fields.add(new Field(0, 100, 0, 20, "", ErrorCauseFinder.CLASS_ERROR_FIELD));
    fields.add(new Field(0, 100, 200, 220, "", "field"));
    when(imageFieldDetector.detectFields()).thenReturn(fields);
    when(imageFieldDetector.detectLabels()).thenReturn(labels);
    List<ErrorCause> causes = new ErrorCauseFinder(testResult).findErrorInLastStepSnapshots();
    Assert.assertEquals(causes.size(), 1);
    Assert.assertEquals(causes.get(0).getType(), ErrorType.ERROR_IN_FIELD);
    Assert.assertEquals(causes.get(0).getDescription(), "At least one field in error");
    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) 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)

Example 38 with ErrorCause

use of com.seleniumtests.core.testanalysis.ErrorCause 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)

Example 39 with ErrorCause

use of com.seleniumtests.core.testanalysis.ErrorCause in project seleniumRobot by bhecquet.

the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceAssertionError.

/**
 * When step fails due to assertion error, we do not compare snapshot with reference as the failure is expected
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceAssertionError() throws Exception {
    stepFailed.setActionException(new AssertionError("result is not the expected one"));
    ITestResult testResult = Reporter.getCurrentTestResult();
    TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
    SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, stepFailed, lastStep));
    PowerMockito.whenNew(StepReferenceComparator.class).withAnyArguments().thenReturn(stepReferenceComparatorStep2);
    List<ErrorCause> causes = new ErrorCauseFinder(testResult).compareStepInErrorWithReference();
    // no comparison done
    PowerMockito.verifyNew(StepReferenceComparator.class, never()).withArguments(any(File.class), any(File.class));
    ;
    Assert.assertEquals(causes.size(), 0);
    Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInReferencePicture(testResult));
}
Also used : ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) StepReferenceComparator(com.seleniumtests.util.imaging.StepReferenceComparator) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 40 with ErrorCause

use of com.seleniumtests.core.testanalysis.ErrorCause in project seleniumRobot by bhecquet.

the class TestErrorCauseFinder method testSearchInLastStepErrorMessage.

/**
 * Check error causes are found with various error messages
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testSearchInLastStepErrorMessage() 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()).thenReturn(fields);
    when(imageFieldDetector.detectLabels()).thenReturn(labels);
    List<ErrorCause> causes = new ErrorCauseFinder(testResult).findErrorInLastStepSnapshots();
    Assert.assertEquals(causes.size(), 2);
    Assert.assertEquals(causes.get(0).getType(), ErrorType.ERROR_MESSAGE);
    // no failed step except "last step", keep association
    Assert.assertEquals(causes.get(0).getTestStep(), lastStep);
    Assert.assertEquals(causes.get(0).getDescription(), "il y a eu un gros problème");
    Assert.assertEquals(causes.get(1).getType(), ErrorType.ERROR_MESSAGE);
    Assert.assertEquals(causes.get(1).getDescription(), "some error");
    Assert.assertEquals(causes.get(1).getTestStep(), lastStep);
    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) 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

ErrorCause (com.seleniumtests.core.testanalysis.ErrorCause)49 GenericTest (com.seleniumtests.GenericTest)48 Test (org.testng.annotations.Test)48 ErrorCauseFinder (com.seleniumtests.core.testanalysis.ErrorCauseFinder)28 ITestResult (org.testng.ITestResult)28 MockitoTest (com.seleniumtests.MockitoTest)27 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 File (java.io.File)25 TestStep (com.seleniumtests.reporter.logger.TestStep)18 ArrayList (java.util.ArrayList)16 Field (com.seleniumtests.connectors.selenium.fielddetector.Field)8 Label (com.seleniumtests.connectors.selenium.fielddetector.Label)8 StepReferenceComparator (com.seleniumtests.util.imaging.StepReferenceComparator)8 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)3 Color (java.awt.Color)2 BufferedImage (java.awt.image.BufferedImage)2 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)1