SlideShare a Scribd company logo
1 of 20
Download to read offline
Cucumber on the JVM with
              Groovy
          cucumber, cuke4duke, groovy, geb




Richard Paul                             2011-03-24
What is Groovy

•   Dynamic language for the JVM
•   Inspired by Python, Ruby, Smalltalk
•   Integrates closely with Java
•   Superset of Java syntax




http://groovy.codehaus.org/
Why Groovy

•   Leverage existing Java API knowledge
•   Integrate closely with production Java code
•   Expressive language & libraries
•   Just a 5MB jar on the classpath
Groovy Support in Cucumber

• Cuke4Duke
• Uses JRuby behind the scenes
  o Pure Java coming later this year
• Groovy DSL to automate scenarios




https://github.com/aslakhellesoy/cuke4duke
Feature

Scenario: Regular numbers
  Given I have entered 3
  And I have entered 2
  When I press divide
  Then the result should be 1.5




https://github.com/aslakhellesoy/cuke4duke/tree/master/examples/groovy
Given


Given(~'I have entered (.*)') { number ->
    calculator.push number
}



// Implicit coercion to integer
Given(~'I have entered (.*)') { int number ->
    assert number.class == Integer.class
    calculator.push number
}
When


When(~'I press (w+)') { operatorName ->
    result = calculator."$operatorName"()
}



// Can use slashy strings to avoid escaping
When(/I press (w+)/) { operatorName ->
    result = calculator."$operatorName"()
}
Then


Then(~'the result should be (.*)') {
        double result ->
    assert expected == result
}


// == compares equality
// not same instance as in Java
Power Assert

def now = new Date()
def old = Date.parse('yyyyMMdd', '20100101')
assert now.date == old.date



Assertion failed:

assert now.date == old.date
       |   |    | |    |
       |   19   | |    1
       |        | Fri Jan 01 00:00:00 GMT 2010
       |        false
       Sat Mar 19 13:18:42 GMT 2011
Multiline Strings

Given some text
"""
Line 1
Line 2
"""

Given(~'some text') { body ->
    body.eachLine {
        println it
    }
}

=> Line 1
=> Line 2
Tables

Given I have the following foods
  |name |healthy|
  |Orange|Yes    |
  |Chips |No     |
When I count the number of healthy items
Then I have 1 healthy item
Tables

Given(~'I have the following foods') { table ->
    basket = new Basket()
    table.hashes().each {
        def item = new Food(
            name:    it.name, // it.get('name')
            healthy: it.healthy == 'Yes')
        basket.add(item)
    }
}
When(~'I count the healthy items') {
    numberOfHealthy = basket.numberOfHealthy
}
Then(~'I have (.+) healthy items') { int count ->
    assert numberOfHealthy == count
}
Tables

class Basket {
    private items = []
    void add(item) {
        items << item
    }
    int getNumberOfHealthy() {
        items.findAll {
            it.healthy
        }.size()
    }
}

class Food {
    def name
    def healthy
}
Organising Step Definitions

Cucumber will read in any .groovy files within step_definitions

All steps are then available to any scenarios

State can be shared between steps by setting to script binding

When(~'I set a variable to the binding') {
    x = 1
}
Then(~'the other step can access variable') {
    assert x == 1
}
Before/After

Before {
  // Initialise something
}

Before('@tagname') {
  // Initialise only for features/scenarios
  // tagged with @tagname
}
Before('~@tagname') {} // not tagged

After {
  // Clean up something
}
World

Allow simple access to methods from within step definitions


World {
    def world = new Object()
    world.metaClass.mixin Math
    world
}


When(~'we take the square root') {
    sqrt(4)    // calls Math.sqrt(4)
}
Browser Automation with Geb

Given(~'I am on the Wikipedia homepage') {
    go()
}

When(~'I search for "(.+)"') { query ->
    $('#searchInput').value(query)
    $('.searchButton').click()
}

Then(~'I am shown the "(.+)" article') { article ->
    assert $('h1').text() == article
}
env.groovy for Geb

import geb.Browser
this.metaClass.mixin(cuke4duke.GroovyDsl)

World {
    new Browser('http://wikipedia.org')
}

After {
    clearCookies()
}
Build Tools

Integration with
 • Maven
 • Ant

Cucumber can write reports in JUnit format for CI reports
Discussion/Questions




                   Thanks!

         http://rapaul.com      @rapaul

