SlideShare a Scribd company logo
Write tests in the end
               users' lingo




Speaker Name : Nikhil Fernandes,Chirag Doshi
Company Name : Thoughtworks Technologies
What is the #1 thing that goes
wrong in software projects ?
Communication
End user   BA   Dev




                Application




           QA
End user       BA        Dev




                                Application




                      QA
End user
           BA       Dev



                  Application


           QA
    Acceptance Criteria
Title:I want to login to the website




 Role:As a user



Action:I want to login into the website


Outcome:So that I can view exclusive content
Acceptance Criteria:

Scenario:Successful Login

Given:The user is on the login page


When:The user types username sam
AND the user types password 123456
AND the user clicks the login button

Then:The user should be directed to the home page
AND the page should display Welcome Sam message
Acceptance Criteria:

Scenario:Invalid Username

Given:The user is on the login page


When:The user types username wrong
AND the user types password 123456
AND the user clicks the login button


Then:The page should display Authentication failed
message
Imperative v/s Declarative
Acceptance Criteria
Title:Book Submision




Role:As a Librarian



Action:I want to add a new book


Outcome:So that members can borrow this book
Imperative

Acceptance Criteria:

Scenario:Successful Submission

Given:The librarian is on the admin page


When:he/she fills in the name as Programming in Objective-C 
AND fills in author as Stephen G Kochan
AND fill in tags as programming,iphone.

Then:The librarian should see a message...
'Successfully created book'
Declarative

Acceptance Criteria:

Scenario:Successful Submission

Given:The librarian is on the admin page


When:he/she adds a new book to the system


Then:The librarian should see a message...
'Successfully created book'
End user   BA   Dev




                Application




           QA
Three ways to build test
cases in the user's
language
1.Build abstractions in the code
2.Automate your acceptance criteria
3.IDE support for these automated
  acceptance criteria
1.Build abstractions in the
 code
2.Automate your acceptance criteria
3.IDE support for these automated
  acceptance criteria
