PHPackages                             alnutile/business-selector-extension - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. alnutile/business-selector-extension

ActiveLibrary[Testing &amp; Quality](/categories/testing)

alnutile/business-selector-extension
====================================

CSS Selector Substitution For Behat

0.9.2(13y ago)04.6kMITPHPPHP &gt;=5.3.0

Since Sep 3Pushed 11y ago2 watchersCompare

[ Source](https://github.com/alnutile/business-selector-extension)[ Packagist](https://packagist.org/packages/alnutile/business-selector-extension)[ Docs](http://github.com/orangedigital/business-selector-extension)[ RSS](/packages/alnutile-business-selector-extension/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (4)Versions (14)Used By (0)

Business Selectors For Behat
============================

[](#business-selectors-for-behat)

[![Build Status](https://camo.githubusercontent.com/001a21bf1be9f4dcfe5f35cae92e3d14cb7a1450b6afbc6b041a117b7484d237/68747470733a2f2f7472617669732d63692e6f72672f616c6e7574696c652f627573696e6573732d73656c6563746f722d657874656e73696f6e2e706e673f6272616e63683d646576656c6f70)](https://travis-ci.org/alnutile/business-selector-extension)

Introduction
------------

[](#introduction)

\--

The original project can be seen here

And many notes still apply below. I needed to simplify it a bit for the project I am using it on though it still is extendable to to other projects.

Basically I do not want errors thrown if a token is not found since it can default back to the string the user used and then let Behat error out as needed

\--

The Mink Extension for Behat is an excellent way to quickly get up and running with web acceptance testing. It allows the user to specify HTML elements on the page using common attributes like 'title', 'alt' and 'value'. Some steps allow the use of CSS selectors inline in the Gherkin files.

While this approach is great it has a few draw backs:

1. The attribute values may not always be the most business friendly and can reduce the readability of the Gherkin scenarios.
2. Sometimes it isn't possible to identify an element using the attributes the MinkExtension provides.
3. By using these attributes directly in the Gherkin files, they become tightly coupled to the front end implementation. Gherkin should express business requirements rather than implementation details.

Business Selectors for Behat allow the user to use steps very similar to the ones provided by the MinkExtension to describe elements on the page in business terms. At the time the test is run the business terms are swapped for a CSS selector which is maintained in a yml file.

### Example

[](#example)

#### Gherkin Written With Steps Provided By BusinessSelectorsExtension

[](#gherkin-written-with-steps-provided-by-businessselectorsextension)

```
Given I go to the page "Home Page"
When I follow the link "Add Subscription"
And I fill in the "first name box" field with "ben"
Then the "first name box" form field should contain "ben"
And I press the "test" button
And the "Widget" should contain "Area One Text"
```

The quoted values map to the values in the file configured in behat.yml by the parameter 'selectorFilePath'.

```
Add Subscription: "a.self-link"
first name box: "form#name_form input[name=first_name]"
test: "form#name_form input[name=submit]"
Widget: div#user_widget
```

Installation
------------

[](#installation)

The best way to install the contexts is by using composer.

1. For instructions on installing Behat see: [behat.org](http://behat.org/)
2. Add in the following to the composer.json of the project you'd like to test.

```
{
    "minimum-stability": "dev",
    "require": {
        "behat/behat": ">v2.4@stable",
        "orangedigital/business-selector-extension": "*"
    }
}
```

3. Add the OrangeDigital\\BusinessSelectorExtension\\Extension section to your behat.yml file as in the example below.

```
default:
    context:
        parameters:
            javascript_session: selenium
            browser: firefox
            show_cmd: open %s
    extensions:
        OrangeDigital\BusinessSelectorExtension\Extension:
          urlFilePath: urls.yml
          selectorFilePath: selectors.yml
          assetPath: path
          timeout: 30
          contexts:
            UIBusinessSelector: ~
        Behat\MinkExtension\Extension:
            base_url: "http://local.dev"
            default_session: goutte
            goutte: ~
            selenium: ~
            selenium2: ~
```

4. Amend your FeatureContext file to use the BusinessSelectorContext file.

```
