Symfony2扩展 - Behat Mink

时间:2013-09-13 03:07:10

标签: symfony behat mink

我从here安装了Behat Mink的Symfony2扩展 当我运行测试时,会发生错误

  

[ReflectionException]类AppKernel不存在。

我做错了什么?

behat.yml

default:
extensions:
    Behat\MinkExtension\Extension:
        base_url: http://localhost/behat
        goutte: ~
        selenium2: ~
    Behat\Symfony2Extension\Extension: ~

1 个答案:

答案 0 :(得分:0)

首先运行这些命令来安装依赖项:

composer require behat/behat
composer require behat/symfony2-extension
composer require behat/mink
composer require behat/mink-browserkit-driver
composer require behat/mink-extension
composer require behat/mink-goutte-driver
composer require behat/mink-selenium2-driver
composer require emuse/behat-html-formatter
composer require coduo/php-matcher

现在说你要将symfony applcation作为localhost.behat托管,然后将vhost配置添加到httpd_vhost.conf:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/behat/web"
    ServerName lochost.behat
    DirectoryIndex app_dev.php
    <Directory "C:/xampp/htdocs/behat/web">
        Order deny,allow
        Allow from all
    </Directory>    
</VirtualHost>

现在你的behat.yml文件应该是app / config / behat.yml,内容是:

default:
    formatters:
        html:
            output_path: web/behat
    extensions:
        Behat\Symfony2Extension: ~
        # Irs\BehatPopupExtension\Extension: ~
        Behat\MinkExtension:
            base_url: http://lochost.behat/app_dev.php/
            javascript_session: selenium2
            sessions:
                symfony2:
                    symfony2: ~
                selenium2:
                    selenium2:
                        browser: chrome
        emuse\BehatHTMLFormatter\BehatHTMLFormatterExtension:
            name: html
            renderer: Twig,Behat2
            file_name: index
            print_args: true
            print_outp: true
            loop_break: true
    suites:
        api:
            type: symfony_bundle
            bundle: NameSpaceYourBundle
            #mink_session: symfony2
            mink_session: selenium2
            contexts:
                - NameSpace\YourBundle\Features\Context\FeatureContext:
                    baseUrl: http://lochost.behat/app_dev.php/
                    screenCapturePath: web/behat

# Add "-p firefox" parameter to behat command to run tests with Firefox browser
firefox:
    extensions:
        Behat\MinkExtension\Extension:
            browser_name: firefox

# Add "-p chrome" parameter to behat command to run tests with Chrome browser
chrome:
    extensions:
        #Behat\MinkExtension\Extension:
        Behat\MinkExtension:
            browser_name: chrome

# Add "-p safari" parameter to behat command to run tests with Safari browser
safari:
    extensions:
        Behat\MinkExtension\Extension:
            browser_name: safari

现在,您可以在命名空间中添加您的功能和上下文文件:NameSpace \ YourBundle \ Features \ Context \ FeatureContext

并从命令提示符/ git bash(preferrable)运行以下命令:

bin/behat -v --suite=api @NameSpaceYourBundle/your.feature --config=app/config/behat.yml -f pretty

或者如果你想将输出保存为web / behat目录下的html,那么:

bin/behat -v --suite=api @NameSpaceYourBundle/your.feature --config=app/config/behat.yml

让我知道它是否有效

注意: 我不确定您是否正在运行selenium服务器或独立服务器,因此添加了运行selenium独立服务器的步骤:

下载seleniumchromedriver并将selenium服务器.exe和chromedriver.exe放在同一文件夹中 检查“java -version”,它不应该是&lt; 1.6.x版 您可能需要下载兼容的selenium服务器和chrome驱动程序 打开命令提示符并运行以下命令:

cd C:\<folder contains selenium server .exe and chromedriver.exe>
java -Dwebdriver.chrome.driver="chromedriver.exe" -jar selenium-server-standalone-x.xx.0.jar