If I run FunctionalJavascript tests when ChromeDriver is not running, the tests always pass. Instead they should fail with the message that ChromeDriver is not running.

Original report

The following test ought to fail in three separate ways, but it passes when I run this test.


namespace Drupal\Tests\my_module\FunctionalJavascript;

use Drupal\FunctionalJavascriptTests\WebDriverTestBase;

/**
 * Basic test.
 *
 * @group MyTest
 */
class MyTestBasicTest extends WebDriverTestBase {

  protected $defaultTheme = 'stark';

  /**
   * Basic test.
   */
  public function testPage() {
    $this->drupalGet('');
    $this->assertSession()->pageTextContains('Text that is not on the page.');

    non_existant_function();

    exit;
  }

}

This is the test output:

Status    Group      Filename          Line Function                            
--------------------------------------------------------------------------------
Pass      Other      MyTestBasicTest.p   19 Drupal\Tests\my_module\FunctionalJa

It finds the test method on line 19, but it doesn't run it. Does anyone know what the problem is?

CommentFileSizeAuthor
#7 3187577-7.patch1.17 KBlongwave

Comments

Liam Morland created an issue. See original summary.

longwave’s picture

What command line are you using to run the test?

liam morland’s picture

php run-tests.sh --verbose --color --non-html --sqlite /tmp/drupal/test.sqlite --module my_module --url <url>

liam morland’s picture

Category: Support request » Bug report

I have observed this problem in core tests as well. For example, in 9.2.x, I edited core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php by adding a call to a non-existent function to one of the test methods. That ought to make it fail. The following command still resulted in the tests passing:

php core/scripts/run-tests.sh --verbose --color --non-html --sqlite /tmp/drupal/test.sqlite --url <url> --class "Drupal\FunctionalJavascriptTests\TableDrag\TableDragTest"

If I edit TableDragTest.php so that it is invalid PHP, such as by removing a line-ending semi-colon, I get a PHP parse error.

liam morland’s picture

Title: WebDriverTestBase tests always pass » FunctionalJavascript tests should fail when ChromeDriver is not running
Issue summary: View changes

The immediate problem is that ChromeDriver is not running. If I run /usr/bin/chromedriver --port=4444 prior to running the run-tests.sh command above, then the tests fail as expected.

liam morland’s picture

If it can't connect to ChromeDriver, PHPUnit will skip the test (this can be seen by running vendor/bin/phpunit directly). run-tests.sh treats this as a pass.

longwave’s picture

Status: Active » Needs review
StatusFileSize
new1.17 KB

So it feels like we should hard fail instead of skip if an error occurs during Mink setup.

Running this locally without a Chromedriver I get:

PHPUnit 8.5.13 by Sebastian Bergmann and contributors.

Testing Drupal\FunctionalJavascriptTests\TableDrag\TableDragTest
FFFFF                                                               5 / 5 (100%)

Time: 14.31 seconds, Memory: 4.00 MB

There were 5 failures:

1) Drupal\FunctionalJavascriptTests\TableDrag\TableDragTest::testRowWeightSwitch
The test wasn't able to connect to your webdriver instance. For more information read core/tests/README.md.

The original message while starting Mink: Could not open connection: Curl error thrown for http POST to http://localhost:4444/session with params: {"desiredCapabilities":{"browserName":"chrome","name":"Behat Test"}}

Failed to connect to localhost port 4444: Connection refused
liam morland’s picture

The patch works.

Perhaps it would be better if the skip status bubbled-up so that run-tests.sh shows the test as skipped rather than failed. The exit status of run-tests.sh should be non-zero if any tests do not pass, whether skip or fail.

longwave’s picture

Test skips should not be considered as fails by the runner. We otherwise use skips to denote that a test is not compatible with a particular environment, e.g. a test for MySQL being run on a different database driver, or a deprecation test for PHPUnit that is being run on a version where the code is already removed. This case is a real failure because we couldn't even run the test at all, it is not due to a compatibility issue.

liam morland’s picture

Status: Needs review » Reviewed & tested by the community

Ah, that makes sense.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
Related issues: +#2905007: Allow run-tests.sh to report skipped/incomplete PHPUnit tests

Honestly I don't think anyone outside of DrupalCI should be using run-tests.sh - if you ran with phpunit the problem would be obvious. Having a running chromedriver is a requirement of the test. The test itself has not failed. Reporting a fail is incorrect. See https://phpunit.de/manual/6.5/en/incomplete-and-skipped-tests.html - for me this is the same as not having PHP extension that is required or a database server.

I think this issue is a duplicate of #2905007: Allow run-tests.sh to report skipped/incomplete PHPUnit tests.

liam morland’s picture

Are you saying that when we run our custom tests for our web site we should use phpunit directly instead of using run-tests.sh?

alexpott’s picture

@Liam Morland that's what I do. One less layer.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

liam morland’s picture

Component: phpunit » documentation
Status: Needs review » Fixed

I have updated the documentation to inform people that they should use phpunit directly instead of using run-tests.sh.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.