Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Pragmatic Browser Automation with Geb - GIDS 2015

1 562 vues

Publié le

Publié dans : Logiciels

Pragmatic Browser Automation with Geb - GIDS 2015

  1. 1. Pragmatic Browser Automation with Geb Naresha K, Chief Technologist Channel Bridge Software Labs @naresha_k
  2. 2. 2
  3. 3. 3
  4. 4. 4
  5. 5. 5
  6. 6. 6 WebDriver
  7. 7. 7 http://martinfowler.com/bliki/PageObject.html
  8. 8. 8 WebDriver ChromeDriver FirefoxDriver InternetExplorerDriver
  9. 9. 9 WebDriver ChromeDriver FirefoxDriver InternetExplorerDriver Selenium server WebDriverJS
  10. 10. 10 Coarse Grained Fine Grained
  11. 11. 11 Any problem in computer science can be solved with another layer of indirection David Wheeler
  12. 12. 12
  13. 13. 13 Geb
  14. 14. 14
  15. 15. 15
  16. 16. 16 Browser import geb.Browser import org.openqa.selenium.firefox.FirefoxDriver Browser browser = new Browser(driver: new FirefoxDriver())
  17. 17. 17 Browser import geb.Browser import org.openqa.selenium.firefox.FirefoxDriver Browser browser = new Browser(driver: new FirefoxDriver()) // driver.get("http://seleniumconf.org/") browser.go 'http://seleniumconf.org/'
  18. 18. 18 Accessing Elements // driver.findElement(By.name("j_username")) def username = browser.$(name: 'j_username') // username.sendKeys("user1") username << 'user1' println username.value()
  19. 19. 19
  20. 20. 20 External Config // GebConfig.groovy import org.openqa.selenium.firefox.FirefoxDriver driver = { def driverInstance = new FirefoxDriver() driverInstance.manage().window().maximize() driverInstance } Browser browser = new Browser() // driver.get("http://seleniumconf.org/") browser.go 'http://seleniumconf.org/' browser.quit()
  21. 21. 21 Hello Geb Browser browser = new Browser() browser.go “http://localhost:8000/app/login.html" browser.$(name: 'j_username') << 'user1' browser.$(name: 'j_password') << 'secret' browser.$('#submit').click() browser.quit()
  22. 22. 22 Hello Geb - Improved Browser.drive{ go “http://localhost:8000/app/login.html" $(name: 'j_username') << 'user1' $(name: 'j_password') << 'secret' $('#submit').click() }.quit()
  23. 23. 23 Configurable URL Browser.drive{ go “login.html” $(name: 'j_username') << 'user1' $(name: 'j_password') << 'secret' $('#submit').click() }.quit() // GebConfig.groovy baseUrl = "http://localhost:8000/app/"
  24. 24. 24 Assertion assert $('h1').text() == 'Dashboard'
  25. 25. 25 Navigator API
  26. 26. 26 Navigator Syntax $(<css selector>, <index or range>, <attribute / text matchers>)
  27. 27. 27 <h2>Introduction</h2> <h2>Navigator</h2> <h2>Page Objects</h2> <h2>Summary</h2> $('h2').text() == 'Introduction' $('h2', 1).text() == 'Navigator' $('h2').size() == 4
  28. 28. 28 <h2>Introduction</h2> <h2>Navigator</h2> <h2>Page Objects</h2> <h2>Summary</h2> $('h2', 0..2)*.text() == ['Introduction', 'Navigator', 'Page Objects']
  29. 29. 29 <h2 duration="5">Introduction</h2> <h2 duration="15">Navigator</h2> <h2>Page Objects</h2> <h2 duration="5">Summary</h2> $('h2', duration: '5').size() == 2 $('h2', text: 'Summary').size() == 1
  30. 30. 30 <h2 duration="5">Introduction</h2> <h2 duration="15">Navigator</h2> <h2>Page Objects</h2> <h2 duration="5">Summary</h2> $('h2', text: contains('o')).size() == 2 $('h2', text: iContains('o')).size() == 3 $('h2', duration: contains('5')).size() == 3
  31. 31. 31 <div class="languages"> <div class="language jvm">Java</div> <div class="language clr">C#</div> <div class="language jvm">Groovy</div> <div class="language clr">F#</div> <div class="language erlang">Elixir</div> </div> $('div.languages').find('.jvm').each{ element -> println element.text() } Java Groovy
  32. 32. 32 <div class="languages"> <div class="language jvm">Java</div> <div class="language clr">C#</div> <div class="language jvm">Groovy</div> <div class="language clr">F#</div> <div class="language erlang">Elixir</div> </div> $('.language').filter('.jvm').each{ element -> println element.text() } Java Groovy $('.language').not('.clr').each{ element -> println element.text() } Java Groovy Elixir
  33. 33. 33 Page Objects
  34. 34. 34 Page Objects
  35. 35. 35 Modules
  36. 36. 36 Modules
  37. 37. 37
  38. 38. 38 Modules class Record extends Module{ static content = { column {index -> $('td', index)} productCode {column(1).text()} price { column(2).text().toInteger()} } } class ProductPage extends Page{ static url = 'table.html' static content = { products {moduleList Record, $('table tbody tr')} } }
  39. 39. 39 Modules Browser.drive() { to ProductPage products.each{ product -> println "${product.productCode} -> ${product.price}" } }.quit()
  40. 40. 40 Modules List
  41. 41. 41 Waiting
  42. 42. 42 Wait <div id="dynamic"></div> waitFor { $('#dynamic').text()} waitFor(8) { $('#dynamic').text()} waitFor(8, 0.5) { $('#dynamic').text()} waitFor('slow') { $('#dynamic').text()} // GebConfig.groovy waiting { presets { slow { timeout = 12 retryInterval = 1 } } }
  43. 43. 43 Integration https://www.flickr.com/photos/lumaxart/2137737248
  44. 44. 44 Supported Frameworks
  45. 45. 45 Spock Example @Stepwise class SampleGebSpec extends GebReportingSpec{ def "User can login"(){ when: to LoginPage login('user1', 'secret') then: at DashboardPage and: header.pageTitle == 'Dashboard' } }
  46. 46. 46 Integration
  47. 47. 47 • Power of WebDriver • Elegance of jQuery selection • Robustness of Page Object modeling • Expressiveness of Groovy Summary Welcome Geb
  48. 48. 48 References Official Geb Page - http://www.gebish.org/ Example - https://github.com/geb/geb-example-gradle Spock Documentation - http://spock- framework.readthedocs.org/en/latest/ Code samples - https://github.com/naresha/seconf2014

×