How to get a certain header on FunctionalJavascript tests Since Drupal 9 is around the corner I'm working on puhsing some contrib modules (and a couple of my own) to be Drupal 9 ready. That involves on updating my tests to use replace deprecated code. Currently I'm working on this issue from Devel module, which replaces \Drupal\FunctionalJavascriptTests\JavascriptTestBase with \Drupal\FunctionalJavascriptTests\WebDriverTestBase but since this I cannot get headers during FunctionalJavascript.

My question what is the proper way to get them. I've checked tests in core but I just can't figure it out.

The code I'm working on is like so:

/**
 * Wait until the toolbar is present on page.
 */
protected function waitForToolbar() {
  $session = $this-&gt;getSession();
  $token = $this-&gt;getToken();
  $page = $session-&gt;getPage();

  $toolbar = $page-&gt;findById('webprofiler' . $token);
  $this-&gt;assertTrue($toolbar-&gt;hasClass('sf-toolbar'), 'Toolbar loader is present in page');

  $session-&gt;wait(1000, 'null !== document.getElementById(\'sfToolbarMainContent-' . $token . '\')');

  return $token;
}

/**
 * Return the Webprofiler token.
 *
 * @return null|string
 *   The page token
 */
 protected function getToken() {
   $token = $this-&gt;getSession()-&gt;getResponseHeader('X-Debug-Token');

   if (NULL === $token) {
     throw new PHPUnit_Framework_AssertionFailedError();
   }

   return $token;
 }


As shown the header is required in order to get an element that is generated using Javascript. Perhaps theres another workaround than fetching the header, but not sure how right now.

Thanks in advance.
I was getting all wrong. This is the key, copied from https://www.drupal.org/node/2857562


  All assertions within these tests must be done by checking the UI. Assertions that don't relate to UI should be added to other types of tests, a BrowserTestBase for example.


I should break this test in two one Functional to check proper header setting and the other pure FunctionalJavascript to check the element (whereas the token is set or not) is present on the page. Also does not make sense in this specific case to have two Webprofiler bars present on the page so a simple document.querySelector('[id^="sfToolbarMainContent-"]') should do the trick.