More Related Content

What's hot

GPars For Beginners
GPars For BeginnersGPars For Beginners
GPars For BeginnersMatt Passell
 
TDD in the wild
TDD in the wildTDD in the wild
TDD in the wildBrainhub
 
Productive Programming in Groovy
Productive Programming in GroovyProductive Programming in Groovy
Productive Programming in GroovyGanesh Samarthyam
 
Auto-GWT : Better GWT Programming with Xtend
Auto-GWT : Better GWT Programming with XtendAuto-GWT : Better GWT Programming with Xtend
Auto-GWT : Better GWT Programming with XtendSven Efftinge
 
C++ course start
C++ course startC++ course start
C++ course startNet3lem
 
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAVNOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAVRohit malav
 
Psycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python ScriptPsycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python ScriptSurvey Department
 
Python in the database
Python in the databasePython in the database
Python in the databasepybcn
 
FRP and Bacon.js
FRP and Bacon.jsFRP and Bacon.js
FRP and Bacon.jsStarbuildr
 
Service Functions
Service FunctionsService Functions
Service Functionspineda2
 
FrontendLab: Programming UI with FRP and Bacon js - Вячеслав Ворончук
FrontendLab: Programming UI with FRP and Bacon js - Вячеслав ВорончукFrontendLab: Programming UI with FRP and Bacon js - Вячеслав Ворончук
FrontendLab: Programming UI with FRP and Bacon js - Вячеслав ВорончукGeeksLab Odessa
 
Voldemort collections library
Voldemort collections libraryVoldemort collections library
Voldemort collections libraryJason Ko
 

What's hot (19)

Python my SQL - create table
Python my SQL - create tablePython my SQL - create table
Python my SQL - create table
 
Python my sql database connection
Python my sql   database connectionPython my sql   database connection
Python my sql database connection
 
GPars For Beginners
GPars For BeginnersGPars For Beginners
GPars For Beginners
 
TDD in the wild
TDD in the wildTDD in the wild
TDD in the wild
 
Productive Programming in Groovy
Productive Programming in GroovyProductive Programming in Groovy
Productive Programming in Groovy
 
Selenium cheat sheet
Selenium cheat sheetSelenium cheat sheet
Selenium cheat sheet
 
Auto-GWT : Better GWT Programming with Xtend
Auto-GWT : Better GWT Programming with XtendAuto-GWT : Better GWT Programming with Xtend
Auto-GWT : Better GWT Programming with Xtend
 
C++ course start
C++ course startC++ course start
C++ course start
 
Gwt and Xtend
Gwt and XtendGwt and Xtend
Gwt and Xtend
 
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAVNOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
 
Psycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python ScriptPsycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python Script
 
Python in the database
Python in the databasePython in the database
Python in the database
 
FRP and Bacon.js
FRP and Bacon.jsFRP and Bacon.js
FRP and Bacon.js
 
Service Functions
Service FunctionsService Functions
Service Functions
 
Meetup slides
Meetup slidesMeetup slides
Meetup slides
 
FrontendLab: Programming UI with FRP and Bacon js - Вячеслав Ворончук
FrontendLab: Programming UI with FRP and Bacon js - Вячеслав ВорончукFrontendLab: Programming UI with FRP and Bacon js - Вячеслав Ворончук
FrontendLab: Programming UI with FRP and Bacon js - Вячеслав Ворончук
 
Voldemort collections library
Voldemort collections libraryVoldemort collections library
Voldemort collections library
 
Grails queries
Grails   queriesGrails   queries
Grails queries
 
Scala
ScalaScala
Scala
 

Viewers also liked

Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)Mindfire Solutions
 
Is Groovy better for testing than Java?
Is Groovy better for testing than Java?Is Groovy better for testing than Java?
Is Groovy better for testing than Java?Trisha Gee
 
Test automation with Cucumber-JVM
Test automation with Cucumber-JVMTest automation with Cucumber-JVM
Test automation with Cucumber-JVMAlan Parkinson
 
Introduction to BDD with Cucumber for Java
Introduction to BDD with Cucumber for JavaIntroduction to BDD with Cucumber for Java
Introduction to BDD with Cucumber for JavaSeb Rose
 

Viewers also liked (8)

Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)
 
Is Groovy better for testing than Java?
Is Groovy better for testing than Java?Is Groovy better for testing than Java?
Is Groovy better for testing than Java?
 
