2016-05-12 42 views
0

取決於我的FeatureContext類是否延伸RawMinkContextMinkContext我在運行Behat測試時遇到問題。Ubuntu上的Behat 3和Mink Extension在FeatureContext中的錯誤

這裏是我的FeatureContext.php

<?php 

use Behat\Behat\Context\ClosuredContextInterface; 
use Behat\Behat\Context\TranslatedContextInterface; 
use Behat\Behat\Context\Context; 
use Behat\Behat\Context\BehatContext; 
use Behat\Behat\Exception\PendingException; 
use Behat\Gherkin\Node\PyStringNode; 
use Behat\Gherkin\Node\TableNode; 
use Behat\MinkExtension\Context\MinkContext; 
use Behat\MinkExtension\Context\RawMinkContext; 
use Behat\Behat\Context\SnippetAcceptingContext; 

use Behat\Mink\Driver\Selenium2Driver; 
use Behat\Behat\Hook\Scope\AfterStepScope; 
use Goutte\Client; 

class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext { 

    /** 
    * Initializes context. 
    * Every scenario gets its own context object. 
    * 
    * @since 1.0.0 
    * 
    * @param array $parameters context parameters (set them up through behat.yml) 
    * @return null 
    */ 

    public function __construct() { 

    }/* __construct() */ 

} 
?> 

behat.yml

default: 
    suites: 
     default: 
      path: %paths.base%/features 
      contexts: 
       - FeatureContext 
       - Behat\MinkExtension\Context\MinkContext 
       - Behat\MinkExtension\Context\RawMinkContext 
    extensions: 
     Behat\Symfony2Extension: ~ 
     Behat\MinkExtension: 
      base_url: 'http://somesite.com' 
      goutte: ~ 
      javascript_session: selenium2 
      files_path: 'vendor' 
      selenium2: ~ 
      sessions: 
       default: 
        goutte: ~ 
       goutte: 
        goutte: ~ 
       selenium2: 
        selenium2: ~ 
       symfony2: 
        symfony2: ~ 
    formatters: 
     html: 
      output_path: %paths.base%/reports 

PHP Fatal error: Call to a member function getSession() on a non-object in /home/behat/composer/vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php on line 101

如果我extendRawMinkContext代替MinkContext,然後運行的測試,但它增加的(空白)版本在MinkContext中定義的默認步驟(即If我在[url]或者當我去[url]等)。

如果我運行behat -c ./config/behat.yml(或者,只是./behat.yml - 我必須在這兩個位置相同的behat.yml文件,我不知道它被正確使用),我得到上述同樣的結果。我幾乎可以肯定做了愚蠢的事情......

composer.json供參考:

{ 
"name": "behat mink skeleton", 
"require": { 
    "behat/behat": "*", 
    "behat/mink-extension": "*", 
    "behat/mink-browserkit-driver": "*", 
    "behat/mink-goutte-driver": "*", 
    "behat/mink-selenium2-driver": "*", 
    "bossa/phpspec2-expect": "*", 
    "teaandcode/behat-guzzle-extension": "*", 
    "sauce/sausage": ">=0.5", 
    "sauce/connect": ">=3.0", 
    "emuse/behat-html-formatter": "dev-master" 
}, 
"minimum-stability": "dev", 
"config": { 
     "bin-dir": "bin/", 
     "github-oauth": { 
      "github.com": "ac1dd3678488663ccc1ba02a5d1d474e1a78bb93" 
     } 
    } 
} 
+1

關於如何使用bahat2,behat3,相關作曲文件,behat.yml文件,FeatureContext等文件,有很多例子[heres](http://www.inanzzz.com/index.php/posts/behat) 。根據您正在擴展的課程,獲取會話會有所不同。你可以在那個博客中搜索'getSession'。 – BentCoder

回答

0

如果您在FeatureContext延長MinkContext然後從behat.yml刪除MinkContext。 behat.yml文件應該僅包含上下文部分下的本地上下文,在您的情況下,您不需要MinkContext或RawAwareContext,只需要FeatureContext。

相關問題