priotas/behat-slack-extension

This package is abandoned and no longer maintained. No replacement package was suggested.

A behat extension for sending files from behat to slack

Installs: 4 888

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:behat-extension

1.0 2017-04-25 08:08 UTC

This package is not auto-updated.

Last update: 2020-04-28 18:46:59 UTC


README

Build Status

Installation

composer require --dev priotas/behat-slack-extension

Configuration

behat.yml

profile_name:
    extensions:
        Priotas\Behat\SlackExtension:
            slackToken: "xoxb-0000000000-xxxxxxxxxxxxxxxxxxxxxxxx"
            slackChannel: "XXXXXXXXX"

Environment Variable

export BEHAT_PARAMS='{"extensions" : {"Priotas\\Behat\\SlackExtension" : {"slackToken" : "xoxb-0000000000-xxxxxxxxxxxxxxxxxxxxxxxx", "slackChannel": "XXXXXXXXX"}}}'

Usage

/**
 * @AfterStep
 */
public function takeScreenshotAfterFailedStep(Behat\Behat\Hook\Scope\AfterStepScope $scope)
{
    /** Behat\Behat\Tester\Result\StepResult $result */
    $result = $scope->getTestResult();
    if (!$result->isPassed()) {

        $driver = $this->getSession()->getDriver();
        if ($driver instanceof \Behat\Mink\Driver\Selenium2Driver) {
            $driver->resizeWindow(1024, 768);

            $featureName = basename($scope->getFeature()->getFile(), '.feature');
            $stepText = $featureName . '.' . $this->scenarioName . '.' . $scope->getStep()->getText();
            $fileTitle = 'behat_screenshot_' . preg_replace("#[^a-zA-Z0-9\._-]#", '', $stepText);
            $fileName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileTitle . '.png';
            $screenshot = $driver->getScreenshot();
            file_put_contents($fileName, $screenshot);

            print "Screenshot for '{$stepText}' placed in {$fileName}\n";

            if (isset($this->slackChannel)) {
                print "Uploading Screenshot to Slack...\n";
                $this->slackChannel->upload($fileName, $fileTitle, $stepText);
            }
        }
    }
}