Drupal

What I Learned Today: Drupal Behat Breakpoints

Today I learned that the Drupal Behat Extension provides an extremely useful step definition for debugging. Breakpoints!


Today I learned that the Drupal Behat Extension provides an extremely useful step definition for debugging. Breakpoints!

Then I break

It allows you to stop at a certain point in the test scenario so you can take a closer look at what is going on in the browser. When you are ready to move on, you just hit enter in your terminal window.

We were already saving snapshots of failed steps, but when this isn't enough; throw in a breakpoint!

/**
 * Take screenshot when step fails.
 * Works only with Selenium2Driver.
 *
 * @AfterStep
 */
public function takeScreenshotAfterFailedStep($event)
{
    if (4 === $event->getResult()) {
        $driver = $this->getSession()->getDriver();
        if (!($driver instanceof Selenium2Driver)) {
            //throw new UnsupportedDriverActionException('Taking screenshots is not supported by %s, use Selenium2Driver instead.', $driver);
            return;
        }
        $step = $event->getStep();
        $stepLine = $step->getLine();
        $fileName = '/tmp/stepAtLine' . $stepLine . '.png';
        $screenshot = $driver->getWebDriverSession()->screenshot();
        file_put_contents($fileName, base64_decode($screenshot));
        echo "Saved Screenshot To $fileName \n";
        $fileName = '/tmp/stepAtLine' . $stepLine .'.html';
        $source = $driver->getWebDriverSession()->source();
        file_put_contents($fileName, $source);
        echo "Saved Source To $fileName\n";
    }
}

Similar posts

Get notified on new marketing insights

Be the first to know about new B2B SaaS Marketing insights to build or refine your marketing function with the tools and knowledge of today’s industry.