2015-04-16 68 views
5

我不能使用getMainContext()和getSubcontext($化名)在3個版本了。在版本3中的上下文之間進行通信的方式是什麼?上下文特徵是唯一的方式嗎?如何在behat 3中的上下文之間進行通信?

# behat.yml 
default: 
    suites: 
     guest_features: 
       paths: [ %paths.base%/features/web ] 
       filters: { role: guest } 
       contexts: [ GuestContext ] 

     user_features: 
      paths: [ %paths.base%/features/web ] 
      filters: { role: member } 
      contexts: [ MemberContext ] 

     groupled_features: 
      paths: [ %paths.base%/features/web ] 
      filters: { role: grouplead} 
      contexts: [ GroupleadContext ] 

     admin_features: 
      paths: [ %paths.base%/features/web ] 
      filters: { role: admin } 
      contexts: [ AdminContext ] 

extensions: 
    Behat\MinkExtension: 
     base_url: http://ollo.com 
     browser_name: firefox 
     selenium2: 
       capabilities: { "browser": "firefox", "version": "24"} 
     goutte: ~ 

回答

10

您可以使用scenario hooks,如"Accessing contexts from each other"文檔頁面解釋說:

use Behat\Behat\Context\Context; 
use Behat\Behat\Hook\Scope\BeforeScenarioScope; 

class MemberContext implements Context 
{ 
    /** @var GuestContext */ 
    private $guestContext; 


    /** @BeforeScenario */ 
    public function before(BeforeScenarioScope $scope) 
    { 
     // Get the environment 
     $environment = $scope->getEnvironment(); 
     // $environment is an instance of 
     //  Behat\Behat\Context\Environment\InitializedContextEnvironment 


     // Get all the contexts you need in this context 
     $this->guestContest = $environment->getContext('GuestContext'); 
     // $this->guestContest is the instance of GuestContext 
    } 
} 
+0

這是工作環節:http://behat.org/en/latest/cookbooks/accessing_contexts_from_each_other.html - 爲我這工作開箱即用,所以這個答案應該被接受 – drupality

+0

@drupality中使用的答案被張貼的時間來工作答案的鏈接,但它似乎在此期間的文檔的佈局和服務器改變。感謝您的評論。我用新的地點更新了答案。 – axiac

+0

抱歉,我忘記了編輯的可能性 – drupality

相關問題