Commit 90380c77 authored by Lisa Seeto's avatar Lisa Seeto Committed by Gerrit Code Review
Browse files

Merge "Bug 1902318: Behat screenshot changes"

parents 2b9eeb60 ddbe0e60
......@@ -2416,4 +2416,19 @@ JS;
throw new ExpectationException('The display button with title ' . $textliteral . ' in row ' . $rowname . ' was found', $this->getSession());
}
}
/**
* This works for Selenium and other real browsers that support screenshots.
*
* @Then show me a screenshot named :shot
*/
public function show_me_a_screenshot($shot) {
global $CFG;
$image_data = $this->getSession()->getDriver()->getScreenshot();
$file_and_path = $CFG->behat_dataroot . '/behat/html_results/screenshots/custom/' . $shot . '.png';
if (!file_exists($CFG->behat_dataroot . '/behat/html_results/screenshots/custom/')) {
mkdir($CFG->behat_dataroot . '/behat/html_results/screenshots/custom/', $CFG->directorypermissions, true);
}
file_put_contents($file_and_path, $image_data);
}
}
......@@ -298,10 +298,12 @@ class BehatHooks extends BehatBase {
if (!$scope->getTestResult()->isPassed()) {
// create filename string
$featureFolder = preg_replace('/\W/', '', $scope->getFeature()->getTitle());
preg_match('|test/behat/features/(.*)\.feature|', $scope->getFeature()->getFile(), $matches);
$featureFolder = preg_replace('/\W/', '', preg_replace('/\//', '__', $matches[1]));
$scenarioName = $this->currentScenario->getTitle();
$fileName = preg_replace('/\W/', '', $scenarioName) . '.png';
$scenarioLine = $scope->getStep()->getLine();
$fileName = preg_replace('/\W/', '', $scope->getStep()->getText()) . '_line' . $scenarioLine . '.png';
// create screenshots directory if it doesn't exist
if (!file_exists($CFG->behat_dataroot . '/behat/html_results/screenshots/' . $featureFolder)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment