Search code examples
automated-testsdrupal-8behat

Behat test error after upgrade to Behat 3.3.1 - Too few arguments to function FeatureContext


I'm upgrading my Drupal 8 site to 8.4.8 which automatically upgrade behat to 3.3.1

I just found out my Behat test is no longer work and stuck on the following errors.

Here's the error

ArgumentCountError: Too few arguments to function Drupal\FeatureContext::__construct(), 0 passed and exactly 1 expected in /var/www/mywebsite/tests/behat/features/bootstrap/Drupal/FeatureContext.php

Here's my constructor in FeatureContext.php file

/**
 * FeatureContext class defines custom step definitions for Behat.
 */
class FeatureContext extends PageObjectContext implements SnippetAcceptingContext {

  private $fourZeroFour;

  public function __construct(FourZeroFour $fourZeroFour) {
    $this->fourZeroFour = $fourZeroFour;
  }

Here's my behat.yml

imports:
  - behat.yml

local:
  suites:
    default:
      paths:
        # Set features to repo root so that .feature files belonging to contrib
        # modules, themes, and profiles can be discovered.
        features: /var/www/mywebsite
        bootstrap: /var/www/mywebsite/tests/behat/features/bootstrap
      contexts:
        - Drupal\FeatureContext:
          parameters:
            environment:
              # absolute path to local directory to store screenshots - do not include trailing slash
              screenshot_dir: /var/www/mywebsite/reports
        - Drupal\DrupalExtension\Context\DrupalContext
        - Drupal\DrupalExtension\Context\MinkContext
        - Drupal\DrupalExtension\Context\MessageContext
        - Drupal\DrupalExtension\Context\DrushContext

Solution

  • It turned out, a part of my configuration was missing from behat.yml file.

    The part was missing:

    SensioLabs\Behat\PageObjectExtension:
      namespaces:
        page: Page
        element: Page\Element