How to change client session variables during a functional browser test? I have a session variable, that once set changes block output of the system branding block. Normally this variable is intercepted from the query string by an inbound path processor, however that is a different test. In this test I just want to make sure the output is as expected.

So I set up my test as follows:

class ConfigOverrideCacheTest extends MyLabelTestBase {

  protected function setUp() {
    parent::setUp();

    $this-&gt;tokenOwner= $this-&gt;drupalCreateUser(['my permission']);
    $this-&gt;drupalLogin($this-&gt;tokenOwner);
  }

  public function testNotoken() {
    $this-&gt;drupalGet('&lt;front&gt;');
    // Check site name is Drupal.
    $this-&gt;assertSession()-&gt;elementTextContains('css', '.block-system-branding-block', 'Drupal');
  }

  public function testToken() {
    // Set session variable.
    \Drupal::service('session')-&gt;set('my_session_key', 'value');

    $this-&gt;drupalGet('&lt;front&gt;');
    // Check site name is NOT Drupal.
    $this-&gt;assertSession()-&gt;elementTextNotContains('css', '.block-system-branding-block', 'Drupal');
  }

}


This second test keeps failing, and the output is the same as in the first test. Which I suspect to be because it is set in the testrunner session, rather than the actual testing session. 

How so set (or synchronize) session variables from the testrunner to the site that gets tested?
I am not sure if the storage you use to save the my_session_key attribute is shared between the testrunner and the site that gets tested, and that could explain why the test fails.

Why not test exactly the case of the inbound path processing, e.g.:

public function testToken() {
  $options = [
    'query' =&gt; [
      'param' =&gt; 'value',
    ]
  ];
  $this-&gt;drupalGet('&lt;front&gt;', $options);
  // Check site name is NOT Drupal.
  $this-&gt;assertSession()-&gt;elementTextNotContains('css', '.block-system-branding-block', 'Drupal');
}


Good luck in any case!