D9 Webform CiviCRM now has automated functional javascript testing! How can I run these tests on my local?

1 Answer 1


Ok here are the steps!

I'm on a Mac/MAMP and I use PhpStorm

A. Get Drupal

composer create-project drupal/recommended-project:8.9.13 d8civicrm.local
cd d8civicrm.local

composer config extra.enable-patching true
composer config minimum-stability dev

B. Get CiviCRM

composer require civicrm/civicrm-core:5.35.0 civicrm/civicrm-packages:5.35.0 civicrm/civicrm-drupal-8:5.35.0 civicrm/civicrm-asset-plugin:~1.1

C. Install Drupal

Browser to your new website -> in my case: http://d8civicrm.local and follow the install step in the UI.

D. Make it writeable

chmod -R +w d8civicrm.local

we need to write e.g. the civicrm.settings.php file next!

E. Install CiviCRM

Go to the UI -> Extend -> or use drush!

F. Patch alert!

No longer needed!

G. PHPUnit configuration

copy this file: https://gist.github.com/mglaman/efcdb804dcced6ddc856e9e0050aad1e -> into /Applications/MAMP/htdocs/d8civicrm.local (i.e. where your composer.json is) and make updates specifically add in your BASE_URL and your DB location and credentials:

<     <env name="SIMPLETEST_BASE_URL" value="http://d8civicrm.local"/>
>     <env name="SIMPLETEST_BASE_URL" value=""/>
<     <env name="SIMPLETEST_DB" value="mysql://myadminuser:db^88*@localhost:3306/d8civicrm_local"/>
>     <env name="SIMPLETEST_DB" value=""/>

Note: when testing CiviCRM Extensions -> add this line as well - as per docs: docs -> https://docs.civicrm.org/dev/en/latest/testing/mink/

<env name="DEV_EXTENSION_DIR" value="/Applications/MAMP/htdocs/d9civicrm.local/web/sites/default/files/civicrm/ext/"/>

H. Install webform module

composer require 'drupal/webform:^6.0'

I. Install webform_civicrm module

-> (at this points the tests have not been released yet so you'll need to clone the webform civicrm github repo):

git clone https://github.com/colemanw/webform_civicrm.git --branch 8.x-5.x

J. Get the Drupal Dev tools

We started with drupal-recommended - now let's get the dev tools:

composer config minimum-stability dev
composer require drupal/core-dev-pinned:^8.9 --no-suggest

Note: reproducing this just now - I ended up having to rm composer.lock and rm -r vendor as it was spitting out a symfony conflict. Ah looks like in the .github/workflows/main.yml file we install the drupal dev tools before we install CiviCRM

K. Configure PHPStorm

PHPStorm -> Preferences -> Language & Frameworks -> PHP -> Test Frameworks.

enter image description here

If running into autoloading issues - things to try: add the entire path to phpunit -> /Applications/MAMP/htdocs/d9civicrm.local/vendor/phpunit/phpunit as a PHP include path in Languages and Frameworks in the PhpStorm settings - hit Apply -> then check the Test Frameworks page again.

enter image description here

L. Install Chromedriver


and start it

To check that it's running:
karins-MBP:bin sysadmin$ ps -ax |grep chromedriver
62821 ttys004 0:00.18 chromedriver

M. Run a test!

Before you can run a test -> you need to drop all tables and triggers from your database or you'll hit this error (below). Of course make a backup if you have any configs you'd like to keep.

1) Drupal\Tests\webform_civicrm\FunctionalJavascript\ContributionDummyTest::testOnePageDonation
RuntimeException: The provided database connection in SIMPLETEST_DB contains CiviCRM tables, use a different database.

enter image description here

PS - Note to self: if you run into: Error : Call to undefined method CRM_Utils_System_UnitTests::parseUrl()

Go into -> Run/Debug Configurations and hit Environment Variables and SWITCH OFF -> Include system environment variables (as one may have included variables specific to CiviCRM Unit Testing)

I'm still working on getting xdebug to work with phpunit test - in the mean time -> to debug variables within your unit test ->

$result_debug = var_export($contact_result);    


throw new \Exception(var_export($api_result, TRUE));

Also handy for local screenshots -> e.g.
    $this->htmlOutputDirectory = '/Applications/MAMP/htdocs/d9civicrm.local/web/sites/default/files/simpletest/';
    $this->createScreenshot($this->htmlOutputDirectory . 'KG.png');

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.