升级到Behat 3.3.1后,Behat测试错误-函数FeatureContext的参数太少

时间:2019-04-23 01:22:44

标签: automated-tests drupal-8 behat

我正在将Drupal 8网站升级到8.4.8,该网站会自动将behat升级到3.3.1

我刚刚发现我的Behat测试不再有效,并且遇到了以下错误。

这是错误

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

这是我在FeatureContext.php文件中的构造函数

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

  private $fourZeroFour;

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

这是我的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

1 个答案:

答案 0 :(得分:0)

原来,behat.yml文件中缺少我的配置的一部分。

缺少该部分:

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