<commit_before># SilverStripe Integration for Behat

[![Build Status](https://travis-ci.org/silverstripe-labs/silverstripe-behat-extension.svg?branch=master)](https://travis-ci.org/silverstripe-labs/silverstripe-behat-extension)

## Overview

[Behat](http://behat.org) is a testing framework for behaviour-driven development.
Because it primarily interacts with your website through a browser, 
you don't need any specific integration tools to get it going with
a basic SilverStripe website, simply follow the 
[standard Behat usage instructions](http://docs.behat.org/).

This extension comes in handy if you want to go beyond
interacting with an existing website and database,
for example make changes to your database content which
would need to be rolled back to a "clean slate" later on.

It provides the following helpers:

 * Provide access to SilverStripe classes in your Behat contexts
 * Set up a temporary database automatically
 * Reset the database content on every scenario
 * Prebuilt Contexts for SilverStripe's login forms and other common tasks
 * Creating of member fixtures with predefined permissions
 * YML fixture definitions inside your Behat scenarios
 * Waiting for jQuery Ajax responses (rather than fixed wait timers)
 * Captures JavaScript errors and logs them through Selenium
 * Saves screenshots to filesystem whenever an assertion error is detected

In order to achieve this, the extension makes one basic assumption:
Your Behat tests are run from the same application as the tested
SilverStripe codebase, on a locally hosted website from the same codebase.
This is important because we need access to the underlying SilverStripe
PHP classes. You can of course use a remote browser to do the actual testing.

Note: The extension has only been tested with the `selenium2` Mink driver.

## Installation

Simply [install SilverStripe through Composer](http://doc.silverstripe.org/framework/en/installation/composer).
Skip this step if adding the module to an existing project.

	composer create-project silverstripe/installer my-test-project 3.1.x-dev

Switch to the newly created webroot, and add the SilverStripe Behat extension.

	cd my-test-project
	composer require "silverstripe/behat-extension:*"

Now get the latest Selenium2 server (requires Java):

	wget http://selenium-release.storage.googleapis.com/2.44/selenium-server-standalone-2.44.0.jar

On OSX, you can also use [Homebrew](http://brew.sh/): `brew install selenium-server-standalone`.
If you are having issues running Selenium with your browser please check 
that you're on the [latest driver](https://code.google.com/p/selenium/downloads/list),
since the download link above might be out of date.

Download the latest [Firefox ESR](https://www.mozilla.org/en-US/firefox/organizations/all/) (Extended Support Release).
It might be older than your currently installed Firefox.
It's important to have a browser that's [supported by Selenium-Webdriver](http://docs.seleniumhq.org/docs/01_introducing_selenium.jsp#selenium-webdriver)

Now install the SilverStripe project as usual by opening it in a browser and following the instructions.
Protip: You can skip this step by using `[SS_DATABASE_CHOOSE_NAME]` in a global 
[`_ss_environment.php`](http://doc.silverstripe.org/framework/en/topics/environment-management) 
file one level above the webroot.

Unless you have [`$_FILE_TO_URL_MAPPING`](http://doc.silverstripe.org/framework/en/topics/commandline#configuration)
set up, you also need to specify the URL for your webroot. Either add it to the existing `behat.yml` configuration file
in your project root, or set is as an environment variable in your terminal session: 

	export BEHAT_PARAMS="extensions[SilverStripe\BehatExtension\MinkExtension][base_url]=http://localhost/"

## Usage

### Prevent Firefox from Automatically Updating

The moment you open Firefox, it's going to try and update itself out of the stone age. To prevent this, open a new tab and go to `about:config`. There, change the following settings to `false`:

- `app.update.auto`
- `app.update.enabled`
- `app.update.silent`

Firefox will already have started the update, so close and delete it. The settings you changed should be stored as preferences, apart from the application files you've just deleted. Reinstall that ancient version. The next time you open it, and go to "About Firefox", you should see a button desperately pleading with you to "check for updates". Don't click that if you know what's good for you...

### Starting the Selenium Server

You can run the server locally in a separate Terminal session:

    java -jar selenium-server-standalone-2.41.0.jar

In some cases it may be necessary to start a specific version of firefox

	java -jar selenium-server-standalone-2.41.0.jar -Dwebdriver.firefox.bin="/Applications/Firefox26.app/Contents/MacOS/firefox-bin"

### Running the Tests

Now you can run the tests (for example for the `framework` module):

	vendor/bin/behat @framework
<commit_msg>Update documentation to match travis firefox 31ESR<commit_after># SilverStripe Integration for Behat

[![Build Status](https://travis-ci.org/silverstripe-labs/silverstripe-behat-extension.svg?branch=master)](https://travis-ci.org/silverstripe-labs/silverstripe-behat-extension)

## Overview

[Behat](http://behat.org) is a testing framework for behaviour-driven development.
Because it primarily interacts with your website through a browser, 
you don't need any specific integration tools to get it going with
a basic SilverStripe website, simply follow the 
[standard Behat usage instructions](http://docs.behat.org/).

This extension comes in handy if you want to go beyond
interacting with an existing website and database,
for example make changes to your database content which
would need to be rolled back to a "clean slate" later on.

It provides the following helpers:

 * Provide access to SilverStripe classes in your Behat contexts
 * Set up a temporary database automatically
 * Reset the database content on every scenario
 * Prebuilt Contexts for SilverStripe's login forms and other common tasks
 * Creating of member fixtures with predefined permissions
 * YML fixture definitions inside your Behat scenarios
 * Waiting for jQuery Ajax responses (rather than fixed wait timers)
 * Captures JavaScript errors and logs them through Selenium
 * Saves screenshots to filesystem whenever an assertion error is detected

In order to achieve this, the extension makes one basic assumption:
Your Behat tests are run from the same application as the tested
SilverStripe codebase, on a locally hosted website from the same codebase.
This is important because we need access to the underlying SilverStripe
PHP classes. You can of course use a remote browser to do the actual testing.

Note: The extension has only been tested with the `selenium2` Mink driver.

## Installation

Simply [install SilverStripe through Composer](http://doc.silverstripe.org/framework/en/installation/composer).
Skip this step if adding the module to an existing project.

	composer create-project silverstripe/installer my-test-project 3.1.x-dev

Switch to the newly created webroot, and add the SilverStripe Behat extension.

	cd my-test-project
	composer require "silverstripe/behat-extension:*"

Now get the latest Selenium2 server (requires Java):

	wget http://selenium-release.storage.googleapis.com/2.44/selenium-server-standalone-2.44.0.jar

On OSX, you can also use [Homebrew](http://brew.sh/): `brew install selenium-server-standalone`.
If you are having issues running Selenium with your browser please check 
that you're on the [latest driver](https://code.google.com/p/selenium/downloads/list),
since the download link above might be out of date.

Download the latest [Firefox ESR](https://www.mozilla.org/en-US/firefox/organizations/all/) (Extended Support Release).
It might be older than your currently installed Firefox.
It's important to have a browser that's [supported by Selenium-Webdriver](http://docs.seleniumhq.org/docs/01_introducing_selenium.jsp#selenium-webdriver)

Now install the SilverStripe project as usual by opening it in a browser and following the instructions.
Protip: You can skip this step by using `[SS_DATABASE_CHOOSE_NAME]` in a global 
[`_ss_environment.php`](http://doc.silverstripe.org/framework/en/topics/environment-management) 
file one level above the webroot.

Unless you have [`$_FILE_TO_URL_MAPPING`](http://doc.silverstripe.org/framework/en/topics/commandline#configuration)
set up, you also need to specify the URL for your webroot. Either add it to the existing `behat.yml` configuration file
in your project root, or set is as an environment variable in your terminal session: 

	export BEHAT_PARAMS="extensions[SilverStripe\BehatExtension\MinkExtension][base_url]=http://localhost/"

## Usage

### Prevent Firefox from Automatically Updating

The moment you open Firefox, it's going to try and update itself out of the stone age. To prevent this, open a new tab and go to `about:config`. There, change the following settings to `false`:

- `app.update.auto`
- `app.update.enabled`
- `app.update.silent`

Firefox will already have started the update, so close and delete it. The settings you changed should be stored as preferences, apart from the application files you've just deleted. Reinstall that ancient version. The next time you open it, and go to "About Firefox", you should see a button desperately pleading with you to "check for updates". Don't click that if you know what's good for you...

### Starting the Selenium Server

You can run the server locally in a separate Terminal session:

    java -jar selenium-server-standalone-2.41.0.jar

In some cases it may be necessary to start a specific version of firefox

	java -jar selenium-server-standalone-2.41.0.jar -Dwebdriver.firefox.bin="/Applications/Firefox31.app/Contents/MacOS/firefox-bin"

### Running the Tests

Now you can run the tests (for example for the `framework` module):

	vendor/bin/behat @framework

{'fraction_non_alphanumeric': 0.07274907564704707, 'fraction_numerical': 0.0047966423503547516, 'mean_word_length': 4.849210987726476, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2290595', 'n_tokens_mistral': 2831, 'n_tokens_neox': 2665, 'n_words': 1196}