SlideShare uma empresa Scribd logo
1 de 42
Baixar para ler offline
Better Selenium Tests with 
Geb 
Naresha K 
Enteleki Solutions 
naresha.k@gmail.com 
@naresha_k
http://martinfowler.com/bliki/PageObject.html 
WebDriver 
ChromeDriver FirefoxDriver InternetExplorerDriver
WebDriver 
WebDriverJS 
Selenium server 
ChromeDriver FirefoxDriver InternetExplorerDriver
Level of Abstraction 
https://www.flickr.com/photos/pagedooley/3028798210
WebDriver 
WebDriverJS 
Selenium server 
ChromeDriver FirefoxDriver InternetExplorerDriver
Any problem in 
computer science can 
be solved with another 
layer of indirection 
David Wheeler 
https://www.flickr.com/photos/pc_plod/14187378533
Web Driver
Geb
Browser 
import geb.Browser! 
import org.openqa.selenium.firefox.FirefoxDriver! 
! 
Browser browser = new Browser(driver: new FirefoxDriver())!
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/'!
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()!
Accessing Elements 
// driver.findElement(By.name("j_username")) ! 
def username = browser.$(name: 'j_username')! 
// username.sendKeys("user1")! 
username << 'user1'! 
println username.value()!
Geb Browser
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()!
Hello Geb - Improved 
Browser.drive{! 
! go “http://localhost:8000/app/login.html"! 
! $(name: 'j_username') << 'user1'! 
! $(name: 'j_password') << 'secret'! 
! $('#submit').click()! 
}.quit()!
Configurable URL 
// GebConfig.groovy! 
baseUrl = "http://localhost:8000/app/" ! 
Browser.drive{! 
! go “login.html”! 
! $(name: 'j_username') << 'user1'! 
! $(name: 'j_password') << 'secret'! 
! $('#submit').click()! 
}.quit()!
Assertion 
assert $('h1').text() == 'Dashboard'!
Navigator API
Navigator Syntax 
$(<css selector>, <index or range>, <attribute / text matchers>)
<h2>Introduction</h2>! 
<h2>Navigator</h2>! 
<h2>Page Objects</h2>! 
<h2>Summary</h2>! 
$('h2').text() == 'Introduction'! 
$('h2', 1).text() == 'Navigator'! 
$('h2').size() == 4!
<h2>Introduction</h2>! 
<h2>Navigator</h2>! 
<h2>Page Objects</h2>! 
<h2>Summary</h2>! 
$('h2', 0..2)*.text() == ! 
! ! ['Introduction', 'Navigator', 'Page Objects']!
<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!
<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!
<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
<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
Page Objects
Page Objects
Modules
Modules
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')}! 
! }! 
}
Modules 
Browser.drive() {! 
! to ProductPage! 
! products.each{ product ->! 
! ! println "${product.productCode} -> ${product.price}"! 
! }! 
}.quit()
Modules List
Waiting
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! 
}! 
}! 
}
Integration 
https://www.flickr.com/photos/lumaxart/2137737248
Supported Frameworks
@Stepwise! 
class SampleGebSpec extends GebReportingSpec{! 
! 
def "User can login"(){! 
!! when:! 
!! ! to LoginPage! 
! ! ! login('user1', 'secret')! 
! 
! then:! 
! ! ! at DashboardPage! 
! ! ! and:! 
! ! ! header.pageTitle == 'Dashboard'! 
}! 
! 
}! 
Spock Example
Integration
Summary 
• Power of WebDriver 
• Elegance of jQuery selection 
• Robustness of Page Object 
modeling 
• Expressiveness of Groovy 
Welcome Geb
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

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
jQuery
jQueryjQuery
jQuery
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Jquery
JqueryJquery
Jquery
 
jQuery
jQueryjQuery
jQuery
 
Sprout core and performance
Sprout core and performanceSprout core and performance
Sprout core and performance
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
 
End-to-end testing with geb
End-to-end testing with gebEnd-to-end testing with geb
End-to-end testing with geb
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
 
jQuery
jQueryjQuery
jQuery
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery Basics
 
前端概述
前端概述前端概述
前端概述
 

Destaque

Cloud browser testing with Gradle and Geb
Cloud browser testing with Gradle and GebCloud browser testing with Gradle and Geb
Cloud browser testing with Gradle and GebDavid Carr
 
