Problem/Motivation

When writing JavascriptTestBase tests I find myself adding code to tests to dump the HTML output at a particular point so I can see what is exactly going on. We dump the output automatically for drupalGet() and submitForm(). It'd be helpful if we also dumped the output if we click anywhere.

Proposed resolution

Add similar code for the click method as we have in submitForm and drupalGet. Also adjust BrowserTestBase::htmlOutput() to be simple to call and just dump the current page.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

CommentFileSizeAuthor
#2 2948276-3.patch2.38 KBalexpott

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new2.38 KB
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

It is a bit sad that we cannot trigger that on a more lower level using some events. Behat for example has these events, but I guess it not on the mink level.

Sorry for my dreaming of a perfect world.

alexpott’s picture

Well it's because Goutte let's us set the http client...

      // Turn off curl timeout. Having a timeout is not a problem in a normal
      // test running, but it is a problem when debugging. Also, disable SSL
      // peer verification so that testing under HTTPS always works.
      /** @var \GuzzleHttp\Client $client */
      $client = $this->container->get('http_client_factory')->fromOptions([
        'timeout' => NULL,
        'verify' => FALSE,
      ]);

      // Inject a Guzzle middleware to generate debug output for every request
      // performed in the test.
      $handler_stack = $client->getConfig('handler');
      $handler_stack->push($this->getResponseLogHandler());

      $driver->getClient()->setClient($client);

And obviously testing with headless browsers don't have the need for a client to make the requests. I guess the perfect world would have some event system be a part of \Behat\Mink\Driver\CoreDriver.

lendude’s picture

debugability++

One question:

  1. +++ b/core/tests/Drupal/Tests/BrowserTestBase.php
    @@ -1054,7 +1054,20 @@ protected function drupalUserIsLoggedIn(AccountInterface $account) {
    +    // Log only for JavascriptTestBase tests because for Goutte we log with
    +    // ::getResponseLogHandler.
    

    If we only do this for JavascriptTestBase, what's the reason for not putting it in JavascriptTestBase but in BrowserTestBase?

alexpott’s picture

@Lendude well because that's where the other ones are for submitForm and drupalGet

alexpott’s picture

Also you can swap the goutte for webdriver etc... for BTBs

lendude’s picture

@alexpott yeah that makes sense. Changing the comment to something like :

// Log only when not using GoutteDriver (like JavascriptTestBase) because
// for GoutteDriver we log with ::getResponseLogHandler.

would make that a little clearer, but then we should also change that for submitForm and drupalGet.

But this is consistent with what's in core, so RTBC +1

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed ea55e39 and pushed to 8.6.x. Thanks!

  • catch committed ea55e39 on 8.6.x
    Issue #2948276 by alexpott: Improve debugability of JavascriptTestBase...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jibran’s picture

This is a test only change and no disruptive. Can we please backport this to 8.5.x?