SlideShare une entreprise Scribd logo
1  sur  42
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Tendances (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
 
前端概述
前端概述前端概述
前端概述
 

En vedette

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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Plus 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
 

Plus 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
 

Dernier

The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsBert Jan Schrijver
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
%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
 
%+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
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%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
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
%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
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
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
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
%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
 
%+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
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 

Dernier (20)

The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%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
 
%+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...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%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
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%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
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
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...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%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
 
%+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...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

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