【问题标题】:Behat unable to find my context classesBehat 找不到我的上下文类
【发布时间】:2016-04-27 00:34:25
【问题描述】:

我有一个 features 文件夹是根目录,在一个子目录中我有一个名为 public 的文件夹,其中包含 2 个要素上下文类。 SignIn.php 和 PostProject.php

我在 behat.yml 文件中指定了上下文类的路径,它一直告诉我找不到上下文类并且无法使用?我真的不明白它怎么找不到它。

我不知道如何纠正这个问题...它看起来对我来说是正确的,但不确定我做错了什么。

任何帮助将不胜感激。下面是我的 behat.yml 文件

default:
    suites:
        public:
            paths:      [%paths.base%/features/public]
            contexts:
                - PostProject
                - SignIn
                - Behat\MinkExtension\Context\MinkContext
    extensions:
      Behat\MinkExtension:
        goutte: ~
        selenium2: ~

【问题讨论】:

    标签: php behat


    【解决方案1】:

    我找到了答案。

    上下文类需要由其命名空间自动加载。并且需要在 behat.yml 文件中指定。路径上下文用于功能测试 (test.feature) 文件

    这是修改后的 .yml 文件

    default:
        autoload:
            '': %paths.base%/features
        suites:
            public:
                paths:      [%paths.base%/features]
                contexts:
                    - public1\PostProject
                    - public1\SignIn
                    - Behat\MinkExtension\Context\MinkContext
            client:
                paths:      [%paths.base%/features]
                contexts:
                    - Client
        extensions:
          Behat\MinkExtension:
            goutte: ~
            selenium2: ~
    

    上下文类示例

    namespace public1;
    
    date_default_timezone_set("America/New_York");
    use Behat\Behat\Context\Context;
    use Behat\Behat\Context\SnippetAcceptingContext;
    use Behat\Behat\Hook\Scope\BeforeScenarioScope;
    
    /**
     * Defines application features from the specific context.
     */
    class SignIn  implements Context, SnippetAcceptingContext
    {
    //Content here
    }
    
    
    
    namespace public1;
    
    date_default_timezone_set("America/New_York");
    use Behat\Behat\Context\Context;
    use Behat\Behat\Context\SnippetAcceptingContext;
    use Behat\Behat\Hook\Scope\BeforeScenarioScope;
    
    /**
     * Defines application features from the specific context.
     */
    class PostProject  implements Context, SnippetAcceptingContext
    {
    //Content here
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多