View on GitHub

specbind

Bridges the SpecFlow and popular UI automation frameworks to simplify acceptance tests.

The first step is most scenarios is to navigate to a page, similar to typing an address into the web browser. Most times this will be the home page, but you may also want to test navigation directly to a page (deep linking perhaps). To do this you would use the following step:

Verb Action
Given I navigated to the <page name> page
When, Then I navigate to the <page name> page

The <page name> parameter maps to the page class in code, and the navigation attribute attached to it. It then combines that with the base address of the site and commands the browser to navigate to that URL and ensures it navigates successfully. For more information on mapping pages and navigation, see [[Page Navigation Binding]]

In some cases, you may also need to provide parameters to that URL, say mimic a link generated by a URL to confirm a user’s e-mail address. SpecBind support this with a similar step:

Verb Action
Given I navigated to the <page name> page with parameters
When, Then I navigate to the <page name> page with parameters

The step is followed by a table with headers and a single row. Each column indicates a parameter name to fill in and the value is what get substituted. For example, if I want to navigate to the “Confirm User” page and specify a “User ID” value of 123 and a “Confirmation Token” value of “abc123”, it would look like:

When I navigate to the Confirm User page with parameters
|| User ID || Confirmation Token ||
| 12 | abc123 |

Checking if you are on the correct page

Similar to navigation, when you select a link or perform an action, the browser needs to know what page it is on so it can use the correct page to translate the interaction. This step is required any time you navigate or switch the pages without using the navigate step. To perform the check and switch the page context use the following step:

Verb Action
Given I was on the <page name> page
When, Then I am on the <page name> page

The <page name> parameter maps to the page class in code, and the navigation attribute attached to it. It then combines that with the base address of the site and commands the browser to navigate to that URL and ensures it navigates successfully. For more information on mapping pages and navigation, see [[Page Navigation Binding]]

This may also apply to a scenario where you want to change focus to a dialog or pop-up on the screen. A similar step is available to switch the context to the dialog or pop-up screen:

Verb Action
Given I was on the <property name> dialog
When, Then I am on the <property name> dialog

The <property name> parameter maps to a property on the current page that will return the HTML element that is the root of that dialog. This is to support most modern dialog design where the dialog is a HTML element within the page.

Waiting for a page

At times you may need to wait for a page become the URL (i.e. Login, Redirect etc.) In this scenario you can use the following:

Verb Action
Given I waited for the <page name> page
When, Then I wait for the <page name> page

This will wait the default timeout for that page to become the active URL. You can also specify the timeout if you need more or less time:

Verb Action
Given I waited <count> seconds for the <page name> page
When, Then I wait <count> seconds for the <page name> page

Selecting Items in a List

In the same way you may need to dig into a list on the page to enter data or click an item. Two steps are available to switch from the page context to the context of an item from the list.

Verb Action
Given I was on <property name> list item matching criteria <table>
When, Then I am on <property name> list item matching criteria <table>

The <property name> parameter maps to a property on the current page that is the list. The <table> is a criteria table similar to what is used in validation that you can use to find an item in the list. An example of this step would be:

When I am on Products list item matching criteria
|| Field || Rule || Value ||
| Product ID | Equals | 12 |

Select an item by order in the list:

Verb Action
Given I was on list <property name> item <item number>
When, Then I am on list <property name> item <item number>

The <property name> parameter maps to a property on the current page that is the list. The Item Number parameter is a numerical value for the item on the list to switch to.

At any point you can use the same command to switch back out to a different context.