groovy and noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/groovy-and-noteworthy.pdf · geb is...
TRANSCRIPT
![Page 1: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/1.jpg)
Groovy and
Noteworthy
Izzet Mustafayev@EPAM Systems@webdizzhttp://webdizz.name
![Page 2: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/2.jpg)
Agenda
● Groovy
○ Specials
○ Basics
○ Infrastructure
● Getting Started
![Page 3: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/3.jpg)
GroovySpecials
![Page 4: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/4.jpg)
Groovy is an agile dynamic language
![Page 5: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/5.jpg)
println 'Hello World!'
![Page 6: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/6.jpg)
Java is a Groovy but Groovy is not Java
![Page 7: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/7.jpg)
Groovy supports DSL
![Page 8: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/8.jpg)
Groovy supports DSL
● A flexible syntax
● Closures
● Meta-programming
● Operator overloading
● No dots and semicolons
● No parentheses, … well almost
![Page 9: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/9.jpg)
Groovy provides statically type check
![Page 10: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/10.jpg)
Groovy provides statically type check
@groovy.transform.TypeChecked void method() { // do nothing}
![Page 11: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/11.jpg)
Groovy Basics
![Page 12: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/12.jpg)
Groovy Shell
![Page 13: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/13.jpg)
Groovy Console
![Page 14: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/14.jpg)
Omission of get/set methodsclass Person { String name String email}
def person = new Person()person.email = '[email protected]'
println person.email //[email protected]
![Page 15: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/15.jpg)
Initializing beans with named parametersclass Person { String name String email}
def person = new Person(name: 'me')
println person.name// me
![Page 16: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/16.jpg)
Context operations using withclass Person { String name String email}def person = new Person(name: 'me', email: '[email protected]')person.with{ println name// me println email// [email protected]}
![Page 17: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/17.jpg)
GStrings (interpolation, multiline)
def param = 'param'def groovyString = """
There is a ‘${param}’ param"""
println groovyString// There is a ‘param’ param
![Page 18: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/18.jpg)
Native syntax for data structures : List
def list = [1, 4, 6, 9]
println list[-2] // 6
list << 10println list.size() // 5
list = list - 10println list // [1, 4, 6, 9]
![Page 19: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/19.jpg)
def map = [UA: 'Ukraine', UK: 'United Kingdom']
println map.UA // Ukraineprintln map[‘UA’] // Ukraine
map << [US: 'United States']println map.US // United States
Native syntax for data structures : Map
![Page 20: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/20.jpg)
Native syntax for data structures : Range
def range = 10..20println range[2] //12
def rangeAlpha = 'a’..'d’println rangeAlpha[2] //c
switch (weight) { case 1..10: shippingCost = 5; break case 11..25: shippingCost = 10; break default: shippingCost = 1; }
![Page 21: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/21.jpg)
Elvis operator for default values
def name = null
println name != null ? name : ’Unknown’ // Unknown
println name ?: ’Unknown’ // Unknown
name = 'name'println name ?: ‘Unknown’ // name
![Page 22: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/22.jpg)
Safe graph navigationif (order != null) { if (order.getCustomer() != null) { if (order.getCustomer().getAddress() != null) {
Address address;address = order.getCustomer().getAddress()System.out.println(address);
} } }
println order?.customer?.address
![Page 23: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/23.jpg)
Closures
printSum = { a, b -> print a+b }
printSum(5, 7)// 12
![Page 24: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/24.jpg)
Closures
upperCasedList = ['a','b','c','d']. collect { it.toUpperCase() }
println upperCasedList // A, B, C, D
![Page 25: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/25.jpg)
MetaprogrammingString.metaClass.cons2var = { ->
String res = ''delegate.toLowerCase()
.tokenize('_')
.each{ s ->res += res ? s.capitalize() : s
} res}
println ’SAMPLE_VAR’.cons2var() //sampleVar
![Page 26: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/26.jpg)
Groovy Infrastructure
![Page 27: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/27.jpg)
Gradle - http://gradle.org/● Strong yet flexible conventions
● Manageable and understandable builds for anything
● Follows convention over configuration approach
● Great plug-ins ecosystem
![Page 28: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/28.jpg)
Spock - https://github.com/spockframework/spock
● Testing and specification framework
● JUnit compatible
● Highly expressive specification language
![Page 29: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/29.jpg)
Easyb - http://easyb.org/● Behavior driven development framework
● Specifications are written in Groovy and run via a Java runner,
command line, Maven or Ant
● Supports a few different styles of specifications ranging from
RSpec's it to a story based DSL with givens, whens, and
thens
![Page 30: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/30.jpg)
Grails - http://grails.org/● Grails is an Open Source, full stack web application
framework for the JVM
● Based on Spring, Hibernate, Sitemesh, etc.
● There are a lot of plug-ins
![Page 31: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/31.jpg)
Grape - http://groovy.codehaus.org/Grape● Grape lets you quickly add maven repository
dependencies to your classpath.
@Grab(group='org.codehaus.sonar', module='sonar-ws-client', version='4.0')@Grab(group='commons-httpclient', module='commons-httpclient', version='3.1')
import org.sonar.wsclient.SonarClient
SonarClient sonarClient = SonarClient.builder().url(URL).login(options.u).password(password).build()
![Page 32: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/32.jpg)
Geb - http://www.gebish.org/● Geb is a browser automation solution
● brings together the power of WebDriver, the elegance of jQuery
content selection, the robustness of Page Object modelling and
the expressiveness of the Groovy
● Can be used for scripting, scraping and general automation — or
equally as a functional/web/acceptance testing solution via
integration with testing frameworks such as Spock, JUnit &
TestNG.
![Page 33: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/33.jpg)
Griffon - http://griffon.codehaus.org● Desktop development framework inspired in Grails
● Primarily Swing based however supports SWT, Pivot,
GTK and JavaFX too
● Growing plugin system (80+ plugins)
![Page 34: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/34.jpg)
Gaelyk - http://gaelyk.appspot.com● Google App Engine development framework based
on Groovy and Groovlets
● Emerging plugin system
![Page 35: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/35.jpg)
GPars - http://gpars.codehaus.org/● Provides DSL and concurrent friendly methods for
collections
● Supports Actors and STM
● Dataflow concurrency model
![Page 36: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/36.jpg)
CodeNarc - http://codenarc.sourceforge.net/● Static analysis for Groovy code
● Over 175 rules to detect defects, bad practices, style
issues etc.
● Build tools and Sonar integration
![Page 37: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/37.jpg)
GVM - http://gvmtool.net/● Manages parallel Versions of multiple SDKs
● Convenient command line interface
● Inspired by RVM
● Supports Groovy, Grails, Gradle etc
● Unfortunately does not work for Win
![Page 38: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/38.jpg)
GroovyServ - http://kobo.github.io/groovyserv/● Improves Groovy’s startup time
![Page 39: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/39.jpg)
Getting Started
![Page 41: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/41.jpg)
Groovy in Action*
by Dierk König
● Groovy committer since
2004
● Frequent conference
speaker
● Contributor to several agile
and testing books
![Page 42: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/42.jpg)
Programming Groovy 2
by Venkat Subramaniam
● An award-winning author
● Famous Agile Guru
● Frequent conference
speaker
![Page 43: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/43.jpg)
![Page 44: Groovy and Noteworthy - jug.uajug.ua/wp-content/uploads/2014/03/Groovy-and-Noteworthy.pdf · Geb is a browser automation solution brings together the power of WebDriver, the elegance](https://reader030.vdocuments.net/reader030/viewer/2022041100/5ed79fca9661ae43ff66a426/html5/thumbnails/44.jpg)
Thank You!
Groovy and
NoteworthyIzzet Mustafayev@EPAM Systems@webdizzhttp://webdizz.name