Design Patterns from 10K feet
Design Patterns from 10K feetDesign Patterns from 10K feet
Design Patterns from 10K feetNaresha K
 
Java beyond Java - from the language to platform
Java beyond Java - from the language to platformJava beyond Java - from the language to platform
Java beyond Java - from the language to platformNaresha K
 

Destaque (6)

Cloud browser testing with Gradle and Geb
Cloud browser testing with Gradle and GebCloud browser testing with Gradle and Geb
Cloud browser testing with Gradle and Geb
 
Design Patterns from 10K feet
Design Patterns from 10K feetDesign Patterns from 10K feet
Design Patterns from 10K feet
 
Java beyond Java - from the language to platform
Java beyond Java - from the language to platformJava beyond Java - from the language to platform
Java beyond Java - from the language to platform
 
Geb presentation
Geb presentationGeb presentation
Geb presentation
 
What makes Geb groovy?
What makes Geb groovy?What makes Geb groovy?
What makes Geb groovy?
 
Geb with spock
Geb with spockGeb with spock
Geb with spock
 

Semelhante a Better Selenium Tests with Geb - Selenium Conf 2014

What you need to know bout html5
What you need to know bout html5What you need to know bout html5
What you need to know bout html5Kevin DeRudder
 
Creating GUI container components in Angular and Web Components
Creating GUI container components in Angular and Web ComponentsCreating GUI container components in Angular and Web Components
Creating GUI container components in Angular and Web ComponentsRachael L Moore
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012ghnash
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and ImprovedTimothy Fisher
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoRob Bontekoe
 
Resource Registries: Plone Conference 2014
Resource Registries: Plone Conference 2014Resource Registries: Plone Conference 2014
Resource Registries: Plone Conference 2014Rob Gietema
 
Practical HTML5: Using It Today
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It TodayDoris Chen
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)Doris Chen
 
Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012
Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012
Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012crokitta
 
Enjoy the vue.js
Enjoy the vue.jsEnjoy the vue.js
Enjoy the vue.jsTechExeter
 

Semelhante a Better Selenium Tests with Geb - Selenium Conf 2014 (20)

jQuery basics
jQuery basicsjQuery basics
jQuery basics
 
What you need to know bout html5
What you need to know bout html5What you need to know bout html5
What you need to know bout html5
 
Creating GUI container components in Angular and Web Components
Creating GUI container components in Angular and Web ComponentsCreating GUI container components in Angular and Web Components
Creating GUI container components in Angular and Web Components
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and Improved
 
HTML5 Essentials
HTML5 EssentialsHTML5 Essentials
HTML5 Essentials
 
Html5 intro
Html5 introHtml5 intro
Html5 intro
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
Html5
Html5Html5
Html5
 
HTML5
HTML5HTML5
HTML5
 
jQuery Basic API
jQuery Basic APIjQuery Basic API
jQuery Basic API
 
Resource Registries: Plone Conference 2014
Resource Registries: Plone Conference 2014Resource Registries: Plone Conference 2014
Resource Registries: Plone Conference 2014
 
J query training
J query trainingJ query training
J query training
 
Practical HTML5: Using It Today
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It Today
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
HTML5, the new buzzword
HTML5, the new buzzwordHTML5, the new buzzword
HTML5, the new buzzword
 
Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012
Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012
Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012
 
jQuery, CSS3 and ColdFusion
jQuery, CSS3 and ColdFusionjQuery, CSS3 and ColdFusion
jQuery, CSS3 and ColdFusion
 
Enjoy the vue.js
Enjoy the vue.jsEnjoy the vue.js
Enjoy the vue.js
 

Mais de Naresha K

The Groovy Way of Testing with Spock
The Groovy Way of Testing with SpockThe Groovy Way of Testing with Spock
The Groovy Way of Testing with SpockNaresha K
 
Evolving with Java - How to Remain Effective
Evolving with Java - How to Remain EffectiveEvolving with Java - How to Remain Effective
Evolving with Java - How to Remain EffectiveNaresha K
 
Take Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainersTake Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainersNaresha K
 
Implementing Resilience with Micronaut
Implementing Resilience with MicronautImplementing Resilience with Micronaut
Implementing Resilience with MicronautNaresha K
 
Take Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainersTake Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainersNaresha K
 
Favouring Composition - The Groovy Way
Favouring Composition - The Groovy WayFavouring Composition - The Groovy Way
Favouring Composition - The Groovy WayNaresha K
 
