This is the first part of many on how to use Spectacular, an open-source acceptance test / behavior driven development tool for development teams. This installment will focus on how to use Spectacular to create Executable Use Cases, and how those use cases can be executed using Selenese to drive a Selenium browser!
Part of why I wanted to write a tool like Spectacular is that I wanted to explore the possibility of using simplified Use Cases in the context of Epics in order to describe the overall requirement, in addition to using that Use Case to assist in creating stories during a story workshop. Of course, the one thing bugging me about the whole subject is that I would also want those Use Cases to be completely testable. Enter Executable Use Cases.
The idea works like this: Let’s say that during a story mapping workshop, an agile team identified an Epic/Activity for logging into a system as an existing user. They collaborated on a simple diagram showing how this would work:

Using this web-flow diagram as a guide, the team can now start to write a simplified use case in order to weed out some details and describe the user flow and interactions. In Spectacular, the requirement for a Use Case is to create a table with at least 2 columns (though 3 or more is typical, to describe ancillary details). The first row should be the title of the use case, with the word “Flow” in there (i.e. “Primary Flow: Log In” or “Alternate Flow: Remember Me Log In”). The next row are the column headers (“User Action”, “Expectation), followed by the use case itself. Additional columns are ignored by Spectacular:
| Primary Flow: | Log In | |
| User Action | Expectation | Comments |
| User navigates to system home page. | User sees system home page with a header of “Home Page” | |
| User clicks login link | User sees a login form requesting credentials | Credentials include username, password. Should include a button for submission of form as well |
| User enters credentials and submits form | User sees a landing page with a list of submitted articles | |
Now that the team has written a use case, its time to make it executable. Many of the use cases I run into with my Agile teams are user-interaction based, which is what inspired me to giving user the ability to express a use case as a series of Selenese commands (in addition to writing the fixtures in Java, Ruby, and Groovy). Once the team has agreed to the use case details (and brainstormed user stories from this i.e. bad login, already logged in, etc.), the team opens up a text editor or IDE and writes the fixture in Selenese:
Flow: User navigates to system home page.
open "/"
waitForPageToLoad 5000
Expectation: User sees system home page with a header of "Home Page"
verifyText "xpath://h1[class='mainHeader']" "Home Page"
verifyText "id=loginLink" "Login"
Flow: User clicks login link
click "id=loginLink"
waitForPageToLoad 5000
Expectation: User sees a login form requesting credentials
verifyElementPresent "id=usernameLogin"
verifyElementPresent "id=passwordLogin"
verifyElementPresent "xpath://input[@class='loginButton']"
Flow: User enters credentials and submits form
type "id=usernameLogin" "myusername"
type "id=passwordLogin" "mypassword"
click "xpath://input[@class='loginButton']"
waitForPageToLoad 5000
Expectation: User sees a landing page with a list of submitted articles
verifyTitle "Welcome Michael!"
verifyElementPresent "xpath://div[@class='article']"
Make sense? The Selenese code above in a text file in effect becomes the fixture code for our executable use case. Executing Spectacular would look like (assuming we named the Selenese file “login.selenese” and the spec as “SystemSpec.html”):
> Spectacular -fixtures ./login.selenese -specLocation ./SystemSpec.html -seleniumRCHost localhost -seleniumRCPort 4444 -seleniumRCInitialUrl http://system-uat/ -seleniumRCStartCommand *safari
(don’t worry, these commands can be stored in a project xml file so that running Spectacular doesn’t require such a long command line
)
By default, results are output in the current directory as “TestResults.html”, which will be the same document the team wrote, but with annotated test results in the use case table. In our case, we haven’t written any implementation code yet, so it would look like this:
| Primary Flow: | Log In | |
| User Action | Expectation | Comments |
| User navigates to system home page. (FAIL) SeleniumException: URL “http://system-uat/” not available | User sees system home page with a header of “Home Page” (NOT PERFORMED) | |
| User clicks login link (NOT PERFORMED) | User sees a login form requesting credentials (NOT PERFORMED) | Credentials include username, password. Should include a button for submission of form as well |
| User enters credentials and submits form (NOT PERFORMED) | User sees a landing page with a list of submitted articles (NOT PERFORMED) | |
This is the essence of writing Executable Use Cases with Spectacular. For more details about how to write them or how to write the fixtures using other methods, visit the Spectacular EUC documentation.
Next in the “Using Spectacular” series, I’ll focus on how to document the executable use cases along with FIT and Gherkin/BDD tests and what they look like…





