Behat 不调用扩展的 mink 方法
Behat not call extended mink methods
我自己说 "I must learn how to bdd?" 我尝试 Symfony2/Behat/Mink 组合。
好吧,我写代码就像写教程一样。但是 documents/tutorials 中的每个 behat 版本都低于版本 3。我想学习 behat3。我要上官网,看书了
一切正常,但不知何故,behat cli 应用程序无法调用扩展的 mink class 方法。我会把我的代码放在下面。我如何 运行 behat3 应用程序使用 mink 的方法。
features/bootstrap/FeatureContext.php
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends \Behat\MinkExtension\Context\MinkContext implements Context, SnippetAcceptingContext
{
}
features/home.特征
Feature: Home
I want to see homepage
As a anonym user
Scenario:
Given |I am on |the homepage
Then |I should see text matching "Sektör"
behat.yml
default:
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
sessions:
default:
symfony2: ~
selenium2:
selenium2: ~
base_url: http://site.dev
composer.json
"behat/behat": "~3.0",
"behat/mink-extension": "~2.0@dev",
"behat/mink-goutte-driver": "~1.0",
"behat/mink-selenium2-driver": "~1.1",
"behat/symfony2-extension": "*"
结果:
Feature: Home
I want to see homepage
As a anonym user
Scenario: # features/home.feature:4
Given |I am on |the homepage
Then |I should see text matching "Sektör"
1 scenario (1 undefined)
2 steps (2 undefined)
0m0.12s (25.80Mb)
--- FeatureContext has missing steps. Define them with these snippets:
/**
* @Given |I am on |the homepage
*/
public function iAmOnTheHomepage()
{
throw new PendingException();
}
/**
* @Then |I should see text matching :arg1
*/
public function iShouldSeeTextMatching($arg1)
{
throw new PendingException();
}
这将使您从版本 3 开始。找到整个示例 here and there are more examples in here,包括。版本 2.
composer.json
{
"require-dev": {
"behat/behat" : "3.0.15",
"behat/symfony2-extension" : "2.0.0",
"behat/mink": "1.6.1",
"behat/mink-extension": "2.0.1",
"behat/mink-browserkit-driver": "1.2.0",
"behat/mink-goutte-driver": "1.1.0",
"behat/mink-selenium2-driver": "1.2.0"
}
}
behat.yml
default:
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: http://football.local/app_test.php
browser_name: firefox
sessions:
goutte: # fast, CLI, browser, no javascript support
goutte: ~
selenium2: # fast, CLI, opens up a browser
selenium2: ~
symfony2: # very fast, CLI, no browser
symfony2: ~
suites:
backend:
type: symfony_bundle
bundle: ApplicationBackendBundle
mink_session: symfony2
contexts:
- Application\BackendBundle\Features\Context\FeatureContext:
param1: hello
param2: world
FeatureContext.php
namespace Application\BackendBundle\Features\Context;
use Behat\MinkExtension\Context\MinkContext;
use Behat\Symfony2Extension\Context\KernelAwareContext;
use Symfony\Component\HttpKernel\KernelInterface;
class FeatureContext extends MinkContext implements KernelAwareContext
{
private $kernel;
private $param1;
private $param2;
public function __construct($param1, $param2)
{
$this->param1 = $param1;
$this->param2 = $param2;
}
public function setKernel(KernelInterface $kernelInterface)
{
$this->kernel = $kernelInterface;
}
/**
* @Given /^I can access service container$/
*/
public function iCanAccessServiceContainer()
{
$container = $this->kernel->getContainer();
echo $container->getParameter('secret');
}
}
示例特征
# Backend
Feature: Dummy feature
Scenario: Home url
Given I am on "/backend"
Then I should see "Welcome to Application backend!"
And I can access service container
# Frontend
Feature: Dummy feature
Scenario: Home url
Given I am on "/"
Then I should see "Welcome to Application frontend!"
And I can access service container
运行
bin/behat --suite=backend
Feature: Dummy feature
Scenario: Home url
Given I am on "/backend"
Then I should see "Welcome to Application backend!"
And I can access service container
│ ThisTokenIsNotSoSecretChangeIt
1 scenario (1 passed)
3 steps (3 passed)
0m0.98s (28.17Mb)
我自己说 "I must learn how to bdd?" 我尝试 Symfony2/Behat/Mink 组合。
好吧,我写代码就像写教程一样。但是 documents/tutorials 中的每个 behat 版本都低于版本 3。我想学习 behat3。我要上官网,看书了
一切正常,但不知何故,behat cli 应用程序无法调用扩展的 mink class 方法。我会把我的代码放在下面。我如何 运行 behat3 应用程序使用 mink 的方法。
features/bootstrap/FeatureContext.php
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends \Behat\MinkExtension\Context\MinkContext implements Context, SnippetAcceptingContext
{
}
features/home.特征
Feature: Home
I want to see homepage
As a anonym user
Scenario:
Given |I am on |the homepage
Then |I should see text matching "Sektör"
behat.yml
default:
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
sessions:
default:
symfony2: ~
selenium2:
selenium2: ~
base_url: http://site.dev
composer.json
"behat/behat": "~3.0",
"behat/mink-extension": "~2.0@dev",
"behat/mink-goutte-driver": "~1.0",
"behat/mink-selenium2-driver": "~1.1",
"behat/symfony2-extension": "*"
结果:
Feature: Home
I want to see homepage
As a anonym user
Scenario: # features/home.feature:4
Given |I am on |the homepage
Then |I should see text matching "Sektör"
1 scenario (1 undefined)
2 steps (2 undefined)
0m0.12s (25.80Mb)
--- FeatureContext has missing steps. Define them with these snippets:
/**
* @Given |I am on |the homepage
*/
public function iAmOnTheHomepage()
{
throw new PendingException();
}
/**
* @Then |I should see text matching :arg1
*/
public function iShouldSeeTextMatching($arg1)
{
throw new PendingException();
}
这将使您从版本 3 开始。找到整个示例 here and there are more examples in here,包括。版本 2.
composer.json
{
"require-dev": {
"behat/behat" : "3.0.15",
"behat/symfony2-extension" : "2.0.0",
"behat/mink": "1.6.1",
"behat/mink-extension": "2.0.1",
"behat/mink-browserkit-driver": "1.2.0",
"behat/mink-goutte-driver": "1.1.0",
"behat/mink-selenium2-driver": "1.2.0"
}
}
behat.yml
default:
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: http://football.local/app_test.php
browser_name: firefox
sessions:
goutte: # fast, CLI, browser, no javascript support
goutte: ~
selenium2: # fast, CLI, opens up a browser
selenium2: ~
symfony2: # very fast, CLI, no browser
symfony2: ~
suites:
backend:
type: symfony_bundle
bundle: ApplicationBackendBundle
mink_session: symfony2
contexts:
- Application\BackendBundle\Features\Context\FeatureContext:
param1: hello
param2: world
FeatureContext.php
namespace Application\BackendBundle\Features\Context;
use Behat\MinkExtension\Context\MinkContext;
use Behat\Symfony2Extension\Context\KernelAwareContext;
use Symfony\Component\HttpKernel\KernelInterface;
class FeatureContext extends MinkContext implements KernelAwareContext
{
private $kernel;
private $param1;
private $param2;
public function __construct($param1, $param2)
{
$this->param1 = $param1;
$this->param2 = $param2;
}
public function setKernel(KernelInterface $kernelInterface)
{
$this->kernel = $kernelInterface;
}
/**
* @Given /^I can access service container$/
*/
public function iCanAccessServiceContainer()
{
$container = $this->kernel->getContainer();
echo $container->getParameter('secret');
}
}
示例特征
# Backend
Feature: Dummy feature
Scenario: Home url
Given I am on "/backend"
Then I should see "Welcome to Application backend!"
And I can access service container
# Frontend
Feature: Dummy feature
Scenario: Home url
Given I am on "/"
Then I should see "Welcome to Application frontend!"
And I can access service container
运行
bin/behat --suite=backend
Feature: Dummy feature
Scenario: Home url
Given I am on "/backend"
Then I should see "Welcome to Application backend!"
And I can access service container
│ ThisTokenIsNotSoSecretChangeIt
1 scenario (1 passed)
3 steps (3 passed)
0m0.98s (28.17Mb)