Symfony2 Extension - Behat Mink

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

I installed a Symfony2 extension for Behat Mink from here
When I run test, an error occurs

[ReflectionException] Class AppKernel does not exist.

What am I doing wrong?

behat.yml

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

回答1:

First run these commands to install the dependencies:

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

Now say your symfony applcation you want to host as localhost.behat, then add the vhost configuration to 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>

Now your behat.yml file should be at app/config/behat.yml with belo content :

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

All you go, now add your feature and context file at namespace : NameSpace\YourBundle\Features\Context\FeatureContext

and run the below commands from command prompt/git bash(preferrable):

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

or if you want to save the output as html at web/behat directory then:

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

Let me know if it works

Note: I am not sure if you are running selenium server or standalone server, hence adding the step to run selenium standalone server:

Download selenium and chromedriver and place the selenium server .exe and chromedriver.exe in same folder check with "java -version" and it should not be < 1.6.x you may need to download compatible selenium server and chrome driver open command prompt and run the below commands:

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


转载请标明出处:Symfony2 Extension - Behat Mink
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!