Added a bunch of safeguard in tests to avoid fatal errors on failure

If the elements used in the tests are not found, most cases are now
reporting a failure instead of triggering a fatal error by calling a
method on null.