protected function MinisiteTestBase::screenshot in Mini site 8
Captures and saves a screenshot.
The result of calling this function will be triggering fail in order to output the URL to the generated screenshot. This is due to result printer not allowing print output from within the test.
@todo: Find a better way to add output to the result printer.
File
- tests/
src/ Functional/ MinisiteTestBase.php, line 114
Class
- MinisiteTestBase
- Provides methods specifically for testing Minisite module's field handling.
Namespace
Drupal\Tests\minisite\FunctionalCode
protected function screenshot() {
$base_directory = '/sites/simpletest/browser_output';
$directory = DRUPAL_ROOT . $base_directory;
// Ensure directory exists.
if (!is_dir($directory)) {
mkdir($directory, 0777, TRUE);
}
$current_url = substr(Html::cleanCssIdentifier($this
->getSession()
->getCurrentUrl()), 100);
$filename = uniqid() . '_' . $current_url . '.html';
$full_filename = file_create_filename($filename, $directory);
$screenshot = $this
->getSession()
->getPage()
->getContent();
file_put_contents($full_filename, $screenshot);
$url = $GLOBALS['base_url'] . $base_directory . '/' . $filename;
$this
->fail($url);
}