/** * @AfterStep */ public function debugStepsAfter(AfterStepScope $scope) { // Tests tagged with @debugEach will perform each step and wait for [ENTER] to proceed. if ($this->scenario->hasTag('debugEach')) { $env = $scope->getEnvironment(); $drupalContext = $env->getContext('Drupal\\DrupalExtension\\Context\\DrupalContext'); $minkContext = $env->getContext('Drupal\\DrupalExtension\\Context\\MinkContext'); // Print the current URL. try { $minkContext->printCurrentUrl(); } catch (Behat\Mink\Exception\DriverException $e) { print "No Url"; } $drupalContext->iPutABreakpoint(); } }
/** Write a html dump after a failing step. * * @AfterStep */ public function dumpPageAfterFailedStep(AfterStepScope $event) { if ($event->getTestResult() instanceof ExecutedStepResult && !$event->getTestResult()->isPassed()) { if (!is_dir($this->htmlDumpPath)) { mkdir($this->htmlDumpPath, 0755, true); } $minkContext = $event->getEnvironment()->getContext($this->contextName); if (!$minkContext) { return; } $filePath = $this->htmlDumpPath . '/' . date('Y-m-d-H-i-s') . '_' . uniqid() . '.html'; file_put_contents($filePath, "<!-- HTML dump from behat\nDate: " . date('Y-m-d H:i:s') . "\nUrl: " . $minkContext->getSession()->getCurrentUrl() . "\n-->\n" . $minkContext->getSession()->getPage()->getContent()); $message = "\nHTML saved to: file://" . $filePath; $exception = $event->getTestResult()->getException(); $refObj = new ReflectionObject($exception); $refObjProp = $refObj->getProperty('message'); $refObjProp->setAccessible(true); $refObjProp->setValue($exception, $exception->getMessage() . $message); } }