Problem/Motivation

When I write FunctionalJavascript tests using the JavascriptTestBase, I often find myself writing the same code over and over again to save the headless browser's HTML at an arbitrary point and debug it after a test fails. It would be helpful is this was an actual method in JavascriptTestBase so that users could easily debug their tests.

Proposed resolution

Add a debug method to JavascriptTestBase which saves the browser's current (as opposed to the original HTML response from drupalGet) HTML to a file.

Remaining tasks

Review.

User interface changes

None.

API changes

A new protected method is added to JavascriptTestBase.

Data model changes

None.

Comments

samuel.mortenson created an issue. See original summary.

samuel.mortenson’s picture

Issue tags: +JavaScript, +JavaScriptTest
dawehner’s picture

+++ b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php
@@ -109,4 +109,15 @@ public function assertSession($name = NULL) {
 
+  /**
+   * Saves the current HTML from our headless browser.
+   *
+   * @param string $filename
+   *   The file name of the resulting HTML file.
+   */
+  protected function saveCurrentHTML($filename) {
+    $html = $this->getSession()->getDriver()->getHtml('/html');
+    file_put_contents($filename, $html);
+  }
+
 }

Actually ... this is useful even in BrowserTestBase itself, but then I guess we could have different tests for this test helper :) One for the classical browser test, and one for the javascript one, as you have already.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.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.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.