【问题标题】:Custom environment contexts with behat使用 behat 自定义环境上下文
【发布时间】:2014-01-26 02:01:19
【问题描述】:

我们正在使用 behat 在我们的系统上运行一些功能测试,模拟用户通过我们网站的旅程。我已经编写了一些上下文,其中包含要检查的事物的定义。

因为 behat 将在不同的环境(我们的开发 PC,然后是我们的登台服务器......)上运行,所以运行的 @BeforeSuite 函数需要不同的设置。我会将它们放在带有自定义配置文件的 behat.yml 中,但我不知道如何阅读该信息

那么,我要问的是如何获取上下文文件中的 behat 配置信息?

【问题讨论】:

    标签: php behat


    【解决方案1】:

    behat.yml 中配置的参数通过构造函数(在 Behat 2 中)注入到主上下文文件中:

    class FeatureContext extends BehatContext
    {
        private $parameters;
    
        public function __construct(array $parameters)
        {
            $this->parameters = $parameters;
        }
    }
    

    但是,由于您使用@BeforeSuite,上下文实例尚不可用(并且钩子方法是静态的)。

    您仍然可以从事件中获取参数:

    class FeatureContext extends BehatContext
    { 
        /** @BeforeSuite */
        public static function setup(SuiteEvent $event)
        {
            $parameters = $event->getContextParameters();
        }
    }
    

    相关文档:http://docs.behat.org/guides/3.hooks.html#suite-hooks

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-11
      • 2012-10-12
      • 2014-12-01
      • 2013-12-01
      • 1970-01-01
      • 2020-01-27
      • 1970-01-01
      • 2020-02-21
      相关资源
      最近更新 更多