baseclass / Contrib.SpecFlow.Selenium.NUnit

Test class generator to drive automated web ui tests with Selenium and SpecFlow
http://www.nuget.org/packages/Baseclass.Contrib.SpecFlow.Selenium.NUnit/
22 stars 13 forks source link

Baseclass.Contrib.SpecFlow.Selenium.NUnit

Test class generator to drive automated web ui tests with Selenium and SpecFlow.

Configures SpecFlow to be able to easily use Selenium for WebTesting.

Creating automated web tests to test an application in addition to testing the application with unit tests is a good practice. SpecFlow supports behavior driven development and acceptance tests driven development.

This project was created to be able to use Selenium with SpecFlow as easy as possible, and at the same time to be able to use it in a Continuos Integration Environment.

Release notes:

1.1 Added support for passing desired capabilities to the RemoteWebDriver.

Example using SauceLabs as remote web driver: http://www.baseclass.ch/blog/Lists/Beitraege/Post.aspx?ID=5&mobile=0

Features:

Get it from Nuget.org:

https://www.nuget.org/packages/Baseclass.Contrib.SpecFlow.Selenium.NUnit/

Before

Scenario Outline: Add Two Numbers

Given I navigated to / using <browser>
And I have entered <summandOne> into summandOne calculator
And I have entered <summandTwo> into summandTwo calculator
When I press add
Then the result should be <result> on the screen
Scenarios:
| browser| summandOne| summandTwo|result|
| Chrome | 10 | 20 | 30 |
| Firefox | 10 | 20 | 30 |
| IE | 10 | 20 | 30 |
| Chrome | 3 | 4 | 7 |
| Firefox | 3 | 4 | 7 |
| IE | 3 | 4 | 7 |

After

@Browser:IE
@Browser:Chrome
@Browser:Firefox
Scenario Outline: Add Two Numbers

Given I navigated to / using
And I have entered <summandOne> into summandOne calculator
And I have entered <summandTwo> into summandTwo calculator
When I press add
Then the result should be <result> on the screen
Scenarios:
| summandOne| summandTwo|result|
| 10 | 20 | 30 |
| 3 | 4 | 7 |


Blogpost: http://www.baseclass.ch/blog/Lists/Beitraege/Post.aspx?ID=4&mobile=0


Using SpecFlow with Selenium without Baseclass.Contrib.SpecFlow.Selenium.NUnit

As I've started with the first test scenario using Selenium i've end up with something like this:

Scenario: Add Two Numbers

Given I navigated to /
And I have entered 10 into summandOne calculator
And I have entered 20 into summandTwo calculator
When I press add
Then the result should be 30 on the screen

Pretty easy to test a simple web page containing a calculator.

Then I decided to take it further and specifiy on what browser I want to support this scenario:

Scenario: Add Two Numbers

Given I navigated to / using Chrome
And I have entered 10 into summandOne calculator
And I have entered 20 into summandTwo calculator
When I press add
Then the result should be 30 on the screen

The first test step is easy to write. Use an IOC-Container to resolve the configured IWebDriver with the specified browser name.

this.driver = this.container.ResolveNamed<OpenQA.Selenium.IWebDriver>(browser)

So now I want the same test to run in InternetExplorer, instead of multiplying the scenario I use gherkin's Scenario Outline feature:

Scenario Outline: Add Two Numbers

Given I navigated to / using <browser>
And I have entered 10 into summandOne calculator
And I have entered 20 into summandTwo calculator
When I press add
Then the result should be 30 on the screen
Scenarios:
| *browser*|
| Chrome |
| IE |
| Firefox |

Do you see the combinatory explosion coming? What if I actually want to use the scenario outline for what it was supposed to? Like specifying the summands it the scenarios:

Scenario Outline: Add Two Numbers

Given I navigated to / using <browser>
And I have entered <summandOne> into summandOne calculator
And I have entered <summandTwo> into summandTwo calculator
When I press add
Then the result should be <result> on the screen
Scenarios:
| browser| summandOne| summandTwo|result|
| Chrome | 10 | 20 | 30 |
| Firefox | 10 | 20 | 30 |
| IE | 10 | 20 | 30 |
| Chrome | 3 | 4 | 7 |
| Firefox | 3 | 4 | 7 |
| IE | 3 | 4 | 7 |

and so on.

Wouldn't it be nice to write the scenario like that:

@Browser:IE
@Browser:Chrome
@Browser:Firefox
Scenario Outline: Add Two Numbers

Given I navigated to / using
And I have entered <summandOne> into summandOne calculator
And I have entered <summandTwo> into summandTwo calculator
When I press add
Then the result should be <result> on the screen
Scenarios:
| summandOne| summandTwo|result|
| 10 | 20 | 30 |
| 3 | 4 | 7 |


Bindings

Until now I've included one binding:

Regex: I navigated to (.*)
Example Usage for navigating to Root:
Given I navigated to /

Logic:

Looks for the seleniumBaseUrl in the App settings and navigates with to the concatonated url of {seleniumBaseUrl}{passedUrl}

<appSettings>
    <add key="seleniumBaseUrl" value="http://localhost:58909" />
</appSettings>

githalytics.com alpha