mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 04:30:15 +01:00
Merge branch 'MDL-54180_master' of https://github.com/marxjohnson/moodle
This commit is contained in:
commit
8a4f4f576e
@ -429,8 +429,19 @@ class behat_hooks extends behat_base {
|
||||
return false;
|
||||
}
|
||||
|
||||
list ($dir, $filename) = $this->get_faildump_filename($scope, 'png');
|
||||
$this->saveScreenshot($filename, $dir);
|
||||
// Some drivers (e.g. chromedriver) may throw an exception while trying to take a screenshot. If this isn't handled,
|
||||
// the behat run dies. We don't want to lose the information about the failure that triggered the screenshot,
|
||||
// so let's log the exception message to a file (to explain why there's no screenshot) and allow the run to continue,
|
||||
// handling the failure as normal.
|
||||
try {
|
||||
list ($dir, $filename) = $this->get_faildump_filename($scope, 'png');
|
||||
$this->saveScreenshot($filename, $dir);
|
||||
} catch (Exception $e) {
|
||||
// Catching all exceptions as we don't know what the driver might throw.
|
||||
list ($dir, $filename) = $this->get_faildump_filename($scope, 'txt');
|
||||
$message = "Could not save screenshot due to an error\n" . $e->getMessage();
|
||||
file_put_contents($dir . DIRECTORY_SEPARATOR . $filename, $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -442,9 +453,14 @@ class behat_hooks extends behat_base {
|
||||
protected function take_contentdump(AfterStepScope $scope) {
|
||||
list ($dir, $filename) = $this->get_faildump_filename($scope, 'html');
|
||||
|
||||
$fh = fopen($dir . DIRECTORY_SEPARATOR . $filename, 'w');
|
||||
fwrite($fh, $this->getSession()->getPage()->getContent());
|
||||
fclose($fh);
|
||||
try {
|
||||
// Driver may throw an exception during getContent(), so do it first to avoid getting an empty file.
|
||||
$content = $this->getSession()->getPage()->getContent();
|
||||
} catch (Exception $e) {
|
||||
// Catching all exceptions as we don't know what the driver might throw.
|
||||
$content = "Could not save contentdump due to an error\n" . $e->getMessage();
|
||||
}
|
||||
file_put_contents($dir . DIRECTORY_SEPARATOR . $filename, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user