Drupal Functional tests and Functional Javascript tests automatically produce HTML output every time the test makes a page request.
This in my test code:
$this->drupalGet('some/path');
gets me this once my test has run:
HTML output was generated
http://my-host/sites/simpletest/browser_output/Drupal_Tests_yadayada-91-80728919.html
This is great! You can navigate between the pages, see exactly what the test code saw, inspect the HTML, and so on.
However, there's no such output when a Functional Javascript test causes an AJAX request.
It's fairly simple to create the debug output manually in the test code, and it will be added to the list of output HTML pages:
// Get the Mink page element.
$page = $this->getSession()->getPage();
// Change a form element that will react with AJAX, and wait for the request to
// complete.
$page->selectFieldOption('my-field', '1');
$this->assertSession()->assertWaitOnAjaxRequest();
// Output the new HTML.
$this->htmlOutput($page->getHtml());
It would be really good though if this happened automatically!
AFAIK, we intercept the normal page requests to save the HTML here:
/**
* Provides a Guzzle middleware handler to log every response received.
*
* @return callable
* The callable handler that will do the logging.
*/
protected function getResponseLogHandler() {
so we'd need a totally different way to hook into Mink.
Comments
Comment #2
joachim CreditAttribution: joachim commentedThe title of this issue seems to suggest it fixed this a long time ago, but if it did, it doesn't work any more: #2763401: PHPunit browser tests should log all Mink requests
Comment #3
jibranThis makes sense to me and thank you for creating the issue. This seems like a task to me but not a major one. Feel free to disagree.
Comment #4
joachim CreditAttribution: joachim commentedBeen poking around in Mink and its dependencies to see where we could hook in...
instaclick/php-webdriver is the package that appears to be doing the actual talking to the browser. That has a swappable service for its curl handling.
So in a test class's setUp(), we can do this:
and then provide this class:
and that dumps a TON of requests. That's far too many (my test only made a couple of AJAX requests), so I don't know how we'd filter that down to the ones we care about.