Cucumber in Practice(en)
Cucumber in Practice(en)Cucumber in Practice(en)
Cucumber in Practice(en)
 
RSpec & TDD Tutorial
RSpec & TDD TutorialRSpec & TDD Tutorial
RSpec & TDD Tutorial
 
Cucumber ppt
Cucumber pptCucumber ppt
Cucumber ppt
 
Test automation with Cucumber-JVM
Test automation with Cucumber-JVMTest automation with Cucumber-JVM
Test automation with Cucumber-JVM
 
Introduction to BDD with Cucumber for Java
Introduction to BDD with Cucumber for JavaIntroduction to BDD with Cucumber for Java
Introduction to BDD with Cucumber for Java
 
Cucumber_Training_ForQA
Cucumber_Training_ForQACucumber_Training_ForQA
Cucumber_Training_ForQA
 

Similar to Cucumber Groovy Guide Automate Tests JVM

Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objectsHusain Dalal
 
GoCracow #5 Bartlomiej klimczak - GoBDD
GoCracow #5 Bartlomiej klimczak - GoBDDGoCracow #5 Bartlomiej klimczak - GoBDD
GoCracow #5 Bartlomiej klimczak - GoBDDBartłomiej Kiełbasa
 
Stuff you didn't know about action script
Stuff you didn't know about action scriptStuff you didn't know about action script
Stuff you didn't know about action scriptChristophe Herreman
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation JavascriptRamesh Nair
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming LanguageAnıl Sözeri
 
This is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfThis is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfakaluza07
 
Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitVaclav Pech
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
 
Property-Based Testing in Objective-C & Swift with Fox
Property-Based Testing in Objective-C & Swift with FoxProperty-Based Testing in Objective-C & Swift with Fox
Property-Based Testing in Objective-C & Swift with FoxBrian Gesiak
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages VictorSzoltysek
 
Dts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlinDts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlinAhmad Arif Faizin
 
Google Guava for cleaner code
Google Guava for cleaner codeGoogle Guava for cleaner code
Google Guava for cleaner codeMite Mitreski
 

Similar to Cucumber Groovy Guide Automate Tests JVM (20)

Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
 
GoCracow #5 Bartlomiej klimczak - GoBDD
GoCracow #5 Bartlomiej klimczak - GoBDDGoCracow #5 Bartlomiej klimczak - GoBDD
GoCracow #5 Bartlomiej klimczak - GoBDD
 
Stuff you didn't know about action script
Stuff you didn't know about action scriptStuff you didn't know about action script
Stuff you didn't know about action script
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
 
Why react matters
Why react mattersWhy react matters
Why react matters
 
Fewd week5 slides
Fewd week5 slidesFewd week5 slides
Fewd week5 slides
 
Java.lang.object
Java.lang.objectJava.lang.object
Java.lang.object
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
This is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfThis is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdf
 
Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruit
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Property-Based Testing in Objective-C & Swift with Fox
Property-Based Testing in Objective-C & Swift with FoxProperty-Based Testing in Objective-C & Swift with Fox
Property-Based Testing in Objective-C & Swift with Fox
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages
 
Dts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlinDts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlin
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 
PHP PPT FILE
PHP PPT FILEPHP PPT FILE
PHP PPT FILE
 
Google Guava for cleaner code
Google Guava for cleaner codeGoogle Guava for cleaner code
Google Guava for cleaner code
 

More from Richard Paul

Acceptance testing with Geb
Acceptance testing with GebAcceptance testing with Geb
Acceptance testing with GebRichard Paul
 
Introduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionIntroduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionRichard Paul
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVCRichard Paul
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing FundamentalsRichard Paul
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax BasicsRichard Paul
 
Mocking in Java with Mockito
Mocking in Java with MockitoMocking in Java with Mockito
Mocking in Java with MockitoRichard Paul
 

More from Richard Paul (9)

Acceptance testing with Geb
Acceptance testing with GebAcceptance testing with Geb
Acceptance testing with Geb
 
Acceptance tests
Acceptance testsAcceptance tests
Acceptance tests
 
jQuery Behaviours
jQuery BehavioursjQuery Behaviours
jQuery Behaviours
 
Introduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionIntroduction to Spring's Dependency Injection
Introduction to Spring's Dependency Injection
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVC
 
