Browser Automation with Geb, Spock, and Groovy

22 October 2018

I recently gave a talk and demonstration, Browser Automation with Geb, Spock, and Groovy, at the Capital Area Software Engineers group in Harrisburg, PA. While explaining the whole stack of software, I showed how to:

  • Start a project in Gradle

  • Get the Geb and Webdriver dependencies in place

  • Get started in Spock testing framework

  • Start up a browser for testing

  • Interact with the page content

  • Wait for asynchronous content

  • Abstract away page components into Geb Page classes

The slides and all the code are available in my geb-preso repo. It includes copies of the code I had prepared, the code we wrote live as a group, and my little toy Planning Poker JS app I was testing.


Alternate Constructors in Groovy

14 September 2017

There are a variety of ways to construct objects in Groovy. We were looking for something more dynamic where we could parameterize the object to be constructed.

We found a couple different things that worked to instantiate an object:

import groovy.transform.*

@ToString
class MyClass {
    String first
    String last
}

def map = [first: 'f', last: 'l']

// instantiate from literal class reference
println new MyClass(map)
println MyClass.newInstance(map)
println (map as MyClass)
println map.asType(MyClass)

// instantiate from a variable reference the class
def clazz = MyClass

println map.asType(clazz)
// println (map as clazz) // 'as' operator doesn't like 'clazz' variable
println clazz.newInstance(map)


Groovy Map Minus

06 June 2017

Groovy is relatively intuitive for me: I can usually guess a method or operator and find it works as I had guessed.

Removing a key/value by the key from a Map conveniently eludes me though. I always guess that I should be able to minus a key from a Map to produce a new Map with that entry /value removed. That doesn’t work, so I needed to invent my own. I still not sure how to practically apply it everywhere though, or if it’s even worthwhile. In practice, I always end up writing the findAll inline.

@Category(Map)
class MapMinus {
    Map minus(Collection keys) {
        this.findAll { k, v -> ! (k in keys) }
    }
    Map minus(Object key) {
        this - [key]
    }
}

use (MapMinus) {
    assert [b: 2, c: 3,] == [a: 1, b: 2, c: 3,] - 'a'
    assert [b: 2, c: 3,] == [a: 1, b: 2, c: 3,] - ['a']

}


JBake with MarkupTemplateEngine

03 November 2016

JBake 2.5.0 got support for the MarkupTemplateEngine, so I wanted to give it a try, since structured code will be nicer than extreme scriptlet stuff that was happening in the original Groovy template example. The stock MTE example shows off MTE templates, but it also switched to Foundation in place of Bootstrap.

I’ve been looking forward to really learning Bootstrap for work and my personal projects, so I’m not looking to switch frameworks right now, so I rebuilt my own example project with MTE and Bootstrap based on the original Groovy/Bootstrap sample I had previously used.

Hopefully, I’ll get a little feedback and the JBake people will incorporate my contribution.


All the Posts

October 2018

September 2017

June 2017

November 2016

January 2016

June 2011

September 2010

January 2010

June 2008

April 2004