Search in sources :

Example 16 with ErrorCauseFinder

use of com.seleniumtests.core.testanalysis.ErrorCauseFinder 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 17 with ErrorCauseFinder

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

Example 18 with ErrorCauseFinder

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

the class TestErrorCauseFinder method testSearchInLastStepNoLastStep.

@Test(groups = { "ut" })
public void testSearchInLastStepNoLastStep() throws Exception {
    ITestResult testResult = Reporter.getCurrentTestResult();
    TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
    SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1));
    List<ErrorCause> causes = new ErrorCauseFinder(testResult).findErrorInLastStepSnapshots();
    Assert.assertEquals(causes.size(), 0);
}
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)

Example 19 with ErrorCauseFinder

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

the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceSearchAlreadyDone.

@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceSearchAlreadyDone() throws Exception {
    ITestResult testResult = Reporter.getCurrentTestResult();
    TestNGResultUtils.setErrorCauseSearchedInReferencePicture(testResult, true);
    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()).thenReturn(90);
    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 20 with ErrorCauseFinder

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

the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceErrorGettingReferenceOnServer.

/**
 * We get an error when trying to get reference snapshot from server
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceErrorGettingReferenceOnServer() throws Exception {
    ITestResult testResult = Reporter.getCurrentTestResult();
    TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
    SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, stepFailed, lastStep));
    // no reference exists for stepFailed on server
    when(serverConnector.getReferenceSnapshot(1)).thenThrow(new SeleniumRobotServerException("error"));
    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) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException) 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)28 ErrorCauseFinder (com.seleniumtests.core.testanalysis.ErrorCauseFinder)28 ITestResult (org.testng.ITestResult)28 GenericTest (com.seleniumtests.GenericTest)27 MockitoTest (com.seleniumtests.MockitoTest)27 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 Test (org.testng.annotations.Test)27 File (java.io.File)25 Field (com.seleniumtests.connectors.selenium.fielddetector.Field)8 Label (com.seleniumtests.connectors.selenium.fielddetector.Label)8 StepReferenceComparator (com.seleniumtests.util.imaging.StepReferenceComparator)8 ArrayList (java.util.ArrayList)7 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)3 Color (java.awt.Color)2 BufferedImage (java.awt.image.BufferedImage)2 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)1