问题
If I use bin/behat @FootballTeamBundle
in terminal as stand-alone, the error screen-shots are taken and saved under build/behat/
folder which is fine however, if I run bin/phing
then the FeatureContext
file seems to be ignored as a whole so neither screen-shots taken nor its internal methods are being triggered (such as I wait for ** seconds) which is strange. Anyone know the solution to it?
I also updated the line to bin/behat -f progress --format html --out ${dir-report}/behat.html
to bin/behat @FootballTeamBundle
in my build.xml but nothing changed.
Thanks in advance.
/var/www/html/local/sport/behat.yml
default:
context:
class: FeatureContext
parameters:
screen_shots_path: 'build/behat/'
extensions:
Behat\Symfony2Extension\Extension:
mink_driver: true
kernel:
env: test
debug: true
Behat\MinkExtension\Extension:
base_url: 'http://localhost/local/sport/web/app_test.php/'
files_path: 'dummy/'
browser_name: chrome
goutte: ~
selenium2: ~
paths:
features: src/Football/TeamBundle/Features
bootstrap: %behat.paths.features%/Context
/var/www/html/local/sport/src/Football/TeamBundle/Features/Context/FeatureContext.php
<?php
namespace Football\TeamBundle\Features\Context;
use Behat\MinkExtension\Context\MinkContext;
use Behat\Mink\Exception\UnsupportedDriverActionException;
use Behat\Mink\Driver\Selenium2Driver;
class FeatureContext extends MinkContext
{
/**
* Where the failure images will be saved.
*
* @var string
*/
protected $screenShotsPath;
/**
* Comes from behat.yml file.
*
* @param $parameters
*/
public function __construct($parameters)
{
$this->screenShotsPath = $parameters['screen_shots_path'];
}
/**
* Take screen-shot when step fails.
* Works only with Selenium2Driver.
*
* @AfterStep
* @param $event
* @throws \Behat\Mink\Exception\UnsupportedDriverActionException
*/
public function takeScreenshotAfterFailedStep($event)
{
if (4 === $event->getResult()) {
$driver = $this->getSession()->getDriver();
if (! ($driver instanceof Selenium2Driver)) {
throw new UnsupportedDriverActionException(
'Taking screen-shots is not supported by %s, use Selenium2Driver instead.',
$driver
);
return;
}
if (! is_dir($this->screenShotsPath)) {
mkdir($this->screenShotsPath, 0777, true);
}
$filename = sprintf(
'%s_%s_%s.%s',
$this->getMinkParameter('browser_name'),
date('Y-m-d') . '_' . date('H:i:s'),
uniqid('', true),
'png'
);
file_put_contents($this->screenShotsPath . '/' . $filename, $driver->getScreenshot());
}
}
/**
* @Then /^I wait for "([^"]*)" seconds$/
*
* @param $seconds
*/
public function iWaitForGivenSeconds($seconds)
{
$this->getSession()->wait($seconds*1000);
}
}
/var/www/html/local/sport/build.xml
<!-- GLOBAL VARIABLES -->
<property name="dir-source" value="${project.basedir}/src" />
<property name="dir-report" value="${project.basedir}/build/phing" />
<!-- END -->
<!-- AVAILABLE CLI COMMANDS -->
<target name="build"
description="Runs everything in order ..."
depends="cache-clear, cache-warm, load-fixtures, codesniffer-psr2, behat-bdd" />
<!-- END -->
<!-- FILESET -->
<fileset id="sourcecode" dir="${dir-source}">
<include name="**/*.php" />
</fileset>
<!-- END -->
............. OTHER TESTS ARE HERE, JUST REMOVED TO KEEP IT CLEAN
<!-- BEHAT - BDD -->
<target name="behat-bdd">
<echo msg="Running Behat tests ..." />
<exec logoutput="true" checkreturn="true"
command="bin/behat -f progress --format html --out ${dir-report}/behat.html"
dir="./" />
</target>
<!-- END -->
回答1:
I never dealt with phing nor a Symfony fan. Hopefully this is purely a config issue. Try being more specific with your paths by using %behat.paths.base%
. Also make use of namespaces ;)
default:
context:
class: Football\TeamBundle\Features\Context\FeatureContext
parameters:
screen_shots_path: %behat.paths.base%/build/behat/
extensions:
Behat\Symfony2Extension\Extension:
mink_driver: true
kernel:
env: test
debug: true
Behat\MinkExtension\Extension:
base_url: 'http://localhost/local/sport/web/app_test.php/'
files_path: %behat.paths.base%/dummy/
browser_name: chrome
goutte: ~
selenium2: ~
paths:
features: %behat.paths.base%/src
bootstrap: %behat.paths.features%/Context
%behat.paths.base%
is where you behat.yml
sits. So update the config with it setting the correct paths relevant to it.
来源:https://stackoverflow.com/questions/25796825/bin-behat-footballteambundle-is-fine-but-bin-phing-is-not-for-running-featureco