Codeception – Custom Error Reporting

Codeception is testing tool for php code. You can test that your pages are functional
or not. It help you to check elements of the page , text in elements , links on the page, data
rendered correctly on page etc.

Here we go to create an extension to log all the errors of your tests files and show them in mail or you can also save it in your custom log file. Either you can create acceptance/functional or unit test cases. As codeception test the page from top to bottom and abort as the error fall and record errors separately.
If you want all errors at the end of the execution of page then it is important to know that while creating codeception test, we checked element or text present on page. We have to avoid elements that gives fatal error like see, dontsee etc. You can also use cansee in place of see
and cantsee in place of dontsee.

Step 1:

Create a file as automation/Codeception/Extension/MyCustomExtension.php.


Step 2:

In codeception.yml replace




Step 3:

And at last add this extension file under automation/tests/bootstrap.php


Notes about the Codeception events:

  1. SUITE_AFTER  :- It runs when all the test files  are completed  and executed. Like if you run php codecept.phar run acceptance command then it will execute when all acceptance test get executed completely.
  2. SUITE_ BEFORE:- It runs as opposite of SUITE_AFTER i.e. at the beginning of execution.
  3. TEST_FAIL :- It runs when the test get failed means at each error test fail function get executed.
  4. TEST_END :- It runs at the complete of single test. Like, Suite_after run at the complete of all test files under acceptance but test_end runs after each of the test  get executed .
  5. RESULT_PRINT_AFTER:- It prints the result  after the complete execution.


Let’s assume, I have to  send mail of all errors at the end of each test page wise – For  which store the filename before test in the variable , At each fail of the test store all errors.  Then at the end of the test send mail of all errors.

To get the name of the file in which error has been occurred we have to use getTestFileName function of descriptor. There are many more functions for different functionality. It is just an example.


getTestFileName is used for getting file name of test.

getMessage gives error message.

getTrace gives you error and line number in detail and there are many more functions you can use according to your need.

To get the complete detail about codeception check

If you have any problem or any query regarding this post you can write to us in comments below.

Please follow and like us: