Learn how to write clean, clear, maintainable automated acceptance tests for both web applications and web services using Serenity BDD (http://serenity-bdd.info). Serenity BDD is an open source library that helps you write better, more effective automated acceptance tests, and use these acceptance tests to produce world-class test reports and living documentation.
6. @wakaleo
Separation of Concerns - Layers
Goals
Tasks
Actions
What are you trying to achieve?
What do you need to do to achieve
this goal?
What interactions with the
system do you need for each
task?
7. @wakaleo
Separation of Concerns - Layers
Scenario: Add a new todo entry on the todo home page
Given I am on the Todo application home page
When I enter 'Buy some milk' into the New Todo field
And I press ENTER
Then the todo list box should contain 'Buy some milk'
8. @wakaleo
Separation of Concerns - Layers
Scenario: Record a new todo action for future use
Given I need to buy some milk
When I add the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in my todo list
12. @wakaleo
The Serenity layered architecture
Goals
Tasks
Interactions
Tests or scenarios
“Steps”
Page Objects or other technical
components
13. @wakaleo
The Serenity layered architecture
Feature: Add new todos
James needs to be able to jot down actions he needs to do as he
thinks of them
Scenario: Record a new todo action for future use
Given James needs to buy some milk
When James adds the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in his todo list
14. @wakaleo
The Serenity layered architecture
Feature: Add new todos
James needs to be able to jot down actions he needs to do as he
thinks of them
Scenario: Record a new todo action for future use
Given James needs to buy some milk
When James adds the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in his todo list
A goal
15. @wakaleo
The Serenity layered architecture
Feature: Add new todos
James needs to be able to jot down actions he needs to do as he
thinks of them
Scenario: Record a new todo action for future use
Given James needs to buy some milk
When James adds the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in his todo list
A goal
A task
16. @wakaleo
The Serenity layered architecture
Feature: Add new todos
James needs to be able to jot down actions he needs to do as he
thinks of them
Scenario: Record a new todo action for future use
Given James needs to buy some milk
When James adds the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in his todo list
A goal
A task
@Steps ATodoUser james;
@When(“^(?:.*) (?:adds|has added) the todo action '(.*)'$")
public void i_add_the_todo_action(String actionName) {
james.adds_an_action_called(actionName);
}
17. @wakaleo
The Serenity layered architecture
Feature: Add new todos
James needs to be able to jot down actions he needs to do as he
thinks of them
Scenario: Record a new todo action for future use
Given James needs to buy some milk
When James adds the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in his todo list
A goal
A task
@Steps ATodoUser james;
@When(“^(?:.*) (?:adds|has added) the todo action '(.*)'$")
public void i_add_the_todo_action(String actionName) {
james.adds_an_action_called(actionName);
}
The task definition
18. @wakaleo
The Serenity layered architecture
Feature: Add new todos
James needs to be able to jot down actions he needs to do as he
thinks of them
Scenario: Record a new todo action for future use
Given James needs to buy some milk
When James adds the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in his todo list
A goal
A task
@Steps ATodoUser james;
@When(“^(?:.*) (?:adds|has added) the todo action '(.*)'$")
public void i_add_the_todo_action(String actionName) {
james.adds_an_action_called(actionName);
}
The task definition
TodoPage onTheTodoHomePage;
@Step
public void adds_an_action_called(String actionName) {
onTheTodoHomePage.addAnActionCalled(actionName);
}
19. @wakaleo
The Serenity layered architecture
Feature: Add new todos
James needs to be able to jot down actions he needs to do as he
thinks of them
Scenario: Record a new todo action for future use
Given James needs to buy some milk
When James adds the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in his todo list
A goal
A task
@Steps ATodoUser james;
@When(“^(?:.*) (?:adds|has added) the todo action '(.*)'$")
public void i_add_the_todo_action(String actionName) {
james.adds_an_action_called(actionName);
}
The task definition
TodoPage onTheTodoHomePage;
@Step
public void adds_an_action_called(String actionName) {
onTheTodoHomePage.addAnActionCalled(actionName);
}
An interaction
20. @wakaleo
Serenity for Living Documentation
Feature: Add new todos
I need to be able to jot down actions I need to do as fast as I think of them
Scenario: Record a new todo action for future use
Given I need to buy some milk
When I add the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in my todo list
21. @wakaleo
Serenity for Living Documentation
Feature: Add new todos
I need to be able to jot down actions I need to do as fast as I think of them
Scenario: Record a new todo action for future use
Given I need to buy some milk
When I add the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in my todo list
26. @wakaleo
The Journey Pattern - A User-Centric model
Actors have goals I’d like to be able to recall all
the things I need to do
Meet James
27. @wakaleo
The Journey Pattern - A User-Centric model
Actors have abilities I can browse the web with my
browser
I can also query REST services
28. @wakaleo
I’d like to be able to recall all
the things I need to do
The Journey Pattern - A User-Centric model
Actors perform tasks
I’ll add ‘Buy some milk’ to my
todo list
29. @wakaleo
I’d like to be able to recall all
the things I need to do
The Journey Pattern - A User-Centric model
Actors may interact with the system to
perform these tasks
I’ll add ‘Buy some milk’ to my
todo list
Type ‘Buy the milk’
Press ‘ENTER’
30. @wakaleo
The Journey Pattern in Serenity
Actors have goals I’d like to be able to recall all
the things I need to do
31. @wakaleo
The Journey Pattern in Serenity
Actors have goals
Feature: Add new todos
James would like to be able to recall all the things he needs to do
Scenario: Record a new todo action for future use
Given James needs to buy some milk
When James adds the todo action 'Buy some milk'
Then 'Buy some milk' should be recorded in his todo list
I’d like to be able to recall all
the things I need to do
32. @wakaleo
A User-Centric model
Actors have abilities I can browse the web with my
browser
Actor james = Actor.named(“James");
@Managed
WebDriver hisBrowser;
…
james.can(BrowseTheWeb.with(hisBrowser));
33. @wakaleo
A User-Centric model
Actors perform tasks I’ll add ‘Buy some milk’ to my
todo list
@Steps
AddItem addATodoItem;
…
james.attemptsTo(addATodoItem.called("Buy some milk"));
34. @wakaleo
A User-Centric model
Actors perform tasks I’ll add ‘Buy some milk’ to my
todo list
@Steps
AddItem addATodoItem;
…
james.attemptsTo(addATodoItem.called("Buy some milk"));
actor.attemptsTo(
Enter.theValue(thingToDo).into(ToDoList.NEW_TODO_FIELD),
Hit.the(RETURN).keyIn(ToDoList.NEW_TODO_FIELD)
);