我自言自语地说:“我必须学会如何bdd?”我尝试过Symfony2 2/Behat/Mink组合。
嗯,我写代码是为了写教程。但是文档/教程中的每个behat版本都低于版本3。我想学习behat3。我要去behat的官方网页,并且阅读。
一切正常,但无论如何,behat cli应用程序不能调用扩展的mink类方法。我会把我的密码放在下面。我是如何用mink的方法运行behat3应用的。
特性/引导/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
{
}特征/家.特征
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.devcomposer.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();
}发布于 2015-08-07 12:25:49
这将从版本3开始。找到完整的示例这里,在这里中有更多的示例,包括版本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: worldFeatureContext.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 containerRun
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)https://stackoverflow.com/questions/31866173
复制相似问题