Commit 4c4f8020 authored by mstrelan's avatar mstrelan Committed by Moshe Weitzman
Browse files

Add option to specify DTT_HTML_OUTPUT_DIRECTORY

parent d3326119
Pipeline #287268950 failed with stage
in 3 minutes and 38 seconds
......@@ -46,7 +46,7 @@ vendor/bin/phpunit --group CustomTestGroup
## Debugging tests
- All HTML requests can be logged. To do so, add `BROWSERTEST_OUTPUT_DIRECTORY=/tmp` and `--printer '\\Drupal\\Tests\\Listeners\\HtmlOutputPrinter'` to the `phpunit` call. To disable deprecation notices, include `SYMFONY_DEPRECATIONS_HELPER=disabled`. Alternatively, you can specify these in your `phpunit.xml` ([example phpunit.xml](docs/phpunit.xml)).
- To write the current HTML of the page to a file in the browser_output directory, use `$this->capturePageContent()`.
- To write the current HTML of the page to a file, use `$this->capturePageContent()`. If using HtmlOutputPrinter this will be saved to the browser_output directory. Alternatively you can specify `DTT_HTML_OUTPUT_DIRECTORY=/path/to/output_directory` which is required when using a different printer, such as Teamcity, which is enforced by PHPStorm.
- To take a screenshot of the current page under ExistingSiteSelenium2DriverTest or ExistingSiteWebDriverTest, use `\weitzman\DrupalTestTraits\ScreenShotTrait::captureScreenshot`.
## Available traits
......
......@@ -26,6 +26,11 @@
<!--<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>-->
<!-- Specify the default directory screenshots should be placed. -->
<!--<env name="DTT_SCREENSHOT_REPORT_DIRECTORY" value=""/>-->
<!-- Specify the default directory page captures should be placed.
When using the \Drupal\Tests\Listeners\HtmlOutputPrinter printerClass this will default to
/sites/simpletest/browser_output. If using another printer such as teamcity this must be defined.
-->
<!--<env name="DTT_HTML_OUTPUT_DIRECTORY" value=""/>-->
</php>
<testsuites>
......
......@@ -39,6 +39,13 @@ trait DrupalTrait
*/
protected $kernel;
/**
* Directory name for HTML output logging.
*
* @var string
*/
protected $outputDirectory;
/**
* Bootstrap Drupal. Call this from your setUp() method.
*/
......@@ -145,7 +152,7 @@ trait DrupalTrait
protected function getOutputFileName($directory = '')
{
if (empty($directory)) {
$directory = $this->htmlOutputDirectory;
$directory = $this->getOutputDirectory();
}
// Ensure directory exists.
if (!is_dir($directory)) {
......@@ -155,6 +162,26 @@ trait DrupalTrait
return $directory . DIRECTORY_SEPARATOR . uniqid() . '_' . $current_url;
}
/**
* Get directory for writing browser output files for debugging.
*
* If the DTT_HTML_OUTPUT_DIRECTORY environment variable is specified we will
* use that. Otherwise when using \Drupal\Tests\Listeners\HtmlOutputPrinter
* the htmlOutputDirectory property should already be set and we can use it.
*
* @return string
* An absolute directory path.
*/
protected function getOutputDirectory()
{
if ($directory = getenv('DTT_HTML_OUTPUT_DIRECTORY')) {
$this->outputDirectory = $directory;
} elseif (isset($this->htmlOutputDirectory)) {
$this->outputDirectory = $this->htmlOutputDirectory;
}
return $this->outputDirectory;
}
/**
* Captures and saves page content.
*
......
Supports Markdown
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