Selenium is a powerful open-source tool for automated web testing.
Let's see how we can easily use Selenium to run web-based stories.
Scenario: User searches for steps Given user is on home page When user clicks on Find Steps Then text is shown: "Patterns and methods matching the textual step" When user searches for "Given a threshold of 10.0" Then search returns: "Given a threshold of $threshold"
The objective in creating a DSL is to represent the business-domain functionality whilst abstracting away the details of the implementation, in this case the access to the web layer via a specific testing tool, such as Selenium. The same DSL should be re-usable with different testing tools.
The TraderWebSteps class is where all the Selenium magic happens:
Here we are using Page Objects to abstract the Selenium behaviour behind pages that specify the user interaction in more meaningful ways.
As always, we configure the use of TraderWebSteps in an embeddable runnable class, e.g.the JUnit-runnable TraderWebStories:
The @BeforeStories and @AfterStories annotations in the PerStoriesSeleniumSteps methods allow to start and stop the selenium server before and after stories are run. Users can of course override the default behaviour, but generally don't need to bother for most use cases. There are also a PerStory and PerScenario implementation.
NOTE: To get the Selenium based tests running in an automated way, you need to run both a webapp server (e.g. Jetty) and the Selenium server. See the trader runner stories examples for a way to do this using Maven.