SlideShare a Scribd company logo
1 of 19
Download to read offline
Geb 
very groovy browser automation 
http://www.gebish.org 1 / 19
Agenda 
1. Introduction to Geb 
WebDriver 
Test framework integrations 
Navigation API 
Page objects 
Module objects 
Content DSL 
Multiple Environments 
2. Our project-setup 
2 / 19
Introduction 
Automating the interaction between web browsers and web content 
Acceptance Testing Web Applications 
Screen scraping 
Great documentation: http://www.gebish.org/manual/current/ 
3 / 19
Example 
geb.Browser 
Browser.drive { 
go "http://myapp.com/login" 
$("h1").text() == "Please Login" 
$("form.login"). { 
username = "admin" 
password = "password" 
login().click() 
} 
$("h1").text() == "Admin Section" 
} 
4 / 19
Technology 
WebDriver (support many browsers) 
Groovy (remove java-boilerplate) 
Spock, JUnit or TestNG (easy to integrate with IDE and build systems) 
Navigator API (jQuery-like content selection) 
5 / 19
WebDriver 
Geb builds on the WebDriver browser automation librar 
Geb can work with any browser that WebDriver can 
Geb provides an abstraction layer, but you can access WebDriver directly 
Geb never talks to the actual browser. 
You need specific driver for each browser you want to work with: 
< > 
< >org.seleniumhq.selenium</ > 
< >selenium-firefox-driver</ > 
< >2.20.0</ > 
</ > 
6 / 19
Test framework integration 
Geb works with existing popular tools like Spock, JUnit, TestNG and 
Cucumber. 
You pick what you like; but Geb encurages Spock. 
7 / 19
Spock example 
geb.spock.GebSpec 
{ 
"first result for wikipedia search should be wikipedia"() { 
given: 
to GoogleHomePage 
expect: 
at GoogleHomePage 
when: 
search.field.value("wikipedia") 
then: 
waitFor { at GoogleResultsPage } 
} 
} 
More about Spock @ https://code.google.com/p/spock/ 8 / 19
Navigator API 
Inspired by jQuery. 
Content is selected via the $ function, which returns a Navigator object 
Makes it super easy to select content 
// match all 'div' elements on the page 
$("div") 
// match the first 'div' element on the page 
$("div", 0) 
// match all 'div' elements with a title attribute value of 'section' 
$("div", title: "section") 
// The parent of the first paragraph 
$("p", 0).parent() 
//<div>foo</div> 
$("div", text: "foo") 
// Using patterns 
$("p", text: ~/p./).size() == 2 
$("p", text: startsWith("p")).size() == 2 
http://www.gebish.org/manual/current/intro.html#the_jquery_ish_navigator_api 9 / 19
Page Objects 
Less fragile code with better abstractions and modelling 
Promotes resuse 
Makes it easier to write tests 
Pages (and modules) can be arranged in inheritance hierarchies. 
Within your web app’s UI there are areas that your tests interact with. A 
Page Object simply models these as objects within the test code. This reduces 
the amount of duplicated code and means that if the UI changes, the fix need 
only be applied in one place. (webdriver...) 
10 / 19
Page Objects: example 
{ 
url = "/login" 
at = { title == "Login to our super page" } 
content = { 
loginButton(to: AdminPage) { $("input", type: "submit", name: "login") } 
} 
} 
{ 
at = { 
assert $("h1").text() == "Admin Page" 
} 
} 
Browser.drive { 
to LoginPage 
loginButton.click() 
at AdminPage 
} 
to changes the browser’s page instance. 
click on login-button changes page to the "Admin page" 
at explicitly asserts that we are on the expected page 
11 / 19
Module Objects 
Reusable fragments that can be used across pages 
Useful for modelling things like UI widgets that are used across multiple 
pages 
We can define a Navigator context when including the module in a Page. 
Module will then only see "its own part" of the dom via the navigator api 
12 / 19
Module Objects: example 
{ 
content = { 
button { $("input", type: "submit") } 
} 
} 
{ 
content = { 
theModule { module ExampleModule } 
} 
} 
Browser.drive { 
to ExamplePage 
theModule.button.click() 
} 
13 / 19
Content DSL 
Content definitions can build upon each other. 
Content definitions are actually templates. 
{ 
content = { 
results { $("li.g") } 
result { i -> results[i] } 
resultLink { i -> result(i).find("a.l", 0) } 
firstResultLink { resultLink(0) } 
} 
} 
Optional Content 
{ 
content = { 
errorMsg(required: ) { $("p.errorMsg") } 
} 
} 
14 / 19
Dynamic content 
{ 
content = { 
linkTotrigger {$("a"} 
awesomeContainer(required: ) { $("div.awesome") } 
} 
} 
Browser.drive { 
to DynamicPage 
linkTotrigger.click() 
waitFor { awesomeContainer } 
} 
By default, it will look for it every 100ms for 5s before giving up. 
15 / 19
Multiple Environments 
The Groovy ConfigSlurper mechanism has built in support for 
environment sensitive configuration 
system property to determine the environment to use 
remoteDriver = {..} 
driver = { FirefoxDriver() } 
baseUrl = "http://iad.finn.no:3002/" 
iadUrl = "http://dev.finn.no" 
environments { 
'dev' { 
baseUrl = "http://dev.finn.no/talent/" 
iadUrl = "http://dev.finn.no" 
driver = remoteDriver 
} 
'prod' { 
baseUrl = "http://www.finn.no/talent/" 
iadUrl = "http://www.finn.no" 
driver = remoteDriver 
} 
} 
16 / 19
Our project-setup 
Kjører tester lokalt mot lokal server 
Kan kjøre tester som en del av maven-bygget 
men valgt å ikke gjøre dette siden vi er avhengig av finndev-login-tjensten 
Sparker i gang en testkjøring mot dev straks en ny artifakt er deployet i 
dev. 
17 / 19
FINN.no :: Testreports 
JUnit-listner that intgrates Geb with http://testreports.finn.no 
Support @Tags annotation 
Gives status and screenshots for each test 
Easy setup with the maven-surfire-plugin 
< > 
< >org.apache.maven.plugins</ > 
< >maven-surefire-plugin</ > 
< >2.16</ > 
< > 
< > 
< >**/*Spec.*</ > 
</ > 
< > 
< >target/test-reports/geb</ > 
< >${artifactId}</ > 
</ > 
< > 
< > 
< >listener</ > 
< >no.finntech.test.report.runner.GebTestReportRunListener</ > 
</ > 
</ > 18 / 19
Demo time 
19 / 19

More Related Content

What's hot

What's hot (20)

Unit Testing
Unit TestingUnit Testing
Unit Testing
 
BDD with CucumberJS and WebdriverIO
BDD with CucumberJS and WebdriverIOBDD with CucumberJS and WebdriverIO
BDD with CucumberJS and WebdriverIO
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
 
Dependency Breaking Techniques
Dependency Breaking TechniquesDependency Breaking Techniques
Dependency Breaking Techniques
 
Unit testing in JavaScript with Jasmine and Karma
Unit testing in JavaScript with Jasmine and KarmaUnit testing in JavaScript with Jasmine and Karma
Unit testing in JavaScript with Jasmine and Karma
 
Lessons Learned from Using Next.js in Production
Lessons Learned from Using Next.js in ProductionLessons Learned from Using Next.js in Production
Lessons Learned from Using Next.js in Production
 
React for Beginners
React for BeginnersReact for Beginners
React for Beginners
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to Elixir
 
React JS Interview Question & Answer
React JS Interview Question & AnswerReact JS Interview Question & Answer
React JS Interview Question & Answer
 
Selenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesSelenium Presentation at Engineering Colleges
Selenium Presentation at Engineering Colleges
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Selenium-Locators
Selenium-LocatorsSelenium-Locators
Selenium-Locators
 
Intro to vue.js
Intro to vue.jsIntro to vue.js
Intro to vue.js
 
An Intro into webpack
An Intro into webpackAn Intro into webpack
An Intro into webpack
 
Test Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and CucumberTest Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and Cucumber
 
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
 
Maven
MavenMaven
Maven
 
Test Automation and Selenium
Test Automation and SeleniumTest Automation and Selenium
Test Automation and Selenium
 
SOAP REST 이해
SOAP REST 이해SOAP REST 이해
SOAP REST 이해
 
JavaScript Engines and Event Loop
JavaScript Engines and Event Loop JavaScript Engines and Event Loop
JavaScript Engines and Event Loop
 

Viewers also liked (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
 
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
 
Design Patterns from 10K feet
Design Patterns from 10K feetDesign Patterns from 10K feet
Design Patterns from 10K feet
 
Better Selenium Tests with Geb - Selenium Conf 2014
Better Selenium Tests with Geb - Selenium Conf 2014Better Selenium Tests with Geb - Selenium Conf 2014
Better Selenium Tests with Geb - Selenium Conf 2014
 
What makes Geb groovy?
What makes Geb groovy?What makes Geb groovy?
What makes Geb groovy?
 
Bike To Work Presentation
Bike To Work PresentationBike To Work Presentation
Bike To Work Presentation
 

Similar to Geb presentation

Agile NCR 2013 - Gaurav Bansal- web_automation
Agile NCR 2013 - Gaurav Bansal- web_automationAgile NCR 2013 - Gaurav Bansal- web_automation
Agile NCR 2013 - Gaurav Bansal- web_automation
AgileNCR2013
 
BlackBerry DevCon 2011 - PhoneGap and WebWorks
BlackBerry DevCon 2011 - PhoneGap and WebWorksBlackBerry DevCon 2011 - PhoneGap and WebWorks
BlackBerry DevCon 2011 - PhoneGap and WebWorks
mwbrooks
 
Build Your Own CMS with Apache Sling
Build Your Own CMS with Apache SlingBuild Your Own CMS with Apache Sling
Build Your Own CMS with Apache Sling
Bob Paulin
 
Pragmatic Browser Automation with Geb - GIDS 2015
Pragmatic Browser Automation with Geb - GIDS 2015Pragmatic Browser Automation with Geb - GIDS 2015
Pragmatic Browser Automation with Geb - GIDS 2015
Naresha K
 

Similar to Geb presentation (20)

End-to-end testing with geb
End-to-end testing with gebEnd-to-end testing with geb
End-to-end testing with geb
 
Agile NCR 2013 - Gaurav Bansal- web_automation
Agile NCR 2013 - Gaurav Bansal- web_automationAgile NCR 2013 - Gaurav Bansal- web_automation
Agile NCR 2013 - Gaurav Bansal- web_automation
 
Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect Model
Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect ModelComprehensive Browser Automation Solution using Groovy, WebDriver & Obect Model
Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect Model
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
BlackBerry DevCon 2011 - PhoneGap and WebWorks
BlackBerry DevCon 2011 - PhoneGap and WebWorksBlackBerry DevCon 2011 - PhoneGap and WebWorks
BlackBerry DevCon 2011 - PhoneGap and WebWorks
 
Single Page JavaScript WebApps... A Gradle Story
Single Page JavaScript WebApps... A Gradle StorySingle Page JavaScript WebApps... A Gradle Story
Single Page JavaScript WebApps... A Gradle Story
 
Build Your Own CMS with Apache Sling
Build Your Own CMS with Apache SlingBuild Your Own CMS with Apache Sling
Build Your Own CMS with Apache Sling
 
Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
WebGUI Developers Workshop
WebGUI Developers WorkshopWebGUI Developers Workshop
WebGUI Developers Workshop
 
Writing automation tests with python selenium behave pageobjects
Writing automation tests with python selenium behave pageobjectsWriting automation tests with python selenium behave pageobjects
Writing automation tests with python selenium behave pageobjects
 
Google App Engine with Gaelyk
Google App Engine with GaelykGoogle App Engine with Gaelyk
Google App Engine with Gaelyk
 
Pragmatic Browser Automation with Geb - GIDS 2015
Pragmatic Browser Automation with Geb - GIDS 2015Pragmatic Browser Automation with Geb - GIDS 2015
Pragmatic Browser Automation with Geb - GIDS 2015
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJS
 

Recently uploaded

%+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
 
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...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
+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
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 

Recently uploaded (20)

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...
 
%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
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
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...
 
+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...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
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...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%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
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
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?
 
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
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%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
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

Geb presentation

  • 1. Geb very groovy browser automation http://www.gebish.org 1 / 19
  • 2. Agenda 1. Introduction to Geb WebDriver Test framework integrations Navigation API Page objects Module objects Content DSL Multiple Environments 2. Our project-setup 2 / 19
  • 3. Introduction Automating the interaction between web browsers and web content Acceptance Testing Web Applications Screen scraping Great documentation: http://www.gebish.org/manual/current/ 3 / 19
  • 4. Example geb.Browser Browser.drive { go "http://myapp.com/login" $("h1").text() == "Please Login" $("form.login"). { username = "admin" password = "password" login().click() } $("h1").text() == "Admin Section" } 4 / 19
  • 5. Technology WebDriver (support many browsers) Groovy (remove java-boilerplate) Spock, JUnit or TestNG (easy to integrate with IDE and build systems) Navigator API (jQuery-like content selection) 5 / 19
  • 6. WebDriver Geb builds on the WebDriver browser automation librar Geb can work with any browser that WebDriver can Geb provides an abstraction layer, but you can access WebDriver directly Geb never talks to the actual browser. You need specific driver for each browser you want to work with: < > < >org.seleniumhq.selenium</ > < >selenium-firefox-driver</ > < >2.20.0</ > </ > 6 / 19
  • 7. Test framework integration Geb works with existing popular tools like Spock, JUnit, TestNG and Cucumber. You pick what you like; but Geb encurages Spock. 7 / 19
  • 8. Spock example geb.spock.GebSpec { "first result for wikipedia search should be wikipedia"() { given: to GoogleHomePage expect: at GoogleHomePage when: search.field.value("wikipedia") then: waitFor { at GoogleResultsPage } } } More about Spock @ https://code.google.com/p/spock/ 8 / 19
  • 9. Navigator API Inspired by jQuery. Content is selected via the $ function, which returns a Navigator object Makes it super easy to select content // match all 'div' elements on the page $("div") // match the first 'div' element on the page $("div", 0) // match all 'div' elements with a title attribute value of 'section' $("div", title: "section") // The parent of the first paragraph $("p", 0).parent() //<div>foo</div> $("div", text: "foo") // Using patterns $("p", text: ~/p./).size() == 2 $("p", text: startsWith("p")).size() == 2 http://www.gebish.org/manual/current/intro.html#the_jquery_ish_navigator_api 9 / 19
  • 10. Page Objects Less fragile code with better abstractions and modelling Promotes resuse Makes it easier to write tests Pages (and modules) can be arranged in inheritance hierarchies. Within your web app’s UI there are areas that your tests interact with. A Page Object simply models these as objects within the test code. This reduces the amount of duplicated code and means that if the UI changes, the fix need only be applied in one place. (webdriver...) 10 / 19
  • 11. Page Objects: example { url = "/login" at = { title == "Login to our super page" } content = { loginButton(to: AdminPage) { $("input", type: "submit", name: "login") } } } { at = { assert $("h1").text() == "Admin Page" } } Browser.drive { to LoginPage loginButton.click() at AdminPage } to changes the browser’s page instance. click on login-button changes page to the "Admin page" at explicitly asserts that we are on the expected page 11 / 19
  • 12. Module Objects Reusable fragments that can be used across pages Useful for modelling things like UI widgets that are used across multiple pages We can define a Navigator context when including the module in a Page. Module will then only see "its own part" of the dom via the navigator api 12 / 19
  • 13. Module Objects: example { content = { button { $("input", type: "submit") } } } { content = { theModule { module ExampleModule } } } Browser.drive { to ExamplePage theModule.button.click() } 13 / 19
  • 14. Content DSL Content definitions can build upon each other. Content definitions are actually templates. { content = { results { $("li.g") } result { i -> results[i] } resultLink { i -> result(i).find("a.l", 0) } firstResultLink { resultLink(0) } } } Optional Content { content = { errorMsg(required: ) { $("p.errorMsg") } } } 14 / 19
  • 15. Dynamic content { content = { linkTotrigger {$("a"} awesomeContainer(required: ) { $("div.awesome") } } } Browser.drive { to DynamicPage linkTotrigger.click() waitFor { awesomeContainer } } By default, it will look for it every 100ms for 5s before giving up. 15 / 19
  • 16. Multiple Environments The Groovy ConfigSlurper mechanism has built in support for environment sensitive configuration system property to determine the environment to use remoteDriver = {..} driver = { FirefoxDriver() } baseUrl = "http://iad.finn.no:3002/" iadUrl = "http://dev.finn.no" environments { 'dev' { baseUrl = "http://dev.finn.no/talent/" iadUrl = "http://dev.finn.no" driver = remoteDriver } 'prod' { baseUrl = "http://www.finn.no/talent/" iadUrl = "http://www.finn.no" driver = remoteDriver } } 16 / 19
  • 17. Our project-setup Kjører tester lokalt mot lokal server Kan kjøre tester som en del av maven-bygget men valgt å ikke gjøre dette siden vi er avhengig av finndev-login-tjensten Sparker i gang en testkjøring mot dev straks en ny artifakt er deployet i dev. 17 / 19
  • 18. FINN.no :: Testreports JUnit-listner that intgrates Geb with http://testreports.finn.no Support @Tags annotation Gives status and screenshots for each test Easy setup with the maven-surfire-plugin < > < >org.apache.maven.plugins</ > < >maven-surefire-plugin</ > < >2.16</ > < > < > < >**/*Spec.*</ > </ > < > < >target/test-reports/geb</ > < >${artifactId}</ > </ > < > < > < >listener</ > < >no.finntech.test.report.runner.GebTestReportRunListener</ > </ > </ > 18 / 19
  • 19. Demo time 19 / 19