Implement PHPUnit\Framework\TestListener, save driver content if there was an error.

@param Test                                    $test
@param \PHPUnit\Framework\AssertionFailedError $failure
@param int                                     $time
485230
public function addFailure(Test $test, AssertionFailedError $failure, float $time): void
    {
        if ($test instanceof TestCase and $test->is_driver_active() and $test->driver()->is_page_active()) {
            $this->save_driver_content(
                $test->driver(),
                \get_class($test).'_'.$test->getName(false),
                $failure->getMessage()
            );
        }
    }
1234592
public function fail($exception)
    {
        Event::trigger('onFailure', array(
            'exception' => $exception,
            'job' => $this,
        ));

        $this->updateStatus(Status::STATUS_FAILED);
        Failure::create(
            $this->payload,
            $exception,
            $this->worker,
            $this->queue
        );

        Stat::incr('failed');
        Stat::incr('failed:' . $this->worker);
    }
542778
public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time)
    {
        if (!$this->colors) {
            parent::addError($test, $e, $time);

            return;
        }

        $this->writeProgress(Coloring::magenta('E'));
        $this->lastTestFailed = true;
    }
625742
protected function writeWarning(\PHPUnit_Framework_Test $test, \Exception $e, $time)
    {
        $this->writeFailureOrError($test, $e, $time, 'failure');
    }
525991
public static function fail($format, $args = null, $_ = null) {
        throw new EnsureException(vsprintf($format, array_slice(func_get_args(), 1)));
    }
1004671
protected function writeError(\PHPUnit_Framework_Test $test, \Exception $e, $time)
    {
        $this->writeFailureOrError($test, $e, $time, 'error');
    }
298288
public function debugWebDriverLogs(TestInterface $test = null)
    {
        if (!isset($this->webDriver)) {
            $this->debug('WebDriver::debugWebDriverLogs method has been called when webDriver is not set');
            return;
        }
        try {
            // Dump out latest Selenium logs
            $logs = $this->webDriver->manage()->getAvailableLogTypes();
            foreach ($logs as $logType) {
                $logEntries = array_slice(
                    $this->webDriver->manage()->getLog($logType),
                    -$this->config['debug_log_entries']
                );

                if (empty($logEntries)) {
                    $this->debugSection("Selenium {$logType} Logs", " EMPTY ");
                    continue;
                }
                $this->debugSection("Selenium {$logType} Logs", "\n" . $this->formatLogEntries($logEntries));

                if ($logType === 'browser' && $this->config['log_js_errors']
                    && ($test instanceof ScenarioDriven)
                ) {
                    $this->logJSErrors($test, $logEntries);
                }
            }
        } catch (\Exception $e) {
            $this->debug('Unable to retrieve Selenium logs : ' . $e->getMessage());
        }
    }
96913
public function addError(Test $test, \Throwable $exception, float $time): void
    {
        $this->writeCase(
            self::STATUS_ERROR,
            $time,
            $this->getStackTrace($exception),
            TestFailure::exceptionToString($exception),
            $test
        );

        $this->currentTestPass = false;
    }
793699
public function addSkipped(Test $test)
    {
        $this->output->updateTable($test->pos->x, $test->pos->y, Graphite::MAGENTA);
        $this->skipped[] = $test;
    }
153784
public function addError(Test $test, \Throwable $t, float $time): void
    {
        $this->doAddFault($test, $t, $time, 'error');
        $this->testSuiteErrors[$this->testSuiteLevel]++;
    }
239999
public function _failed(TestInterface $test, $fail)
    {
        if (isset($this->container) && $this->container->has(ErrorHandlerInterface::class)) {
            $error = $this->container->get(ErrorHandlerInterface::class)->getError();
            
            if ($error) {
                $this->debug((string)$error);
            }
        }

        
        parent::_failed($test, $fail);
    }
1293873
public final function setFail(\Throwable $fail): void
    {
        if ($this->failOption) {
            if ($this->failOption == 'log') {
                $logger = clone $this->service->getApp()->getLogger();
                $logger->setDirectory($this->failLogDirectory);
                $logger->logFail($fail);
            } elseif ($this->failOption == 'throw') {
                throw $fail;
            }
        }
        $this->fail = $fail;
    }
847883
protected function failIfContainerNotFound(ServiceException $exception, $action, $containerName)
    {
        $errorCode = $this->getErrorCodeFromServiceException($exception);

        if ($errorCode === self::ERROR_CONTAINER_NOT_FOUND) {
            throw new \RuntimeException(sprintf(
                'Failed to %s: container "%s" not found.',
                $action,
                $containerName
            ), $exception->getCode());
        }
    }
895883
def spin_assert(self, assertion, failure_message='Failed Assertion', timeout=None):
        
        timeout = self.timeout if timeout is None else timeout
        time_spent = 0
        while time_spent < timeout:
            try:
                assert assertion() is True
                return True
            except AssertionError:
                pass
            sleep(self.step)
            time_spent += 1
        raise WebDriverAssertionException.WebDriverAssertionException(self.driver_wrapper, failure_message)
54157
public function run(TestResult $result)
    {
        $this->eventEmitter->emit('suite.start', [$this]);
        $this->eventEmitter->on('suite.halt', [$this, 'halt']);

        foreach ($this->getTestsToRun() as $test) {
            if ($this->halted) {
                break;
            }

            $this->runTest($test, $result);
        }

        $this->eventEmitter->emit('suite.end', [$this]);
    }
1347603
public function addPass(Test $test)
    {
        $this->output->updateTable($test->pos->x, $test->pos->y, Graphite::GREEN);
        $this->passed[] = $test;
    }
957821
private void failWithMessage(String errorMessage) {
      AssertionError assertionError = Failures.instance().failureIfErrorMessageIsOverridden(info);
      if (assertionError == null) {
        // error message was not overridden, build it.
        String description = MessageFormatter.instance().format(info.description(), info.representation(), "");
        assertionError = new AssertionError(description + errorMessage);
      }
      Failures.instance().removeAssertJRelatedElementsFromStackTraceIfNeeded(assertionError);
      throw assertionError;
    }