drupal-8 - 如何将参数对象变量从 behat.yml 传递给 FeatureContext.php 构造函数?
问题描述
在我的 behat.yml 上下文中,我需要将参数对象变量传递给 FeatureContext.php 构造函数方法。
在我的 behat.yml 文件中,我无法实例化 FeatureContext.php 中构造函数所需的类的实例。
当我运行 Behat 测试时,它显示一个错误,说我传入了一个“字符串”但需要类 FourZeroFour 的实例
这是我的 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:
fourZeroFour: FourZeroFour
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
extensions:
这是我在 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;
}
解决方案
我的建议是:
FeatureContext
应该扩展MinkContext
或从 Drupal 扩展的另一个上下文MinkContext
(如果有)(可能MinkContext
来自 drupal)。- 该
yml
文件应该MinkContext
只加载一次,只添加MinkContext
直接延伸到另一个类的类。例如:如果 FeatureContext 扩展了 MinkContext 或者另一个扩展了 MinkContext 的类,那么在 yml 中你只能添加FeatureContext
- 对于页面对象使用注入,以便您可以在 ide 中受益于自动完成
- 关于构造函数,这似乎是一个页面对象,您可以使用
use
推荐阅读
- apache - 检索不记名访问令牌时打开 JPA 错误
- node.js - 如何在 Angular 项目中从默认 npmjs 存储库切换到 Artifactory 存储库
- php - Woocommerce - 从 csv 文件导入产品
- xamarin.forms - 在 xmlns Xamarin 表单中找不到类型 ImageButton
- jquery - 如何在单击按钮时以两种不同的颜色显示按钮
- php - 使用 Retrofit 和 PHP 脚本上传多个数据
- python - Python pandas显示重复值
- git - Git fetch 命令随机失败,错误代码为 128
- html - 如何在页面两侧设置两个 div?
- c# - 通过在启动时将 HKCU RegKey 自动设置为 0,Outlook 加载项持续禁用