Search in sources :

Example 26 with ErrorCause

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

the class TestErrorCause method testEqualsNullStep1.

@Test(groups = { "ut" })
public void testEqualsNullStep1() {
    ErrorCause cause1 = new ErrorCause(ErrorType.APPLICATION_CHANGED, "some changes", null);
    ErrorCause cause2 = new ErrorCause(ErrorType.APPLICATION_CHANGED, "some changes", new TestStep("step2", null, new ArrayList<>(), true));
    Assert.assertNotEquals(cause1, cause2);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 27 with ErrorCause

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

the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceBadMatchErrorGettingReference.

/**
 * Bad match: an error occurs when getting reference snapshot
 * We should not fail
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceBadMatchErrorGettingReference() 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);
    PowerMockito.whenNew(StepReferenceComparator.class).withArguments(new File(stepFailed.getSnapshots().get(0).getScreenshot().getFullImagePath()), referenceImgStep1).thenReturn(stepReferenceComparatorStep1);
    // bad comparison with step2 reference
    when(stepReferenceComparatorStep2.compare()).thenReturn(49);
    // error occurs when getting reference on step 1
    when(serverConnector.getReferenceSnapshot(0)).thenReturn(null);
    List<ErrorCause> causes = new ErrorCauseFinder(testResult).compareStepInErrorWithReference();
    Assert.assertEquals(causes.size(), 1);
    Assert.assertEquals(causes.get(0).getType(), ErrorType.UNKNOWN_PAGE);
    Assert.assertNull(causes.get(0).getDescription());
    Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInReferencePicture(testResult));
}
Also used : ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) 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 28 with ErrorCause

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

the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceNoIDForStep3.

/**
 * Same thing as above but only step1 has no ID with bad match so we cannot look for previous step reference
 * In this case, we get an unknown_page cause
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceNoIDForStep3() throws Exception {
    step1.setStepResultId(null);
    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);
    PowerMockito.whenNew(StepReferenceComparator.class).withArguments(new File(stepFailed.getSnapshots().get(0).getScreenshot().getFullImagePath()), referenceImgStep1).thenReturn(stepReferenceComparatorStep1);
    // bad comparison with step2 reference
    when(stepReferenceComparatorStep2.compare()).thenReturn(49);
    // good comparison with step1 reference
    when(stepReferenceComparatorStep1.compare()).thenReturn(81);
    List<ErrorCause> causes = new ErrorCauseFinder(testResult).compareStepInErrorWithReference();
    Assert.assertEquals(causes.size(), 1);
    Assert.assertEquals(causes.get(0).getType(), ErrorType.UNKNOWN_PAGE);
    Assert.assertNull(causes.get(0).getDescription());
}
Also used : ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) 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 29 with ErrorCause

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

the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceBadMatchNoPreviousStep.

/**
 * Matching between reference picture stored on server and the one for current test is bad (we are not on the right page)
 * No previous step can be found
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceBadMatchNoPreviousStep() throws Exception {
    ITestResult testResult = Reporter.getCurrentTestResult();
    TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
    SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(stepFailed, lastStep));
    // comparison successful
    PowerMockito.whenNew(StepReferenceComparator.class).withArguments(new File(stepFailed.getSnapshots().get(0).getScreenshot().getFullImagePath()), referenceImgStep2).thenReturn(stepReferenceComparatorStep2);
    // bad comparison with step2 reference
    when(stepReferenceComparatorStep2.compare()).thenReturn(49);
    List<ErrorCause> causes = new ErrorCauseFinder(testResult).compareStepInErrorWithReference();
    Assert.assertEquals(causes.size(), 1);
    Assert.assertEquals(causes.get(0).getType(), ErrorType.UNKNOWN_PAGE);
    Assert.assertNull(causes.get(0).getDescription());
    Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInReferencePicture(testResult));
}
Also used : ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) 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 30 with ErrorCause

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

the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceNoStep.

/**
 * Check the case where no TestStep is available
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceNoStep() throws Exception {
    ITestResult testResult = Reporter.getCurrentTestResult();
    TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
    SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(new ArrayList<>());
    List<ErrorCause> causes = new ErrorCauseFinder(testResult).compareStepInErrorWithReference();
    Assert.assertEquals(causes.size(), 0);
    Assert.assertFalse(TestNGResultUtils.isErrorCauseSearchedInReferencePicture(testResult));
}
Also used : ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) 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