在我的composer.json中。
{
...
"behat/behat": "^3.6",
"behat/mink-extension": "^2.3",
"behat/mink-goutte-driver": "^1.2",
"behat/mink-selenium2-driver": "^1.4"
}
我的behat. yml:
default:
autoload:
'': %paths.base%/features/bootstrap
suites:
default:
path:
- %paths.base%/features
contexts:
- FeatureContext
- Behat\MinkExtension\Context\MinkContext
- Behat\MinkExtension\Context\RawMinkContext
extensions:
Behat\MinkExtension:
base_url: https://localhost:8443
goutte: ~
selenium2: ~
javascript_session: selenium2
files_path: 'vendor'
sessions:
default:
selenium2: ~
我的特征上下文:
class FeatureContext extends MinkContext
{
/** @var Behat\Mink\Element\DocumentElement */
protected $page;
/**
* Initializes context.
*
* Every scenario gets its own context instance.
* You can also pass arbitrary arguments to the
* context constructor through behat.yml.
*/
public function __construct()
{
$this->page = $this->getSession()->getPage();
}
/**
* @Given /^I am not logged in$/
*/
public function iAmNotLoggedIn()
{
// Do nothing
}
/**
* @When /^I visit \.*$/
*/
public function iVisit($page)
{
$this->getSession()->visit('/login');
}
/**
* @Then /^I should see the login page$/
*/
public function iShouldSeeTheLoginPage()
{
$this->assertSession()->elementExists('css', '#username');
$this->assertSession()->elementExists('css', '#password');
$this->assertSession()->elementExists('css', '#submit');
}
}
我的特征文件
Feature: Viewing the main page as an unauthenticated user
@javascript
Scenario: View the main page
Given I am not logged in
When I visit "/login"
Then I should see the login page
当我试图运行 behat
命令,我得到的错误是 Mink instance has not been set on Mink context class. Have you enabled the Mink Extension?
. 我看了一下围绕这个错误实例的问题,并按照尽可能多的步骤来修复,但他们似乎都没有做到这一点。我是否有什么遗漏的地方?
所以在构造函数中的 FeatureContext
我试图在完全实例化之前访问会话。删除这一行后,问题就解决了。