Effective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesEffective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesNaresha K
 
What's in Groovy for Functional Programming
What's in Groovy for Functional ProgrammingWhat's in Groovy for Functional Programming
What's in Groovy for Functional ProgrammingNaresha K
 
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...Naresha K
 
Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...
Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...
Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...Naresha K
 
Eclipse Collections, Java Streams & Vavr - What's in them for Functional Pro...
Eclipse Collections, Java Streams & Vavr - What's in them for  Functional Pro...Eclipse Collections, Java Streams & Vavr - What's in them for  Functional Pro...
Eclipse Collections, Java Streams & Vavr - What's in them for Functional Pro...Naresha K
 
Implementing Cloud-Native Architectural Patterns with Micronaut
Implementing Cloud-Native Architectural Patterns with MicronautImplementing Cloud-Native Architectural Patterns with Micronaut
Implementing Cloud-Native Architectural Patterns with MicronautNaresha K
 
Groovy - Why and Where?
Groovy  - Why and Where?Groovy  - Why and Where?
Groovy - Why and Where?Naresha K
 
Leveraging Micronaut on AWS Lambda
Leveraging Micronaut on AWS LambdaLeveraging Micronaut on AWS Lambda
Leveraging Micronaut on AWS LambdaNaresha K
 
Groovy Refactoring Patterns
Groovy Refactoring PatternsGroovy Refactoring Patterns
Groovy Refactoring PatternsNaresha K
 
Implementing Cloud-native Architectural Patterns with Micronaut
Implementing Cloud-native Architectural Patterns with MicronautImplementing Cloud-native Architectural Patterns with Micronaut
Implementing Cloud-native Architectural Patterns with MicronautNaresha K
 
Effective Java with Groovy
Effective Java with GroovyEffective Java with Groovy
Effective Java with GroovyNaresha K
 
Evolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and EffectiveEvolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and EffectiveNaresha K
 
Effective Java with Groovy - How Language can Influence Good Practices
Effective Java with Groovy - How Language can Influence Good PracticesEffective Java with Groovy - How Language can Influence Good Practices
Effective Java with Groovy - How Language can Influence Good PracticesNaresha K
 
Beyond Lambdas & Streams - Functional Fluency in Java
Beyond Lambdas & Streams - Functional Fluency in JavaBeyond Lambdas & Streams - Functional Fluency in Java
Beyond Lambdas & Streams - Functional Fluency in JavaNaresha K
 

Mais de Naresha K (20)

The Groovy Way of Testing with Spock
The Groovy Way of Testing with SpockThe Groovy Way of Testing with Spock
The Groovy Way of Testing with Spock
 
Evolving with Java - How to Remain Effective
Evolving with Java - How to Remain EffectiveEvolving with Java - How to Remain Effective
Evolving with Java - How to Remain Effective
 
Take Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainersTake Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainers
 
Implementing Resilience with Micronaut
Implementing Resilience with MicronautImplementing Resilience with Micronaut
Implementing Resilience with Micronaut
 
Take Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainersTake Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainers
 
Favouring Composition - The Groovy Way
Favouring Composition - The Groovy WayFavouring Composition - The Groovy Way
Favouring Composition - The Groovy Way
 
Effective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesEffective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good Practices
 
What's in Groovy for Functional Programming
What's in Groovy for Functional ProgrammingWhat's in Groovy for Functional Programming
What's in Groovy for Functional Programming
 
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
 
Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...
Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...
Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...
 
Eclipse Collections, Java Streams & Vavr - What's in them for Functional Pro...
Eclipse Collections, Java Streams & Vavr - What's in them for  Functional Pro...Eclipse Collections, Java Streams & Vavr - What's in them for  Functional Pro...
Eclipse Collections, Java Streams & Vavr - What's in them for Functional Pro...
 
Implementing Cloud-Native Architectural Patterns with Micronaut
Implementing Cloud-Native Architectural Patterns with MicronautImplementing Cloud-Native Architectural Patterns with Micronaut
Implementing Cloud-Native Architectural Patterns with Micronaut
 
Groovy - Why and Where?
Groovy  - Why and Where?Groovy  - Why and Where?
Groovy - Why and Where?
 
Leveraging Micronaut on AWS Lambda
Leveraging Micronaut on AWS LambdaLeveraging Micronaut on AWS Lambda
Leveraging Micronaut on AWS Lambda
 
