-
-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Milestone
Description
As a means to share step workflows with testers, I knocked together this extremely crude addition to ScreenshotContext this morning. It captures a screenshot of each step of a tagged scenario (probably erring on the side of too many screenshots, really), and means a tester can see the output frame by frame.
From here it would not be far to output a video artefact.
use FeatureTrait, ScenarioTrait;
/**
* Record every step with a screenshot, if tagged with 'screenshot-vcr'.
*
* @AfterStep
*/
public function recordStepScreenshots($event)
{
$tagName = 'screenshot-vcr';
/** @var \Behat\Behat\Hook\Scope\BeforeStepScope $event */
if (!$this->getScenario()->hasTag($tagName) && !$this->getFeature()->hasTag($tagName)) {
return;
}
$driver = $this->getSession()->getDriver();
$stepText = $event->getStep()->getText();
$stepLine = $event->getFeature()->getFile() . '-' . $event->getStep()->getLine();
$fileName = $this->makeFileName('html', preg_replace('/[^a-zA-Z0-9-]+/', '-', $stepLine . '-' . $stepText));
try {
$data = $driver->getContent();
} catch (DriverException $exception) {
// Do not do anything if the driver does not have any content - most
// likely the page has not been loaded yet.
return;
}
$this->saveScreenshotData($fileName, $data);
try {
$data = $driver->getScreenshot();
// Preserve filename, but change the extension - this is to group
// content and screenshot files together by name.
$fileName = substr($fileName, 0, -1 * strlen('html')).'png';
$this->saveScreenshotData($fileName, $data);
} catch (UnsupportedDriverActionException $exception) {
// Nothing to do here - drivers without support for screenshots
// simply do not have them created.
}
}Any thoughts on the approach @AlexSkrypnyk ? I'd love to contribute this in a way that makes sense alongside the rest of the project, or perhaps you know of existing solutions I'm not aware of.
Happy to turn into a PR if you want, but I don't feel it's at that level of quality yet 😁
(I mistakenly opened this at drevops/behat-steps#69 initially 🙄)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels