Symfony2 Extension - Behat Mink

前端 未结 1 565
暗喜
暗喜 2021-01-24 01:50

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

[ReflectionException] Class AppKernel does not exist.

<
1条回答
  •  孤城傲影
    2021-01-24 01:52

    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:

    
        DocumentRoot "C:/xampp/htdocs/behat/web"
        ServerName lochost.behat
        DirectoryIndex app_dev.php
        
            Order deny,allow
            Allow from all
            
    
    

    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:\
    java -Dwebdriver.chrome.driver="chromedriver.exe" -jar selenium-server-standalone-x.xx.0.jar
    

    0 讨论(0)
提交回复
热议问题