0
Fluent Interfaces in Testing
@Test
public void testCheckResults() {

        startSeleniumSession("localhost", 8000, "firefox", "www.google.com");

   ...
@Test
public void shouldReturnResultsForGivenQuery() {
        new HomePage()
        .enterSearchString("vodQA infusion")...
Fluent Interface?

@Test
public void shouldReturnResultsForGivenQuery() {
          new HomePage()
          .enterSearchS...
Confused?
A different example
import static org.openqa.selenium.lift.Finders.*;
import static org.openqa.selenium.lift.Matchers.*;
....
assertThat
Examples

assertThat(searchResultsCount, greaterThan(10));

assertThat(username, equalTo("Anay"));

assertThat(currentTime...
Matchers




http://code.google.com/p/hamcrest/wiki/Tutorial
Thank You

anayak@thoughtworks.com
Anay - Fluent interfaces in testing
Anay - Fluent interfaces in testing
Upcoming SlideShare
Loading in...5
×

Anay - Fluent interfaces in testing

1,139

Published on

Anay Nayak
Organization: ThoughtWorks
Topic: Fluent interfaces in testing
Presented in vodQA - THE TESTING SPIRIT! on Oct 7, 2010 in ThoughtWorks, Pune

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,139
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Anay - Fluent interfaces in testing"

  1. 1. Fluent Interfaces in Testing
  2. 2. @Test public void testCheckResults() { startSeleniumSession("localhost", 8000, "firefox", "www.google.com"); Selenium selenium = session(); selenium.type("//input[@name="search"]", "vodQA infusion"); selenium.click("//form[@id='search']/a/span[text()='Go']"); selenium.waitForPageToLoad("300000"); selenium.isElementPresent("//div[@class='resultStats']"); verifyTrue(session().isTextPresent("the testing spirit")); }
  3. 3. @Test public void shouldReturnResultsForGivenQuery() { new HomePage() .enterSearchString("vodQA infusion").search() .validateResultsDisplayed() .validateSearchResult("the testing spirit"); } http://code.google.com/p/selenium/wiki/PageObjects @Test public void testCheckResults() { startSeleniumSession("localhost", 8000, "firefox", "www.google.com"); Selenium selenium = session(); selenium.type("//input[@name="search"]", "vodQA infusion"); selenium.click("//form[@id='search']/a/span[text()='Go']"); selenium.waitForPageToLoad("300000"); selenium.isElementPresent("//div[@class='resultStats']"); verifyTrue(session().isTextPresent("the testing spirit")); }
  4. 4. Fluent Interface? @Test public void shouldReturnResultsForGivenQuery() { new HomePage() .enterSearchString("vodQA infusion").search() .validateResultsDisplayed() .validateSearchResult("the testing spirit"); }
  5. 5. Confused?
  6. 6. A different example import static org.openqa.selenium.lift.Finders.*; import static org.openqa.selenium.lift.Matchers.*; ... @Test public void testHasAnImageSearchPage() { goTo("http://www.google.com"); assertPresenceOf(link("Images")); assertPresenceOf(atLeast(4), links().with(text(not(equalTo("Images"))))); clickOn(link("Images")); assertPresenceOf(title().with(text(equalTo("Google Image Search")))); } http://code.google.com/p/selenium/wiki/LiftStyleApi https://lift.dev.java.net/
  7. 7. assertThat
  8. 8. Examples assertThat(searchResultsCount, greaterThan(10)); assertThat(username, equalTo("Anay")); assertThat(currentTimeText, startsWith("Local time:")); assertThat(basket, new IsCollectionContaining<String>(equalTo("apples"))); assertThat(xml, hasXPath("/root/@type", equalTo("food")));
  9. 9. Matchers http://code.google.com/p/hamcrest/wiki/Tutorial
  10. 10. Thank You anayak@thoughtworks.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×