Problem/Motivation

A simple grep shows sometimes we use browser output directory as absolute path and sometimes relative. We should consolidate how we want to use it.

grep -inr browser_output core/
core/tests/Drupal/Tests/Listeners/HtmlOutputPrinterTrait.php:37:        $this->browserOutputFile = tempnam($html_output_directory, 'browser_output_');
core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php:121:    $uri = $GLOBALS['base_url'] . '/sites/simpletest/browser_output/' . $html_output_filename;
core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php:132:    $browser_output_file = getenv('BROWSERTEST_OUTPUT_FILE');
core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php:133:    $this->htmlOutputEnabled = is_file($browser_output_file);
core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php:135:      $this->htmlOutputFile = $browser_output_file;
core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php:137:      $this->htmlOutputDirectory = DRUPAL_ROOT . '/sites/simpletest/browser_output';
core/phpunit.xml.dist:29:    <!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output -->

Also see https://gitlab.com/weitzman/drupal-test-traits/merge_requests/39

the html files are not going into the BROWSERTEST_OUTPUT_DIRECTORY. instead they are going into /sites/simpletest/browser_output regardless.

Proposed resolution

We can convert BROWSERTEST_OUTPUT_DIRECTORY to always be relative webroot and convert to absolute/url when needs be that would mean \Drupal\Tests\Listeners\HtmlOutputPrinterTrait::setUpHtmlOutput has to adapt.

Remaining tasks

  • Agree on the approach.
  • Create patch.
  • Commit it.
  • Rejoice.

User interface changes

None

API changes

None

Data model changes

None.

Issue fork drupal-2992069

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jibran created an issue. See original summary.

mile23’s picture

BROWSERTEST_OUTPUT_DIRECTORY is where BTB stores the HTML it gets from guzzle, before processing it to be browsable from sites/simpletest/browser_output/. It's supposed to be a temp directory which is cleaned up sometime after the test run.

The artifacts *always* live in sites/simpletest/browser_output/, regardless of what BROWSERTEST_OUTPUT_DIRECTORY says.

We do that because we use multisite for testing anyway, so the HTML artifacts can live there, too. That way your web server configuration will allow you to browse the artifacts, and all the paths to assets will work and you can see CSS and images.

Basically: BROWSERTEST_OUTPUT_DIRECTORY is poorly named. :-) It's really browsertest_temp_output_directory.

jibran’s picture

We do that because we use multisite for testing

How do we fix it for existing site testing?

mile23’s picture

It seems to me that if you're still using all the traits that BTB uses, you'll be using guzzle for requests, and that Drupal\Tests\BrowserHtmlDebugTrait could be modified to put the files somewhere else.

I'd guess you want to serve HTML with URLs to all your assets form the installed site. You don't want evidence of multisites at all.

HtmlOutputPrinter does this:

    if ($this->browserOutputFile) {
      putenv('BROWSERTEST_OUTPUT_FILE=' . $this->browserOutputFile);
    }

That's the signal to BrowserHtmlDebugTrait::initBrowserOutputFile() that it should put HTML somewhere.

Unfortunately, initBrowserOutputFile() has lines like this:

      $this->htmlOutputDirectory = DRUPAL_ROOT . '/sites/simpletest/browser_output';

So it's a hardcoded path.

The solution would be to reproduce or override BrowserHtmlDebugTrait in your project and have it store the HTML files in the place you want. It can still use HtmlOutputPrinter and BROWSERTEST_OUTPUT_DIRECTORY to get a temp storage location, but then it would put the HTML files in some public place.

You can see that BTB::getResponseLogHandler() calls $this->htmlOutput($html_output); as a guzzle middleware, which connects BTB to the trait. That's where the HTML logging happens, so ExistingSiteBase would have to set that up, much like BTB::initMink() does.

If this is an easy change to BrowserHtmlDebugTrait that would be easy to accommodate in core without too much complexity, that'd be great. But I'm thinking this solution lives in Drupal Test Traits.

pieterdc’s picture

This was a big WTF moment; realising BROWSERTEST_OUTPUT_DIRECTORY isn't as configurable as it seems to be from what you can read at phpunit.xml(.dist).

If found my way around it for our use case - GitLab CI artifacts - by copying the browser output from the Drupal directory to the GitLab CI directory. Much like what is illustrated here: https://forum.gitlab.com/t/gitlab-ci-artifacts-not-found/7588/2

Nevertheless, it would be very useful to

  1. Short term: explain the restrictions on this setting like https://gitlab.com/weitzman/drupal-test-traits/merge_requests/39 does.
  2. Longer term: actually make it more flexible to specify another folder.
chi’s picture

Status: Active » Needs review
StatusFileSize
new870 bytes

Quick fix.

chi’s picture

Another confusing thing here is that setting BROWSERTEST_OUTPUT_DIRECTORY may reset BROWSERTEST_OUTPUT_FILE variable.
https://github.com/drupal/drupal/blob/8.6.4/core/tests/Drupal/Tests/List...

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dave reid’s picture

Oh my gosh yes this is poorly named environment variable. I just ran into this assumption in our CI that this directory would contain the artifacts I want to store for review and it was always empty. Using /web/sites/simpletest/browser_output worked as expected, but you also need this variable set in order to store results, ugh.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new168 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

tstoeckler’s picture

Just hit this as well. Noticed that \Drupal\Tests\BrowserHtmlDebugTrait::htmlOutput() needs to be updated, as well.

immaculatexavier made their first commit to this issue’s fork.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

jibran’s picture

This needs a rebase.