2015-09-22 52 views
1

我已经设置了我的第一个Behat项目,但我遇到了定义除了FeatureContext以外的其他上下文的麻烦。它被创建(我用__construct中的一个骰子检查过),但是这些步骤没有被调用。无法识别自定义上下文的步骤

这里我的文件夹结构:

|-root 
    |-bin 
    |-features 
    |-FeatureContext.php 
    |-PageLoaderContext.php 
    |-page_loading.feature 

我的package.json

{ 
    "require": { 
    "behat/behat":   "3.0.5", 
    "behat/mink-extension": "*", 
    "behat/mink-goutte-driver":  "*", 
    "behat/mink-selenium2-driver": "*", 
    "behat/mink-zombie-driver": "*", 
    "symfony/http-kernel": "*" 
    }, 
    "minimum-stability": "dev", 
    "config": { 
    "bin-dir": "bin" 
    } 
} 

这里是我的behat.yaml

default:    
    suites: 
    default: 
     contexts: 
     - PageLoaderContext 

而我的特点

Feature: Tutte le pagine del sito caricano senza errori 
    Per poter usare il sito 
    Come utente 
    Ho bisogno che tutte le pagine carichino senza errori 

    Scenario Outline: Controlla il caricamento senza errori di pagine significative 
    Given I'm on "<url>" 
    When La pagina finisce di caricare 
    Then Dovrei ottenere uno status code HTTP pari a "<code>" 
    And Il "<selector>" della pagina dovrebbe contenere "<value>" 

    Examples: 
     | url | code | selector | value | 
     | ? | 200 | head title | Spagro | 

PageLoaderContext.php

<?php 

use Behat\Behat\Exception\PendingException; 

class PageLoaderContext implements \Behat\Behat\Context\Context 
{ 
    /** 
    * @Given /^Carico la pagina "([^"]*)"$/ 
    */ 
    public function caricoLaPagina($arg1) 
    { 
    throw new PendingException(); 
    } 

    /** 
    * @When /^La pagina finisce di caricare$/ 
    */ 
    public function laPaginaFinisceDiCaricare() 
    { 
    throw new PendingException(); 
    } 

    /** 
    * @Then /^Dovrei ottenere uno status code HTTP pari a "([^"]*)"$/ 
    */ 
    public function dovreiOttenereUnoStatusCodeHttpPariA($arg1) 
    { 
    throw new PendingException(); 
    } 

    /** 
    * @Given /^Il "([^"]*)" della pagina dovrebbe contenere "([^"]*)"$/ 
    */ 
    public function ilDellaPaginaDovrebbeContenere($arg1, $arg2) 
    { 
    throw new PendingException(); 
    } 
} 

就像我说的,如果我实现FeatureContext的步骤,一切都很好,但是这是不行的。

+0

请参阅:http://stackoverflow.com/help/tagging – Rizier123

回答

0

试图改变自己的behat.yml

default:    
    suites: 
    pageLoaderSuite: 
     paths: 
     - %paths.base%/features 
     contexts: 
     - Path\To\Your\Context 

不过,我可以看到你没有命名空间PageLoaderContextClass

0

我试图使套房工作,但贝哈特似乎忽略它们。所以我不得不在套件上使用配置文件,它工作。

*behat.yaml* 
page_loading: 
    paths: 
    features: features\bootstrap\page_loading 
    bootstrap: %behat.paths.features% 
    context: 
    class: PageLoaderContext 

现在,对于每个功能,我将在.feature文件和上下文类的引导程序中创建一个文件夹。

相关问题