Getting Behat to Beep When it’s Finished

Some times when you’ve got a big Behat test suite to run you want to go off an do other things. Which means you have to constantly check back on your terminal to see if its done. Wouldn’t it be better if the terminal beeped when it was done? Well using Behat’s hook its as easy as:

/**
 * @AfterSuite
 */
public static function beep(Behat\Behat\Event\SuiteEvent $event) {
    echo "\007";
}

If you are on a mac and are feeling particularly fancy you can do:

/**
 * @AfterSuite
 */
public static function beep(Behat\Behat\Event\SuiteEvent $event) {
    $params = $event->getContextParameters();
    $result = $event->getLogger()->getFeaturesStatuses();
    if (isset($params['announce_completion']) && $params['announce_completion']) {
        if ($result['failed']) {
            exec("say behat failed");
        } else {
            exec("say behat succeeded");
        }
    }
}

To enable the audio prompt go into behat.yml and add:

default:
  context:
    parameters:
      announce_completion: true

This allow you to enable on a profile by profile basis.