Unit Testing Fundamentals
Unit Testing FundamentalsUnit Testing Fundamentals
Unit Testing Fundamentals
 
Using Dojo
Using DojoUsing Dojo
Using Dojo
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax Basics
 
Mocking in Java with Mockito
Mocking in Java with MockitoMocking in Java with Mockito
Mocking in Java with Mockito
 

Recently uploaded

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Cucumber Groovy Guide Automate Tests JVM

  • 1. Cucumber on the JVM with Groovy cucumber, cuke4duke, groovy, geb Richard Paul 2011-03-24
  • 2. What is Groovy • Dynamic language for the JVM • Inspired by Python, Ruby, Smalltalk • Integrates closely with Java • Superset of Java syntax http://groovy.codehaus.org/
  • 3. Why Groovy • Leverage existing Java API knowledge • Integrate closely with production Java code • Expressive language & libraries • Just a 5MB jar on the classpath
  • 4. Groovy Support in Cucumber • Cuke4Duke • Uses JRuby behind the scenes o Pure Java coming later this year • Groovy DSL to automate scenarios https://github.com/aslakhellesoy/cuke4duke
  • 5. Feature Scenario: Regular numbers Given I have entered 3 And I have entered 2 When I press divide Then the result should be 1.5 https://github.com/aslakhellesoy/cuke4duke/tree/master/examples/groovy
  • 6. Given Given(~'I have entered (.*)') { number -> calculator.push number } // Implicit coercion to integer Given(~'I have entered (.*)') { int number -> assert number.class == Integer.class calculator.push number }
  • 7. When When(~'I press (w+)') { operatorName -> result = calculator."$operatorName"() } // Can use slashy strings to avoid escaping When(/I press (w+)/) { operatorName -> result = calculator."$operatorName"() }
  • 8. Then Then(~'the result should be (.*)') { double result -> assert expected == result } // == compares equality // not same instance as in Java
  • 9. Power Assert def now = new Date() def old = Date.parse('yyyyMMdd', '20100101') assert now.date == old.date Assertion failed: assert now.date == old.date | | | | | | 19 | | 1 | | Fri Jan 01 00:00:00 GMT 2010 | false Sat Mar 19 13:18:42 GMT 2011
  • 10. Multiline Strings Given some text """ Line 1 Line 2 """ Given(~'some text') { body -> body.eachLine { println it } } => Line 1 => Line 2
  • 11. Tables Given I have the following foods |name |healthy| |Orange|Yes | |Chips |No | When I count the number of healthy items Then I have 1 healthy item
  • 12. Tables Given(~'I have the following foods') { table -> basket = new Basket() table.hashes().each { def item = new Food( name: it.name, // it.get('name') healthy: it.healthy == 'Yes') basket.add(item) } } When(~'I count the healthy items') { numberOfHealthy = basket.numberOfHealthy } Then(~'I have (.+) healthy items') { int count -> assert numberOfHealthy == count }
  • 13. Tables class Basket { private items = [] void add(item) { items << item } int getNumberOfHealthy() { items.findAll { it.healthy }.size() } } class Food { def name def healthy }
  • 14. Organising Step Definitions Cucumber will read in any .groovy files within step_definitions All steps are then available to any scenarios State can be shared between steps by setting to script binding When(~'I set a variable to the binding') { x = 1 } Then(~'the other step can access variable') { assert x == 1 }
  • 15. Before/After Before { // Initialise something } Before('@tagname') { // Initialise only for features/scenarios // tagged with @tagname } Before('~@tagname') {} // not tagged After { // Clean up something }
  • 16. World Allow simple access to methods from within step definitions World { def world = new Object() world.metaClass.mixin Math world } When(~'we take the square root') { sqrt(4) // calls Math.sqrt(4) }
  • 17. Browser Automation with Geb Given(~'I am on the Wikipedia homepage') { go() } When(~'I search for "(.+)"') { query -> $('#searchInput').value(query) $('.searchButton').click() } Then(~'I am shown the "(.+)" article') { article -> assert $('h1').text() == article }
  • 18. env.groovy for Geb import geb.Browser this.metaClass.mixin(cuke4duke.GroovyDsl) World { new Browser('http://wikipedia.org') } After { clearCookies() }
  • 19. Build Tools Integration with • Maven • Ant Cucumber can write reports in JUnit format for CI reports
  • 20. Discussion/Questions Thanks! http://rapaul.com      @rapaul