I know how to check values and create tests and do the error handling if something fails, but what I din't found anywhere was the following:

A test case tests specific things. But what when unexpected errors occurs which arent a covered by a specific check of a test? Is it possible to set something like a "watchdog for error messages" up or is the only way to get this done to create a function which is called after every step?

I'm using Selenium together with PHP/PHPUnit (but not integrated into the application which I test itself). Any "best practises" or hints to get this done are very welcome.

  • Good answer here: stackoverflow.com/questions/4189312/…
    – Sam Woods
    Sep 26, 2013 at 18:02
  • 1
    That's very interesting, but it seems to be that I wasn't clear enough. I don't think about JS errors or something like this. In my case the application itself throws a custom error message in a div if an error occures. Not all errors are that critical that they stop a workflow. But it's important for me to capture them too with Selenium. I know I could check every check for a error message. But what I'm searching is a tactic to do this for all pages automatically. Do I overlook something?
    – Andy
    Sep 26, 2013 at 20:48
  • Can you give an example scenario when such additional error message appear? Just to justify why you can use soft assertions for error msg check after each step.
    – dzieciou
    Mar 26, 2014 at 12:40
  • Does the PHPUnit have WebDriverEventListener functionality? I couldn't find it on their guide for it but that would be the optimal way to achieve your desired results.
    – Paul Muir
    Sep 22, 2014 at 17:44

1 Answer 1


Depending on what testrunner you are using it may have support for multithreading, so you could always create your own watchdog type method that runs on another thread while your test is running, captures all the errors that are written to that specific error message div you mentioned. The concurrent thread would basically loop on the div text and save any text that is put in it, returning that at the end of the test you would have a list of errors that had occurred.

  • Thanks for your answer. But as I understand, I have to handle this myself and there is no way to deal with this automatically? (beside calling my own function)
    – Andy
    Sep 27, 2013 at 16:40
  • @Andy when dealing with custom errors you usually end up having custom functions to call whenever you think you might encounter them. That may be where you end up unless you can learn to make an intelligent script that looks for deviations its only going to do what you tell it.
    – MichaelF
    Sep 27, 2013 at 20:08
  • I see your point and it makes sense of course. But I don't see a nicer way than calling the same "checkErrorMessage"-Function after every step. I differenciate a little bit. There is a workflow and the related checks (for example is the value ok, enter a value, click a button and so on), but fo UNEXPECTED errors I'll get something like: doSomething() checkForErrorMessages() doSomething2() checkForErrorMessages() doSomething3() checkForErrorMessages() doSomething4() ... It would be really nice to have a possibility to auto-check for not expected error messages beside custom-checks.
    – Andy
    Sep 28, 2013 at 7:40
  • Having it running in a thread would do away with the problem of having to call it over and over again. You set it off at the beginning and collect the data at the end. It seems like a nicer solution to calling the same function after every step.
    – gomesr
    Sep 29, 2013 at 19:11
  • You're right. But which testrunner would you use to get it done then?
    – Andy
    Oct 1, 2013 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.