How to communicate between contexts in behat 3?

烂漫一生 提交于 2019-12-03 16:00:29

You can use scenario hooks, as explained in the "Accessing contexts from each other" documentation page:

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
     }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!