priotas / behat-slack-extension
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
Requires
- php: ^7.0
- behat/behat: ~3.0,>=3.0.4
Requires (Dev)
- phpunit/phpunit: ^6.1
This package is not auto-updated.
Last update: 2020-04-28 18:46:59 UTC
README
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); } } } }