Skip to content

Commit

Permalink
issue #467: add UT
Browse files Browse the repository at this point in the history
  • Loading branch information
bhecquet committed Nov 26, 2021
1 parent 1fad1d2 commit 8e213f3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,12 @@ public Date getVideoStartDate() {
public void setVideoStartDate(Date videoStartDate) {
this.videoStartDate = videoStartDate;
}

/**
* For tests only
* @param testSteps
*/
public void setTestSteps(List<TestStep> testSteps) {
this.testSteps = testSteps;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public List<ErrorCause> findErrorCause() {
List<ErrorCause> causes = new ArrayList<>();

causes.addAll(findErrorInLastStepSnapshots());
causes.addAll(compareStepInErrorWithReference());

return causes;
}
Expand All @@ -79,9 +80,14 @@ public List<ErrorCause> findErrorCause() {
* If reference cannot be found, skip this step
* @return
*/
private List<ErrorCause> compareStepInErrorWithReference() {
public List<ErrorCause> compareStepInErrorWithReference() {
List<ErrorCause> causes = new ArrayList<>();

// do not seearch again
if (TestNGResultUtils.isErrorCauseSearchedInReferencePicture(testResult)) {
return causes;
}

// don't analyze if result has not been recorded on seleniumRobot server
TestStepManager testStepManager = TestNGResultUtils.getSeleniumRobotTestContext(testResult).getTestStepManager();
if (testStepManager.getLastTestStep().getStepResultId() == null) {
Expand Down Expand Up @@ -137,7 +143,7 @@ private List<ErrorCause> compareStepInErrorWithReference() {
}


TestNGResultUtils.setErrorCauseInReferencePicture(testResult, true);
TestNGResultUtils.setErrorCauseSearchedInReferencePicture(testResult, true);

return causes;
}
Expand Down Expand Up @@ -183,10 +189,15 @@ private int compareReferenceToStepSnapshot(File stepSnapshot, File referenceSnap
* Search in snapshots of the last step if there are any displayed errors (error messages or fields in error)
* @return
*/
private List<ErrorCause> findErrorInLastStepSnapshots() {
public List<ErrorCause> findErrorInLastStepSnapshots() {

List<ErrorCause> causes = new ArrayList<>();

// do not seearch again
if (TestNGResultUtils.isErrorCauseSearchedInLastStep(testResult)) {
return causes;
}

TestStep lastTestStep = TestNGResultUtils.getSeleniumRobotTestContext(testResult).getTestStepManager().getLastTestStep();

if (lastTestStep != null) {
Expand All @@ -196,7 +207,6 @@ private List<ErrorCause> findErrorInLastStepSnapshots() {
List<Field> fields = imageFieldDetector.detectFields();
List<Label> labels = imageFieldDetector.detectLabels();


// are some text considered as error messages (mainly in red on page)
for (Field field: fields) {
if ("error_message".equals(field.getClassName())) {
Expand Down Expand Up @@ -227,7 +237,7 @@ private List<ErrorCause> findErrorInLastStepSnapshots() {
}

}
TestNGResultUtils.setErrorCauseInLastStep(testResult, true);
TestNGResultUtils.setErrorCauseSearchedInLastStep(testResult, true);
}

return causes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class TestNGResultUtils {
private static final String DESCRIPTION = "description"; // description of the test method, if any
private static final String ERROR_CAUSES = "errorCauses"; // list of causes of the test error
private static final String ERROR_CAUSE_IN_LAST_STEP = "errorCauseInLastStep"; // true when we have searched for error cause in the last step
private static final String ERROR_CAUSE_IN_REFERENCE = "errorCauseInLastStep"; // true when we have searched for error cause by comparing reference picture of the failed step
private static final String ERROR_CAUSE_IN_REFERENCE = "errorCauseInReference"; // true when we have searched for error cause by comparing reference picture of the failed step

private TestNGResultUtils() {
// nothing to do
Expand Down Expand Up @@ -514,19 +514,19 @@ public static void setErrorCauses(ITestResult testNGResult, List<ErrorCause> err
testNGResult.setAttribute(ERROR_CAUSES, errorCauses);
}

public static Boolean getErrorCauseInLastStep(ITestResult testNGResult) {
public static boolean isErrorCauseSearchedInLastStep(ITestResult testNGResult) {
return isReportCreated(testNGResult, ERROR_CAUSE_IN_LAST_STEP);
}

public static void setErrorCauseInLastStep(ITestResult testNGResult, Boolean errorCauseInLastStep) {
public static void setErrorCauseSearchedInLastStep(ITestResult testNGResult, Boolean errorCauseInLastStep) {
testNGResult.setAttribute(ERROR_CAUSE_IN_LAST_STEP, errorCauseInLastStep);
}

public static Boolean getErrorCauseInReferencePicture(ITestResult testNGResult) {
public static boolean isErrorCauseSearchedInReferencePicture(ITestResult testNGResult) {
return isReportCreated(testNGResult, ERROR_CAUSE_IN_REFERENCE);
}

public static void setErrorCauseInReferencePicture(ITestResult testNGResult, Boolean errorCauseInReferencePicture) {
public static void setErrorCauseSearchedInReferencePicture(ITestResult testNGResult, Boolean errorCauseInReferencePicture) {
testNGResult.setAttribute(ERROR_CAUSE_IN_REFERENCE, errorCauseInReferencePicture);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class TestErrorCauseFInder extends GenericTest {

@Test(groups={"it"})
@Test(groups={"it"}, enabled=false)
public void testMultiThreadTests(ITestContext testContext) throws Exception {

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,30 @@ public void testCustomReportCreatedNull() {
Assert.assertFalse(TestNGResultUtils.isCustomReportCreated(tr));
}

@Test(groups={"ut"})
public void testErrorCauseSearchedInLastStep() {
ITestResult tr = Reporter.getCurrentTestResult();
TestNGResultUtils.setErrorCauseSearchedInLastStep(tr, true);
Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInLastStep(tr));
}
@Test(groups={"ut"})
public void testErrorCauseSearchedInLastStepNull() {
ITestResult tr = Reporter.getCurrentTestResult();
Assert.assertFalse(TestNGResultUtils.isErrorCauseSearchedInLastStep(tr));
}

@Test(groups={"ut"})
public void testErrorCauseSearchedInReferencePicture() {
ITestResult tr = Reporter.getCurrentTestResult();
TestNGResultUtils.setErrorCauseSearchedInReferencePicture(tr, true);
Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInReferencePicture(tr));
}
@Test(groups={"ut"})
public void testErrorCauseSearchedInReferencePictureNull() {
ITestResult tr = Reporter.getCurrentTestResult();
Assert.assertFalse(TestNGResultUtils.isErrorCauseSearchedInReferencePicture(tr));
}

@Test(groups={"ut"})
public void testNoMoreRetry() {
ITestResult tr = Reporter.getCurrentTestResult();
Expand Down

0 comments on commit 8e213f3

Please sign in to comment.