I'm writing front end tests for a custom webform. These tests work fine when testing on the webform page of the form.


However, testing the form using a custom theme and the page that the form is displayed on, does not work and the assertion fails returning a 404 response.


namespace Drupal\Tests\test_module\Kernel;

use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\webform\Functional\Element\WebformElementBrowserTestBase;

class WebformValidationTest extends WebformElementBrowserTestBase {

  public static $modules = [

  public static $testWebforms = ['custom_form'];

  protected $defaultTheme = 'custom_theme';

   * Test custom_form page from site with custom_theme theme install.
   * @throws \Exception
  public function testThemeFormPage() {

I have also tried creating a submodule that imports the full config and installs all dependent modules from the site. This also did not work.

Is writing front end tests for specific nodes something that is possible with Drupal Browser Tests? If not, how does one write tests for webforms (validation, fields, display, etc)?


2 Answers 2


I Would recommend reading https://www.previousnext.com.au/blog/introducing-drupal-testing-traits-drupal-extension-testing-existing-sites

in this article it explains using https://gitlab.com/weitzman/drupal-test-traits

in this way you can do...

use weitzman\DrupalTestTraits\ExistingSiteBase;

 * Test webform on theme
class WebformValidationTest extends ExistingSiteBase
    public function testThemeFormPage()
        // Assert stuff here.

It is possible to get a custom theme to load during a test.

Checkout the webform_bootstrap_test_theme included in the core Webform module. Make sure to includes all the needed blocks.

You can use the WebformNodeBrowserTestTrait to create a webform node during a test.

Still, it is worth checking out DrupalTestTraits.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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