Acceptance testing with Geb


Published on

Slides for a talk I present at SkillsMatter.

This talk will cover the basics of using Geb to automate browser testing.
It will compare Geb with raw WebDriver/Selenium showing Geb's expressive Groovy API.
It will also demonstrate how to integrate Geb with acceptance testing frameworks, namely Cucumber via Cuke4Duke.

We will also cover an experience report on how and why we transitioned from raw WebDriver to Geb and how existing WebDriver projects can be ported across to Geb with minimal initial effort due to its underlying use of WebDriver.

Published in: Technology
1 Comment
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Acceptance testing with Geb

  1. 1. Acceptance Testing with Geb cucumber, cuke4duke, groovy, geb, webdriver, selenium, bdd, teamcityRichard Paul 2011-01-26
  2. 2. Talk Overview Introduction to the testing technologies Experience report at F1000
  3. 3. Testing Stack Maven Cucumber Geb WebDriver Browser
  4. 4. Cuke4DukeAllow Cucumber to be run on the JVM via JRubyAll programming can be done in Java Groovy Scala ...Good fit for teams already fluent in JVM languages.
  5. 5. Features - Wikipedia ExampleFeature: Search In order to learn more As an information seeker I want to find more information Scenario: Im feeling lucky Given I am on the Wikipedia homepage When I search for "dog" Then I am shown the "Dog" article
  6. 6. Step Definitions - Wikipedia ExampleGiven(~I am on the Wikipedia homepage) { browser.go()}When(~I search for "(.+)") { query -> browser.find(#searchInput).value(query) browser.find(#searchButton).click()}Then(~I am shown the "(.+)" article) { article -> assert browser.find(h1).text() == article}
  7. 7. Where does the browser come from?import geb.Browserthis.metaClass.mixin(cuke4duke.GroovyDsl)Before { browser = new Browser(}After { browser.driver.manage().deleteAllCookies()}
  8. 8. Geb - Very Groovy BrowserAutomation an expressive API for interacting with webbrowsers.Excellent documentation provided by the manual.
  9. 9. Geb - Frequently used APIsgo(/search)$(#query).value(dog)$(#query).value() == dog$(#submit).click()Covers 90% of use cases
  10. 10. Geb - Form Shortcutsdef form = $(#register)form.firstname = Richardform.lastname = = http://rapaul.comform.submit()// Shortcut forform.find(input[name=firstname]).value(Richard)// Similarly can inspect withassert form.firstname == Richard
  11. 11. Geb & WebDriverGeb uses WebDriver under the hood.Automatically chooses a driver based on classpath. HtmlUnit Firefox IE ChromeCan select a specific driver using geb.driver property.
  12. 12. WebDriver to Geb MigrationStarting with WebDriver APIbrowser.findElementByCssSelector(.x)Change browser from WebDriver to Gebbrowser.driver.findElementByCssSelector(.x)Refactor when working in that areabrowser.find(.x)
  13. 13. Groovys PowerAssertPowerAssert shows values for intermediary statementsassert $(.divTop20item strong)*.text() =~ English | | | [] [] ..regex..Can tell if the selector matched elements or if the textactual text didnt match without needing to rerun scenario.
  14. 14. Geb & the Page Object PatternDefines a Content DSL for encapsulating reusable aspects of apage.Modules for page fragments.We use Cucumbers steps as the item of reuse so dont use thePage Object Pattern.
  15. 15. Advantages of Geb (over WebDriver) Expressive API Caching of WebDriver between scenarios All the power of underlying WebDriver if needed
  16. 16. Acceptance Testing @ F1000 2 week iterations, releasing every iteration Story wall with columns Sprint backlog, specify, dev/test, done Acceptance tests written with Cucumber Outside in development Acceptance tests drive view layer View layer drivers controller Controller drives service ... Acceptance & unit tests running in CI (TeamCity)
  17. 17. TeamCity3 separate builds in TeamCity Key Features (tagged with @keyfeature) Non Key Features Work in Progress (tagged with @wip) Any WIP scenarios that pass fail the buildCucumber supports JUnit report format Instant notification on first failure Build statisticsMore detail at:
  18. 18. Lessons LearnedThe Why & What are so much harder than the How Identifying the value (In order to) is difficult Important to have all team members in planning session Declarative steps instead of imperative trails of clicked GUI itemsSmall slices Vertical slicing (pairing for knowledge gaps) As small as possible Initial search had no sorting, paging, filtering etc Feature Toggles YAGNI
  19. 19. Lessons Learned (continued)Confidence in acceptance tests is critical 8 hours does not give confidence Flakey tests should be refactoredForgetting details for features near end of iteration Writing up full features & scenarios during planning is time consuming. Capture important details on back of card.Getting stakeholders to look at Cucumber reports is hard Marking up key features
  20. 20. Tips for working with CucumberTag (@now) to just run the scenario you are working onFind unused steps with --format usage --dry-runCuke4Duke with Groovy uses a lot of memory Both heap and PermGen, RAM is cheap
  21. 21. Discussion/Questions Thanks! @rapaul