I had some issues diagnosing 500 errors that were happening with Mink. The main issue being that a page would 500, but then the test would proceed and fail a later step. Unfortunately the HTML/screenshot that was captured does not capture the error, but instead captures the assertion which doesn’t help debug.
It’s possible to react after a step and check if the last Mink request was a 500 or not. This way, we fail on the 500, and not on the subsequent assertions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php /** * @AfterStep */ public function afterStep(Behat\Behat\Hook\Scope\AfterStepScope $scope) { // Fail if we got a 500. try { $this->minkContext->assertSession(); $this->minkContext->assertNotHttpResponse(500); } catch (Behat\Mink\Exception\DriverException $e) { // Page is not loaded. } } |