bin/behat @FootballTeamBundle很好,但是bin/phing不用于运行FeatureContext [英] bin/behat @FootballTeamBundle is fine but bin/phing is not for running FeatureContext

查看:88
本文介绍了bin/behat @FootballTeamBundle很好,但是bin/phing不用于运行FeatureContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在终端机中单独使用bin/behat @FootballTeamBundle,则会拍摄错误屏幕截图并将其保存在build/behat/文件夹下,这很好,但是,如果我运行bin/phing,则FeatureContext文件似乎是整体上被忽略,因此既不触发屏幕截图也不触发其内部方法(例如我等待**秒),这很奇怪.有人知道解决方案吗?

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?

我还在build.xml中将行更新为bin/behat -f progress --format html --out ${dir-report}/behat.htmlbin/behat @FootballTeamBundle,但没有任何改变.

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.

谢谢.

/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 -->

推荐答案

我从不对phing或Symfony粉丝进行处理.希望这纯粹是一个配置问题.尝试使用%behat.paths.base%更具体地说明您的路径.还可以使用名称空间;)

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%是您behat.yml所在的位置.因此,使用它更新配置,设置与之相关的正确路径.

%behat.paths.base% is where you behat.yml sits. So update the config with it setting the correct paths relevant to it.

这篇关于bin/behat @FootballTeamBundle很好,但是bin/phing不用于运行FeatureContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