Scenario Successful Login
Given the user is on the login page
AND the user type username sam
AND the user types password 123456
AND the user clicks the login button
Then the page should display Welcome Sam Message
@Test
public void shouldDisplayWelcomeMessageWhenUserSuccessfullyLogsIn(){

       selenium.click(LOGIN_LINK);
       selenium.waitForElementPresent(LOGIN_BUTTON);
       selenium.type(LOGIN_USERNAME_EDIT_FIELD, ”sam");
       selenium.type(LOGIN_PASSWORD_EDIT_FIELD, “123456");    
       selenium.click(LOGIN_BUTTON);
       selenium.waitForElementPresent("Welcome");
}


@Test
public void shouldDisplayErrorMessageWhenUserTriesLoginWithWrongUsername(){

       selenium.click(LOGIN_LINK);
       selenium.waitForElementPresent(LOGIN_BUTTON);
       selenium.type(LOGIN_USERNAME_EDIT_FIELD, ”wrong");
       selenium.type(LOGIN_PASSWORD_EDIT_FIELD, ”123456");    
       selenium.click(LOGIN_BUTTON);
       selenium.waitForElementPresent("Authentication Failed");
}
@Test
public void shouldDisplayWelcomeMessageWhenUserSuccessfullyLogsIn(){

       new LoginPage()
       .openLoginPage()
       .enterUserName('sam').enterPassword('123456')
       .login().verifySuccessfulLogin();
}


@Test
public void shouldDisplayErrorMessageWhenUserTriesLoginWithWrongUsername(){

       new LoginPage()
       .openLoginPage()
       .enterUserName('wrong').enterPassword('123456').
       login().verifyUserIsNotAuthenticated();
}
public class LoginPage {

private Selenium selenium;

public LoginPage(Selenium selenium) {
        this.selenium = selenium;
}

public LoginPage openLoginPage() {
        selenium.click(LOGIN_LINK);
        selenium.waitForElementPresent(LOGIN_BUTTON);
        return this;
}

public LoginPage enterUserName(String userName){
        selenium.type(LOGIN_USERNAME_EDIT_FIELD, userName);
        return this;
}
public LoginPage enterPassword(String password){
        selenium.type(LOGIN_PASSWORD_EDIT_FIELD, password);
        return this;
}

public LoginPage login(){
        selenium.click(LOGIN_BUTTON);
        return this;
}

public boolean verifyUserIsNotAuthenticated(){
        selenium.waitForElementPresent("Authentication Failed");
        return this;
}

public boolean verifySuccessfulLogin(){
        selenium.waitForElementPresent("Welcome");
        return this;
}

}
1.Build abstractions in the code

2.Automate your
 acceptance criteria
3.IDE support for these automated
  acceptance criteria
Write Tests in End Users’ Lingo
Scenario Successful Login
 Given the user is on the login page
 AND the user type username sam
 AND the user types password 123456
 AND the user clicks the login button
 Then the page should display Welcome Sam Message


Given 'the user is on the login page' do
         @browser.open('http://foobar.com/')
end

AND /the user types (w+) (w+)/ do |element,value|
        @browser.type(element, value)
end

AND /the user clicks (w+) button/ do |element|
        @browser.click element
        @browser.wait_for_page_to_load
end

Then /the page should display (.*) Message/ do |expected_textl|
        @browser.is_element_present("css=p['#{expected_text}']").should be_true
end
Scenario Invalid UserName
 Given the user is on the login page
 AND the user type username wrong
 AND the user types password 123456
 AND the user clicks the login button
 Then the page should display 'Authentication Failed' Message


Given 'the user is on the login page' do
         @browser.open('http://foobar.com/')
end

AND /the user types (w+) (w+)/ do |element,value|
        @browser.type(element, value)
end

AND /the user clicks (w+) button/ do |element|
        @browser.click element
        @browser.wait_for_page_to_load
end

Then /the page should display (.*) Message/ do |expected_textl|
        @browser.is_element_present("css=p['#{expected_text}']").should be_true
end
JBehave
Scenario Invalid UserName
 Given the user is on the login page
 AND the user type username wrong
 AND the user types password 123456
 AND the user clicks the login button
 Then the page should display 'Authentication Failed' Message


@Given("the user is on the login page")
public void theUserIsOnTheLoginPage() {
         LoginPage loginPage = new LoginPage();
         loginPage.verifyPresenceOfLoginButton();
}

@When("the user types username $username")
public void theUserTypesUsername(String username) {
         loginPage().typeUsername(username);
}

@When("the user types password $password")
public void theUserTypesPassword(String password) {
         loginPage().typePassword(password);
}
@When("clicks the login button")
public void clicksTheLoginButton() {
         loginPage().login();
}
@Then("the page should display $errorMessage Message")
public void thePageShouldDisplayErrorMessage(String errorMessage) {
         loginPage().verifyPresenceOfErrorMessage(errorMessage);
}
1.Build abstractions in the code
2.Automate your acceptance criteria

3.IDE support for these
 automated acceptance
 criteria
Write Tests in End Users’ Lingo
Write Tests in End Users’ Lingo
Thank You
chirag@thoughtworks.com

nikhil@thoughtworks.com

More Related Content

Write Tests in End Users’ Lingo

  • 1. Write tests in the end users' lingo Speaker Name : Nikhil Fernandes,Chirag Doshi Company Name : Thoughtworks Technologies
  • 2. What is the #1 thing that goes wrong in software projects ?
  • 4. End user BA Dev Application QA
  • 5. End user BA Dev Application QA End user BA Dev Application QA
  • 7. Title:I want to login to the website Role:As a user Action:I want to login into the website Outcome:So that I can view exclusive content
  • 8. Acceptance Criteria: Scenario:Successful Login Given:The user is on the login page When:The user types username sam AND the user types password 123456 AND the user clicks the login button Then:The user should be directed to the home page AND the page should display Welcome Sam message
  • 9. Acceptance Criteria: Scenario:Invalid Username Given:The user is on the login page When:The user types username wrong AND the user types password 123456 AND the user clicks the login button Then:The page should display Authentication failed message
  • 11. Title:Book Submision Role:As a Librarian Action:I want to add a new book Outcome:So that members can borrow this book
  • 12. Imperative Acceptance Criteria: Scenario:Successful Submission Given:The librarian is on the admin page When:he/she fills in the name as Programming in Objective-C  AND fills in author as Stephen G Kochan AND fill in tags as programming,iphone. Then:The librarian should see a message... 'Successfully created book'
  • 13. Declarative Acceptance Criteria: Scenario:Successful Submission Given:The librarian is on the admin page When:he/she adds a new book to the system Then:The librarian should see a message... 'Successfully created book'
  • 14. End user BA Dev Application QA
  • 15. Three ways to build test cases in the user's language
  • 16. 1.Build abstractions in the code 2.Automate your acceptance criteria 3.IDE support for these automated acceptance criteria
  • 17. 1.Build abstractions in the code 2.Automate your acceptance criteria 3.IDE support for these automated acceptance criteria
  • 18. Scenario Successful Login Given the user is on the login page AND the user type username sam AND the user types password 123456 AND the user clicks the login button Then the page should display Welcome Sam Message
  • 19. @Test public void shouldDisplayWelcomeMessageWhenUserSuccessfullyLogsIn(){ selenium.click(LOGIN_LINK); selenium.waitForElementPresent(LOGIN_BUTTON); selenium.type(LOGIN_USERNAME_EDIT_FIELD, ”sam"); selenium.type(LOGIN_PASSWORD_EDIT_FIELD, “123456");     selenium.click(LOGIN_BUTTON); selenium.waitForElementPresent("Welcome"); } @Test public void shouldDisplayErrorMessageWhenUserTriesLoginWithWrongUsername(){ selenium.click(LOGIN_LINK); selenium.waitForElementPresent(LOGIN_BUTTON); selenium.type(LOGIN_USERNAME_EDIT_FIELD, ”wrong"); selenium.type(LOGIN_PASSWORD_EDIT_FIELD, ”123456");     selenium.click(LOGIN_BUTTON); selenium.waitForElementPresent("Authentication Failed"); }
  • 20. @Test public void shouldDisplayWelcomeMessageWhenUserSuccessfullyLogsIn(){ new LoginPage() .openLoginPage() .enterUserName('sam').enterPassword('123456') .login().verifySuccessfulLogin(); } @Test public void shouldDisplayErrorMessageWhenUserTriesLoginWithWrongUsername(){ new LoginPage() .openLoginPage() .enterUserName('wrong').enterPassword('123456'). login().verifyUserIsNotAuthenticated(); }
  • 21. public class LoginPage { private Selenium selenium; public LoginPage(Selenium selenium) { this.selenium = selenium; } public LoginPage openLoginPage() { selenium.click(LOGIN_LINK); selenium.waitForElementPresent(LOGIN_BUTTON); return this; } public LoginPage enterUserName(String userName){ selenium.type(LOGIN_USERNAME_EDIT_FIELD, userName); return this; }
  • 22. public LoginPage enterPassword(String password){ selenium.type(LOGIN_PASSWORD_EDIT_FIELD, password); return this; } public LoginPage login(){ selenium.click(LOGIN_BUTTON); return this; } public boolean verifyUserIsNotAuthenticated(){ selenium.waitForElementPresent("Authentication Failed"); return this; } public boolean verifySuccessfulLogin(){ selenium.waitForElementPresent("Welcome"); return this; } }
  • 23. 1.Build abstractions in the code 2.Automate your acceptance criteria 3.IDE support for these automated acceptance criteria
  • 25. Scenario Successful Login Given the user is on the login page AND the user type username sam AND the user types password 123456 AND the user clicks the login button Then the page should display Welcome Sam Message Given 'the user is on the login page' do @browser.open('http://foobar.com/') end AND /the user types (w+) (w+)/ do |element,value| @browser.type(element, value) end AND /the user clicks (w+) button/ do |element| @browser.click element @browser.wait_for_page_to_load end Then /the page should display (.*) Message/ do |expected_textl| @browser.is_element_present("css=p['#{expected_text}']").should be_true end
  • 26. Scenario Invalid UserName Given the user is on the login page AND the user type username wrong AND the user types password 123456 AND the user clicks the login button Then the page should display 'Authentication Failed' Message Given 'the user is on the login page' do @browser.open('http://foobar.com/') end AND /the user types (w+) (w+)/ do |element,value| @browser.type(element, value) end AND /the user clicks (w+) button/ do |element| @browser.click element @browser.wait_for_page_to_load end Then /the page should display (.*) Message/ do |expected_textl| @browser.is_element_present("css=p['#{expected_text}']").should be_true end
  • 28. Scenario Invalid UserName Given the user is on the login page AND the user type username wrong AND the user types password 123456 AND the user clicks the login button Then the page should display 'Authentication Failed' Message @Given("the user is on the login page") public void theUserIsOnTheLoginPage() { LoginPage loginPage = new LoginPage(); loginPage.verifyPresenceOfLoginButton(); } @When("the user types username $username") public void theUserTypesUsername(String username) { loginPage().typeUsername(username); } @When("the user types password $password") public void theUserTypesPassword(String password) { loginPage().typePassword(password); }
  • 29. @When("clicks the login button") public void clicksTheLoginButton() { loginPage().login(); } @Then("the page should display $errorMessage Message") public void thePageShouldDisplayErrorMessage(String errorMessage) { loginPage().verifyPresenceOfErrorMessage(errorMessage); }
  • 30. 1.Build abstractions in the code 2.Automate your acceptance criteria 3.IDE support for these automated acceptance criteria