More Related Content
Similar to Pragmatic Browser Automation with Geb - GIDS 2015
Similar to Pragmatic Browser Automation with Geb - GIDS 2015 (20)
Pragmatic Browser Automation with Geb - GIDS 2015
- 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
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
Hello Geb - Improved
Browser.drive{
go “http://localhost:8000/app/login.html"
$(name: 'j_username') << 'user1'
$(name: 'j_password') << 'secret'
$('#submit').click()
}.quit()
- 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
<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
- 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')}
}
}
- 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
}
}
}
- 47. 47
• Power of WebDriver
• Elegance of jQuery selection
• Robustness of Page Object
modeling
• Expressiveness of Groovy
Summary
Welcome Geb
- 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