During functional JavaScript testing one can create and login a user by using the following code:

$this->testUser = $this->drupalCreateUser(['permission']);

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.

  '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?

  • the only idea I have is that there is a fatal error/exception on that page. why is hard to debug, you could try to print the page content which should be visible in the output. Could be the php version, an extension or something like that. One common difference to local is that the testbot runs tests in a subdirectory – Berdir Apr 23 '18 at 18:35
  • Thanks @Berdir, I started thinking it might be because of the web driver engine replacing PhantomJS, but from what I could find I was not really sure if that was implemented already and if it could indeed result in different results. – Neograph734 Apr 23 '18 at 21:13

After reading through the Jenkins results for the nth time, it finally occurred to me that during Drupal core (and other contrib) tests all JavaScript tests always run separately from the other tests. All my tests however were in the same list.

This happened because all test classes started originally as functional tests, but as I went ahead some of them were changed into functional javascript tests. Class extending was changed into JavascriptTestBase and the tests were working perfectly fine. At least, when running individually. Running multiple tests at the same time made them somehow interfere with one another.

The problem was that I had never changed the namespace from Functional into FunctionalJavascript. The Drupal testrunner makes sure that all FunctionalJavascript tests are ran one by one, but performs other tests in parallel.

After changing the namespace, the tests were listed separate from the rest, ran after each other and finally showed up green on Drupal.org

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.