In what cases will the `ErrorCollector` contain mutliple Exceptions?

What’s going on?

I have my custom TestCaseReporter, which includes in Reports folder the following:

  • screenshot of the browser,
  • the entire DOM,
  • a text file containing the browser URL, and
  • a text file containing the error message

Its report() method accepts a TestCaseContext, which we pass in AfterTestCase in the Test Listener. But this introduces a problem

Problem

Many of my test cases have their own TearDown hook, and this teardown hook will run before the Test Listener’s AfterTestCase (as it should be)…but this means that, by the time we report on the test case, it’s too late!

There has got to be a way to do this report inside the test case instead!

Solution

We create a MockTestCaseContext (or something similar):

  • we can use our custom test case util to get the name of the test case
  • we use ErrorCollector.getCollector().getCoppiedErrors() to get the list of Exceptions that thrown at runtime
  • we stub out everything else

In our Test case, in TearDownIfFailed, first thing we do is create instance of this MockTestCaseContext, and give it to TestCaseReporter.report() (or create and call similar method called TestCaseReporter.reportFromTestCase() to set a flag, to prevent the test listener from doing the report afterwards)

But there’s one thing holding me up from implementing this right now…

Hangups

What scenarios will cause the ErrorCollector to contain multiple Exceptions?

1 Like

@mwarren04011990

ErrorCollector will have many error if you run a test case that contains many test steps with CONTINUE_ON_FALILURE.

This collector will collect all errors but only report the first error in the end.

2 Likes