Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stephenharris/bf0159f35e920b45009f1f751a28d319 to your computer and use it in GitHub Desktop.
Save stephenharris/bf0159f35e920b45009f1f751a28d319 to your computer and use it in GitHub Desktop.
Running Behat on VVV

Running Behat on VVV

TODO:

  • How to copy plugins into place
  1. Configure Behat.yml

    Here I've used the details for http://local.wordpress-trunk.dev/:

    • Database: wordpress_trunk
    • DB Username: wp
    • DB Password wp
    # behat.yml
    default:
      suites:
        default:
          contexts:
            - FeatureContext:
                screenshot_dir: '%paths.base%/failed-scenarios/'
            - \StephenHarris\WordPressBehatExtension\Context\WordPressContext
            - \StephenHarris\WordPressBehatExtension\Context\WordPressLoginContext
            - \StephenHarris\WordPressBehatExtension\Context\PostTypes\WordPressPostContext
            - \StephenHarris\WordPressBehatExtension\Context\Terms\WordPressTermContext
            - \StephenHarris\WordPressBehatExtension\Context\Users\WordPressUserContext
            - \StephenHarris\WordPressBehatExtension\Context\Options\WordPressOptionContext
            - \StephenHarris\WordPressBehatExtension\Context\Plugins\WordPressPluginContext
            - \StephenHarris\WordPressBehatExtension\Context\WordPressAdminContext
            - \StephenHarris\WordPressBehatExtension\Context\WordPressEditPostContext
            - \StephenHarris\WordPressBehatExtension\Context\WordPressPostListContext
            - \StephenHarris\WordPressBehatExtension\Context\WordPressMailContext
    
      extensions:
         StephenHarris\WordPressBehatExtension:
           path: '/vagrant/www/wordpress-trunk/'
           connection:
             db: 'wordpress_trunk'
             username: 'wp'
             password: 'wp'
           mail:
             directory: '/tmp/mail'
         Behat\MinkExtension:
             base_url: 'http://local.wordpress-trunk.dev/'
             files_path: '%paths.base%/features/files/'
             goutte:
               guzzle_parameters:
                              curl.options:
                                 CURLOPT_SSL_VERIFYPEER: false
                                 CURLOPT_CERTINFO: false
                                 CURLOPT_TIMEOUT: 120
                              ssl.certificate_authority: false
             selenium2: ~
    
  2. Install Java

    (To run selenium)

    sudo apt-get update
    sudo apt-get install openjdk-7-jre-headless
    
  3. Install Firefox

    (Preferably v45.0.2) see https://gist.github.com/stephenharris/90bb468bf80e7f7b02e8b8afe694de4f

    We'll use firefox for our browser interactions when using Selenium (for @javascript tests).

  4. Install xvfb

    Xvfb is a display server that allows us to perform graphical operations in a headless (no screen) environment

    sudo apt-get install xvfb
    
  5. Create the following script (e.g in ci/ in your project root)

    # Used when waiting for stuff
    NAP_LENGTH=1
    SELENIUM_PORT=4444
    
    # Wait for a specific port to respond to connections.
    wait_for_port() {
        local PORT=$1
        while echo | telnet localhost $PORT 2>&1 | grep -qe 'Connection refused'; do
            echo "Connection refused on port $PORT. Waiting $NAP_LENGTH seconds..."
            sleep $NAP_LENGTH
        done
    }
    
    rm -f /tmp/.X0-lock
    
    Xvfb & export DISPLAY=localhost:0.0
    
    # Start Selenium
    wget http://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.1.jar
    java -jar selenium-server-standalone-2.53.1.jar -p $SELENIUM_PORT > /dev/null 2>&1 &
    
    # Wait for Selenium, if necessary
    wait_for_port $SELENIUM_PORT
    
    echo 'waiting to start tests...';
    sleep 5
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment