Created
July 2, 2016 04:42
-
-
Save Sam152/fa9a4d834a1b6c3fdf173b72ce9c0a4a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\local_testing; | |
trait LocalTestingTrait { | |
/** | |
* Screenshot. | |
*/ | |
public function takeScreenshot() { | |
$this->getSession()->getDriver()->executeScript("document.body.style.backgroundColor = '#FFF';"); | |
$html_output_filename = $this->htmlOutputClassName . '-' . $this->htmlOutputCounter . '-' . $this->htmlOutputTestId . '.jpg'; | |
file_put_contents($this->htmlOutputDirectory . '/' . $html_output_filename, $this->getSession()->getDriver()->getScreenshot()); | |
// $this->getSession()->wait(200); | |
file_put_contents($this->htmlOutputCounterStorage, $this->htmlOutputCounter++); | |
file_put_contents($this->htmlOutputFile, '<a href="' . file_create_url('sites/simpletest/browser_output/' . $html_output_filename) . '">' . file_create_url('sites/simpletest/browser_output/' . $html_output_filename) . '</a>' . "<br/>" . file_get_contents($this->htmlOutputFile)); | |
} | |
/** | |
* Output. | |
*/ | |
protected function htmlOutput($message) { | |
if (!$this->htmlOutputEnabled) { | |
return; | |
} | |
$message = '<hr />ID #' . $this->htmlOutputCounter . ' (<a href="' . $this->htmlOutputClassName . '-' . ($this->htmlOutputCounter - 1) . '-' . $this->htmlOutputTestId . '.html">Previous</a> | <a href="' . $this->htmlOutputClassName . '-' . ($this->htmlOutputCounter + 1) . '-' . $this->htmlOutputTestId . '.html">Next</a>)<hr />' . $message; | |
$html_output_filename = $this->htmlOutputClassName . '-' . $this->htmlOutputCounter . '-' . $this->htmlOutputTestId . '.html'; | |
file_put_contents($this->htmlOutputDirectory . '/' . $html_output_filename, $message); | |
file_put_contents($this->htmlOutputCounterStorage, $this->htmlOutputCounter++); | |
file_put_contents($this->htmlOutputFile, '<a href="' . file_create_url('sites/simpletest/browser_output/' . $html_output_filename) . '">' . file_create_url('sites/simpletest/browser_output/' . $html_output_filename) . '</a>' . "<br/>" . file_get_contents($this->htmlOutputFile)); | |
} | |
/** | |
* Newlines in the output. | |
*/ | |
protected function tearDown() { | |
file_put_contents($this->htmlOutputFile, "<br/><br/>" . file_get_contents($this->htmlOutputFile)); | |
parent::tearDown(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment