首先运行这些命令来安装依赖项:
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
现在说你想要作为 localhost.behat 托管的 symfony 应用程序,然后将 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(首选)运行以下命令:
bin/behat -v --suite=api @NameSpaceYourBundle/your.feature --config=app/config/behat.yml -f pretty
或者如果要将输出保存为 html 在 web/behat 目录中,则:
bin/behat -v --suite=api @NameSpaceYourBundle/your.feature --config=app/config/behat.yml
让我知道它是否有效
注意:我不确定您是在运行 selenium 服务器还是独立服务器,因此添加了运行 selenium 独立服务器的步骤:
下载selenium和chromedriver并将 selenium 服务器 .exe 和 chromedriver.exe 放在同一个文件夹中,使用“java -version”检查它不应该小于 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