Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Functionally Testing Web Apps with Geb

1,510 views

Published on

Recorded at SpringOne2GX
Presenter: Allison Figus
Groovy Advanced Track

Geb is a Groovy implementation of Selenium. This talk is for devs who want to learn more about functional testing and QA who want an introduction to automated testing.

I’ll show a few examples of how to bring a test plan through pseudo code and into concrete code. There will be live demos of Geb tests driven by Spock. Finally, we’ll look at code; but we’ll also look behind the code to understand what it means and why Geb is a great way to do functional automated testing."

Published in: Technology
  • D0WNL0AD FULL ▶ ▶ ▶ ▶ http://1lite.top/4KxwV ◀ ◀ ◀ ◀
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Functionally Testing Web Apps with Geb

  1. 1. SPRINGONE2GX WASHINGTON, DC Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Functionally Testing Web Apps with Geb By Allison Figus @ErinWith2Ls
  2. 2. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Presentation Scope • What is Geb? • Survey of the testing ecosystem • Where does Geb fit in? • How does Geb do it better? • Selenium vs Geb • Design Patterns— Page Object, Data Driven • How to write Functional tests with Geb 2
  3. 3. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Geb is… • A standalone framework for Automated Functional Testing • A Page Object framework to be used with another test runner (jUnit, Spock, etc) for Automated Functional Testing • Spock • jUnit • Cucumber-JVM • TestNg 3
  4. 4. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What is Spock? • Test framework based on jUnit • Unit, Integration, and Functional tests • Can be used with Geb 4
  5. 5. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Important Groovy Points • Groovy derives from Java, but it is actually an (improper) superset of Java • (Most) Java can be compiled by the Groovy compiler • Groovy can be compiled by the Java compiler Java and Groovy can be used interchangeably A Groovy test suite can be a fully integrated part of a Java project • When used as a dynamic, duck-typing language, Groovy can be faster to develop in than Java 5
  6. 6. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Geb translates to Selenium WebDriver code 6
  7. 7. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The Testing Ecosystem 1. Unit 2. Integration 3. External 7
  8. 8. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The Testing Ecosystem Internal • Unit • Integration 8
  9. 9. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The Testing Ecosystem Internal • Unit • Integration External • Functional 9
  10. 10. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Functionally Testing an App 10 Application Back-end Automated Functional Tests Manual QA Application User Interface
  11. 11. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Functionally Testing a Web App 11 Automated Functional Tests Manual QA Server
  12. 12. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Functionally Testing a Web App 12 Automated Functional Tests Manual QA Server Geb (Groovy) PHP? .Net? JVM? Implementation Agnostic
  13. 13. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ History of Geb 13 WebDriver 2006 Selenium 2004 2010 Geb 2009 Selenium WebDriver
  14. 14. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ History of Geb 14 WebDriver 2006 Selenium 2004 2010 Geb 2009 Selenium WebDriver Selenium IDE
  15. 15. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Application Under Test— CLUE • Select a Suspect, Room, and Weapon • Click “Accuse!” • Reset Solution to play again • View and Create new Suspects/Rooms/Weapons 15
  16. 16. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Smoke Test Go to the Suspects page Verify presence of “Suspect List” header 16 <h1>Suspect List</h1>
  17. 17. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 17 Recording with Selenium IDE
  18. 18. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 18 Running Tests with Selenium IDE
  19. 19. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 19 Maintaining Tests with Selenium IDE UI Changes… <h1>Suspect List</h1> <h3>Suspect List</h3>
  20. 20. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 20 Maintaining Test with Selenium IDE
  21. 21. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Maintaining Tests with Selenium IDE • No encapsulation • Violation of open-closed principle • No debugger • Doesn’t scale • Not Data Driven 21
  22. 22. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Next Option: Selenium WebDriver • Encapsulation • Open-Closed • Debug with an IDE • Data Driven testing 22
  23. 23. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ public void testSuspectHeader() { WebDriver driver = new FirefoxDriver() String baseUrl = "http://localhost:8080" driver.get(baseUrl + "/") driver.findElement(By.linkText("Suspects")).click() assert "Suspect List" == driver.findElement(By.cssSelector("h1")).getText() driver.quit() } 23 Selenium WebDriver Example
  24. 24. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ public void testSuspectHeader() { WebDriver driver = new FirefoxDriver() String baseUrl = "http://localhost:8080" driver.get(baseUrl + "/") driver.findElement(By.linkText("Suspects")).click() assert "Suspect List" == driver.findElement(By.cssSelector("h1")).getText() driver.quit() } 24 Selenium WebDriver Example
  25. 25. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The WebDriver Interface 25
  26. 26. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ public void testSuspectHeader() { WebDriver driver = new FirefoxDriver() String baseUrl = "http://localhost:8080" driver.get(baseUrl + "/") driver.findElement(By.linkText("Suspects")).click() assert "Suspect List" == driver.findElement(By.cssSelector("h1")).getText() driver.quit() } 26 Selenium WebDriver Example
  27. 27. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ public void testSuspectHeader() { WebDriver driver = new FirefoxDriver() String baseUrl = "http://localhost:8080" driver.get(baseUrl + "/") driver.findElement(By.linkText("Suspects")).click() assert "Suspect List" == driver.findElement(By.cssSelector("h1")).getText() driver.quit() } 27 Selenium WebDriver Example
  28. 28. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ driver.findElement(By.linkText(“Suspects")).click() assert "Suspect List" == driver.findElement(By.cssSelector("h1")).getText() 28 Selenium WebDriver Selenium IDE
  29. 29. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ public void testAllHeaders() { WebDriver driver = new FirefoxDriver() String baseUrl = "http://localhost:8080" ['Suspect', 'Room', 'Weapon'].each { page -> driver.get(baseUrl + '/') driver.findElement(By.linkText("${page}s")).click() assert "${page} List" == driver.findElement(By.cssSelector("h1")).getText() } driver.quit() } 29 Data-Driven Selenium WebDriver
  30. 30. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Functional Testing Architecture How do we design scaleable, maintainable test suites? The problem: 30 Page Objects are the solution “if you write tests that manipulate the HTML elements directly your tests will be brittle to changes in the UI” - Martin Fowler
  31. 31. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 31 Functional Tests Without Page Objects driver.findElement(By.linkText(“Suspects")).click()
  32. 32. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 32 With Page Objects
  33. 33. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The Page Object Design Pattern • A layer of abstraction between the test and the HTML • Provides an easy-to-use interface • Meaningful names for the HTML elements used in test • Hides “structure” of the HTML page • Allows test to do anything & see anything a human can 33 If the UI changes, the tests themselves don’t need to change
  34. 34. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Page Objects: Good OO Design • Encapsulation • Interact with web page solely through the Page Object • DRY • Use the same Page Object from many tests 34 “There is a single ‘repository’ for the services or operations offered by the page rather than having these services scattered throughout the tests” — SeleniumHQ.org
  35. 35. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Selenium WebDriver with Page Objects 35
  36. 36. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ LandingPage landingPage = new LandingPage(driver) SuspectsPage suspectsPage = landingPage.toSuspectsPage() assert "Suspect List" == suspectsPage.getHeaderText() 36 Selenium WebDriver with Page Objects driver.findElement(By.linkText(“Suspects")).click() assert "Suspect List" == driver.findElement(By.cssSelector("h1")).getText() Selenium WebDriver without Page Objects
  37. 37. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ driver.findElement(By.linkText(“Suspects")).click() landingPage.toSuspectsPage() 37 Page Objects: Improved Code Clarity
  38. 38. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ class LandingPage { WebDriver driver WebElement suspectsPageLink LandingPage(WebDriver driver) { this.driver = driver // Sanity Check to see that we're on the right page if ('Clue Demo' != driver.getTitle()) { throw new IllegalStateException(‘Not the Landing Page') } suspectsPageLink = driver.findElement(By.linkText("Suspects")) } SuspectsPage toSuspectsPage() { suspectsPageLink.click() return new SuspectsPage(driver) } } 38 Page Object Example: LandingPage
  39. 39. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ class LandingPage { WebDriver driver WebElement suspectsPageLink LandingPage(WebDriver driver) { this.driver = driver // Sanity Check to see that we're on the right page if ('Clue Demo' != driver.getTitle()) { throw new IllegalStateException(‘Not the Landing Page') } suspectsPageLink = driver.findElement(By.linkText("Suspects")) } SuspectsPage toSuspectsPage() { suspectsPageLink.click() return new SuspectsPage(driver) } } 39 Page Object Example: LandingPage
  40. 40. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ class LandingPage { WebDriver driver WebElement suspectsPageLink LandingPage(WebDriver driver) { this.driver = driver // Sanity Check to see that we're on the right page if ('Clue Demo' != driver.getTitle()) { throw new IllegalStateException(‘Not the Landing Page') } suspectsPageLink = driver.findElement(By.linkText("Suspects")) } SuspectsPage toSuspectsPage() { suspectsPageLink.click() return new SuspectsPage(driver) } } 40 Page Object Example: LandingPage
  41. 41. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ class LandingPage { WebDriver driver WebElement suspectsPageLink LandingPage(WebDriver driver) { this.driver = driver // Sanity Check to see that we're on the right page if ('Clue Demo' != driver.getTitle()) { throw new IllegalStateException(‘Not the Landing Page') } suspectsPageLink = driver.findElement(By.linkText("Suspects")) } SuspectsPage toSuspectsPage() { suspectsPageLink.click() return new SuspectsPage(driver) } } 41 Page Object Example: LandingPage
  42. 42. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ class LandingPage { WebDriver driver WebElement suspectsPageLink LandingPage(WebDriver driver) { this.driver = driver // Sanity Check to see that we're on the right page if ('Clue Demo' != driver.getTitle()) { throw new IllegalStateException(‘Not the Landing Page') } suspectsPageLink = driver.findElement(By.linkText("Suspects")) } SuspectsPage toSuspectsPage() { suspectsPageLink.click() return new SuspectsPage(driver) } } 42 Page Object Example: LandingPage
  43. 43. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Interacting with Page Object elements • Complexity of interaction • Finish functions before verification step • Code Clarity/Readability toSuspectPage 43
  44. 44. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ class LandingPage { WebDriver driver WebElement suspectsPageLink LandingPage(WebDriver driver) { this.driver = driver // Sanity Check to see that we're on the right page if ('Clue Demo' != driver.getTitle()) { throw new IllegalStateException(‘Not the Landing Page') } suspectsPageLink = driver.findElement(By.linkText("Suspects")) } SuspectsPage toSuspectsPage() { suspectsPageLink.click() return new SuspectsPage(driver) } } 44 Page Object Example: LandingPage
  45. 45. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ class LandingPage { WebDriver driver WebElement suspectsPageLink LandingPage(WebDriver driver) { this.driver = driver // Sanity Check to see that we're on the right page if ('Clue Demo' != driver.getTitle()) { throw new IllegalStateException(‘Not the Landing Page') } suspectsPageLink = driver.findElement(By.linkText("Suspects")) } SuspectsPage toSuspectsPage() { suspectsPageLink.click() return new SuspectsPage(driver) } } 45 Page Object Example: LandingPage
  46. 46. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Geb Support for Page Objects • Selenium WebDriver Page Objects are just a design pattern • Geb Page Objects are a feature of the “language” • Reduces boilerplate 46
  47. 47. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ void testSuspectHeaderWithGeb() { Browser browser = new Browser(driver: new FirefoxDriver()) browser.drive { LandingPage landingPage = to LandingPage SuspectsPage suspectsPage = landingPage.toSuspectsPage() assert "Suspect List" == suspectsPage.getHeaderText() }.quit() } 47 Geb Example
  48. 48. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ SuspectsPage suspectsPage = landingPage.toSuspectsPage() assert "Suspect List" == suspectsPage.getHeaderText() 48 Using Geb Page Object SuspectsPage suspectsPage = landingPage.toSuspectsPage() assert "Suspect List" == suspectsPage.getHeaderText() Using Selenium WebDriver Page Object
  49. 49. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ void testSuspectHeaderWithGeb() { Browser browser = new Browser(driver: new FirefoxDriver()) browser.drive { LandingPage landingPage = to LandingPage SuspectsPage suspectsPage = landingPage.toSuspectsPage() assert "Suspect List" == suspectsPage.getHeaderText() }.quit() } 49 Geb Example
  50. 50. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Browser = WebDriver + “current page” 50 • driver • page
  51. 51. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ void testSuspectHeaderWithGeb() { Browser browser = new Browser(driver: new FirefoxDriver()) browser.drive { LandingPage landingPage = to LandingPage SuspectsPage suspectsPage = landingPage.toSuspectsPage() assert "Suspect List" == suspectsPage.getHeaderText() }.quit() } 51 Geb Example
  52. 52. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ void testSuspectHeaderWithGeb() { Browser browser = new Browser(driver: new FirefoxDriver()) browser.drive { LandingPage landingPage = to LandingPage SuspectsPage suspectsPage = landingPage.toSuspectsPage() assert "Suspect List" == suspectsPage.getHeaderText() }.quit() } 52 Geb Example
  53. 53. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ browser.drive { go "signup" assert $("h1").text() == "Signup Page" } 53 Browser.drive Browser browser = new Browser(driver: new FirefoxDriver()) browser.go "signup" assert browser.$("h1").text() == "Signup Page"
  54. 54. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ class LandingPage extends geb.Page { static url = "http://localhost:8080/" static at = { title == 'Clue Demo'} static content = { suspectsPageLink(to: SuspectsPage) {$("a", text: "Suspects")} } SuspectsPage toSuspectsPage() { suspectsPageLink.click() return browser.page } } 54 Geb Page Object Example: LandingPage
  55. 55. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ class LandingPage extends geb.Page { static url = "http://localhost:8080/" static at = { title == 'Clue Demo'} static content = { suspectsPageLink(to: SuspectsPage) {$("a", text: "Suspects")} } SuspectsPage toSuspectsPage() { suspectsPageLink.click() return browser.page } } 55 Geb Page Object Example: LandingPage
  56. 56. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ static content = { suspectsPageLink(to: SuspectsPage) { $("a", text: “Suspects") } } 56 Geb Page Object Elements WebElement suspectsPageLink … suspectsPageLink = driver.findElement(By.linkText("Suspects")) Selenium WebDriver Page Object Elements
  57. 57. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ class LandingPage extends geb.Page { static url = "http://localhost:8080/" static at = { title == 'Clue Demo'} static content = { suspectsPageLink(to: SuspectsPage) {$("a", text: "Suspects")} } SuspectsPage toSuspectsPage() { suspectsPageLink.click() return browser.page } } 57 Geb Page Object Example: LandingPage
  58. 58. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ return browser.page 58 Geb Page Object Return Values return new SuspectsPage(driver) Selenium WebDriver Page Object Return Values
  59. 59. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ class LandingPage extends geb.Page { static url = "http://localhost:8080/" static at = { title == 'Clue Demo'} static content = { suspectsPageLink(to: SuspectsPage) {$("a", text: "Suspects")} } SuspectsPage toSuspectsPage() { suspectsPageLink.click() return browser.page } } 59 Geb Page Object Example: LandingPage
  60. 60. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ static at = { title == 'Clue Demo'} 60 Geb Page Object at-checker if ('Clue Demo' != driver.getTitle()) { throw new IllegalStateException(‘Not the Landing Page') } Selenium WebDriver at-checker
  61. 61. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ class LandingPage extends geb.Page { static url = "http://localhost:8080/" static at = { title == 'Clue Demo'} static content = { suspectsPageLink(to: SuspectsPage) {$("a", text: "Suspects")} } SuspectsPage toSuspectsPage() { suspectsPageLink.click() return browser.page } } 61 Geb Page Object Example: LandingPage
  62. 62. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ to LandingPage 62 Geb Page Object URL navigation driver.get(“http://localhost:8080“) Selenium WebDriver URL navigation
  63. 63. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 63 Other Ways to Use Geb Page Objects void testSuspectHeaderWithGebAlternative() { Browser browser = new Browser(driver: new FirefoxDriver()) browser.drive { to LandingPage suspectsPageLink.click() assert "Suspect List" == header.text() }.quit() } Where are the references to the Page Objects?
  64. 64. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ suspectsPageLink.click() vs landingPage.toSuspectsPage() 64
  65. 65. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 65 Why Geb?
  66. 66. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Interacting with Content • css selector • tag name, id, class • index • If there are multiple matches • tag attributes 66 static content = { suspectsPageLink(to: SuspectsPage) { $("a", text: “Suspects") } } —gebish.org
  67. 67. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Interacting with Content: Text Selectors • startsWith • contains • endsWith • containsWord
 • notStartsWith • notContains • notEndsWith • notContainsWord 67 —gebish.org
  68. 68. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Interacting with Content: Finding and Filtering $("div").find(".b") $("div").$(".b") 68 —gebish.org $("div").filter(".b") $(".b").not("p")
  69. 69. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Verifying CSS Properties Select the style 69 <input ... style="background-color: red"/> assert $("input").css("background-color") == "red"
  70. 70. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Questions/Comments/Discussion 70 Allison Figus @ErinWith2Ls
  71. 71. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ More Groovy & Spock! 71
  72. 72. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The End, Thank You 72

×