During functional JavaScript testing one can create and login a user by using the following code:
$this->testUser = $this->drupalCreateUser(['permission']);
$this->drupalLogin($this->testUser);
This works fine when testing locally with PhantomJS. However after uploading this code to drupal.org it keeps failing randomly (sometimes 1 test, sometimes 2) with the following error:
User dOGIV5Iu successfully logged in.
Failed asserting that false is true.
This appears to be coming from the assertion in BrowserTestBase::drupalLogin, which should normally check that the user is logged in correctly.
$this->drupalGet('user/login');
$this->submitForm([
'name' => $account->getUsername(),
'pass' => $account->passRaw,
], t('Log in'));
// @see BrowserTestBase::drupalUserIsLoggedIn()
$account->sessionId = $this->getSession()->getCookie($this->getSessionName());
$this->assertTrue($this->drupalUserIsLoggedIn($account), new FormattableMarkup('User %name successfully logged in.', ['%name' => $account->getAccountName()]));
How come that a test function does work locally, but not on Drupal.org? Even stranger is that this function is used throughout multiple core tests without issues. And why is this assertion failing randomly?