Groovy Refactoring Patterns
Groovy Refactoring PatternsGroovy Refactoring Patterns
Groovy Refactoring Patterns
 
Implementing Cloud-native Architectural Patterns with Micronaut
Implementing Cloud-native Architectural Patterns with MicronautImplementing Cloud-native Architectural Patterns with Micronaut
Implementing Cloud-native Architectural Patterns with Micronaut
 
Effective Java with Groovy
Effective Java with GroovyEffective Java with Groovy
Effective Java with Groovy
 
Evolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and EffectiveEvolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and Effective
 
Effective Java with Groovy - How Language can Influence Good Practices
Effective Java with Groovy - How Language can Influence Good PracticesEffective Java with Groovy - How Language can Influence Good Practices
Effective Java with Groovy - How Language can Influence Good Practices
 
Beyond Lambdas & Streams - Functional Fluency in Java
Beyond Lambdas & Streams - Functional Fluency in JavaBeyond Lambdas & Streams - Functional Fluency in Java
Beyond Lambdas & Streams - Functional Fluency in Java
 

Último

What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 

Último (20)

What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 

Better Selenium Tests with Geb - Selenium Conf 2014

  • 1. Better Selenium Tests with Geb Naresha K Enteleki Solutions naresha.k@gmail.com @naresha_k
  • 3. WebDriver WebDriverJS Selenium server ChromeDriver FirefoxDriver InternetExplorerDriver
  • 4. Level of Abstraction https://www.flickr.com/photos/pagedooley/3028798210
  • 5. WebDriver WebDriverJS Selenium server ChromeDriver FirefoxDriver InternetExplorerDriver
  • 6. Any problem in computer science can be solved with another layer of indirection David Wheeler https://www.flickr.com/photos/pc_plod/14187378533
  • 7.
  • 9. Geb
  • 10. Browser import geb.Browser! import org.openqa.selenium.firefox.FirefoxDriver! ! Browser browser = new Browser(driver: new FirefoxDriver())!
  • 11. 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/'!
  • 12. 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()!
  • 13. Accessing Elements // driver.findElement(By.name("j_username")) ! def username = browser.$(name: 'j_username')! // username.sendKeys("user1")! username << 'user1'! println username.value()!
  • 15. 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()!
  • 16. Hello Geb - Improved Browser.drive{! ! go “http://localhost:8000/app/login.html"! ! $(name: 'j_username') << 'user1'! ! $(name: 'j_password') << 'secret'! ! $('#submit').click()! }.quit()!
  • 17. Configurable URL // GebConfig.groovy! baseUrl = "http://localhost:8000/app/" ! Browser.drive{! ! go “login.html”! ! $(name: 'j_username') << 'user1'! ! $(name: 'j_password') << 'secret'! ! $('#submit').click()! }.quit()!
  • 20. Navigator Syntax $(<css selector>, <index or range>, <attribute / text matchers>)
  • 21. <h2>Introduction</h2>! <h2>Navigator</h2>! <h2>Page Objects</h2>! <h2>Summary</h2>! $('h2').text() == 'Introduction'! $('h2', 1).text() == 'Navigator'! $('h2').size() == 4!
  • 22. <h2>Introduction</h2>! <h2>Navigator</h2>! <h2>Page Objects</h2>! <h2>Summary</h2>! $('h2', 0..2)*.text() == ! ! ! ['Introduction', 'Navigator', 'Page Objects']!
  • 23. <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!
  • 24. <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!
  • 25. <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
  • 26. <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
  • 31.
  • 32. 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')}! ! }! }
  • 33. Modules Browser.drive() {! ! to ProductPage! ! products.each{ product ->! ! ! println "${product.productCode} -> ${product.price}"! ! }! }.quit()
  • 36. 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! }! }! }
  • 39. @Stepwise! class SampleGebSpec extends GebReportingSpec{! ! def "User can login"(){! !! when:! !! ! to LoginPage! ! ! ! login('user1', 'secret')! ! ! then:! ! ! ! at DashboardPage! ! ! ! and:! ! ! ! header.pageTitle == 'Dashboard'! }! ! }! Spock Example
  • 41. Summary • Power of WebDriver • Elegance of jQuery selection • Robustness of Page Object modeling • Expressiveness of Groovy Welcome Geb
  • 42. 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