I’m not a fan of the GEB browser automation framework for Groovy.  In fact I prefer to use just straight selenium with Groovy.

Getting up and going with Selenium in Groovy should be pretty easy.

If you’re using Intellij here’s what you would do:

  1. Download the Selenium standalone server jar  & the Selenium Java jar
  2. Create a new Groovy project in Intellij
  3. In the new Intellij Groovy Project, click File |  Project Structure
  4. Click On Libraries
  5. Click the + Sign and select where you downloaded the Selenium standalone server jar file
  6. Repeat step 5 and point to the Selenium Java Jar.

That’s it.  At this point you should be able to create a new groovy file and do your regular imports, like:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

Instantiating the Driver is just like in Java:

WebDriver ffBrowser = new FirefoxDriver()

Why Use Groovy?

Well… for one thing you can use all those nice Java libraries… such as Sikuli.  Imagine you had a case where you want to do this web automation, but there’s one component that is behind a closed API (i.e. Flash) and you need to click a button in that element.  You can’t rely on Webdriver for that one bit of trickery… so you Use webdriver to launch the browser, click on elements it has access to and use Sikuli for finding visual reference on the screen when needed.

Why Not Use GEB?

I have tried GEB on several occasions… I am not a fan, namely because of the poor dependency issues.  I’ve gone into greater detail on my frustration in previous posts.

Why Not Use JRuby with Watir?

Actually I think that’s a fine solution.  But it will limit your Ruby version to 1.9.3 (which is what JRuby uses.)  It also will be a problem with potential Sikuli issues… I’ve gotten it to work, but Sikui and JRuby definitely do not play as nice as Groovy and Sikuli.

How do I install Sikuli in Groovy?

Same way as before… in Intellij, we go to the Project Structure, click libraries and point to your Sikuli-java.jar file… to get that file, you have to download the Sikuli setup file from the Sikuli website, and then run the setup (choosing of course the Java checkboxes.)  This will create a the Sikuli-Java.jar file for you.


5 Responses

  1. Hi, I have been working on browser automation testing using java and selenium. And a few months later I realized that our I’m working on not only selenium and java, but groovy, geb and spock also. So, I am trying to learn groovy, geb and spock but not getting any relevant site for the same.

    Could you please provide me the tutorial link for the same.

    • I should be honest and tell you up front that I’m not a fan of GEB, but my experience with it is from many years ago (around 2010)… My main problem with GEB is that it wasn’t well maintained. GEB was a developer solution to a QA problem. The real issue was that it didn’t have a strong QA community supporting it. When I worked at eHarmony, we were forced to use GEB, and it was insane how bad it was. It took 3 dev’s 2 weeks to get it working right… then once handed over to QA we had a situation were Firefox was upping their version every 2 weeks (over the space of a month)… GEB fell considerably behind, because it lacked a community to support it (took the GEB community back then, almost a year to catch up to the Firefox API changes). Then there’s the problem of GEB’s own dependancies… it relies on Spock, which can significantly lag behind (they were in beta for years). HOWEVER, that was many years ago… I just looked it up and it’s now up to version 4.0… so maybe things have changed. I’ll give it another go and see if it’s gotten any better. I personally either make my own software automation, or for web automation I use Python’s Golem… as I like Python, and it has a UI for reports. Regarding your question. The only documentation I know on GEB is https://gebish.org/manual/current/

      GEB is useful if you’re somehow embedding into the use cases / back end automation. If doing strictly FE automation, there’s so many choices, but probably a JS automation system would be best, to directly work with JS calls on the FE. I like Python so I use Golem, even though the codebase I work in is Groovy/Grails based. But hey, I’ll try GEB again, and if it’s improved maybe I’ll do a write up on it. Thanks for bringing GEB up again, I thought it had died out years ago.

    • Read my other reply first… but I wanted to add this regarding Spock… Spock is the Groovy version of BDD (Behavior Driven Development). Spock didn’t invent this, in fact Spock copied this from other tools that did this, implementing it for Groovy. If you want to know Spock, google “BDD” or “Behavior Driven Development” … check out this https://en.wikipedia.org/wiki/Behavior-driven_development I first learned BDD with GEB (GEB was my first automation framework to use, many years ago when I first started out). I discovered later that Cucumber had a more flushed out version of BDD and I used that for some time. BDD is fine, if you have a team to support it. Since they’re using GEB… look into BDD. Once you understand the concepts of BDD, then Spock should be easy. If it is still confusing, consider trying Cucumber first… and see if it makes more sense. With Cucumber in a JetBrains IDE I was able to do the GIVEN, WHEN, THEN tests, and right click the Given, to jump to the code itself. The GIVEN WHEN THEN is just English (no code), that dynamically links to an automation file. So one person can read the Spock template (knowing no code) and understand what the test is supposed to do. I think these days it makes little sense as anyone touching the tests will be proficient to read the code.

  2. Hi Brian,

    We are looking to build a hybrid selenium framework that will be functional tester-friendly. A big challenge. I want to build this using Groovy and Selenium. Do you know of any good resources for basic setup to include reporting. We will build out the modules, object repo, libraries, etc once we have groovy running.

    Thank you,

    • Hi Paul. Thanks for the comment. Although I write tools in grails and groovy, I don’t use it for web automation. There’s a considerable amount of user acceptance testing options available with everything you desire already built. Are you sold on groovy as a solution? I’ve noticed a big uptick in comments on my site asking about Groovy as an automation solution and I’m a bit surprised. Groovy, AFAIK only has one framework – GEB. I’m not a fan of it. You can, of course, build your own framework… but to me that seems impractical considering suites like Python’s Golem that already exist. Golem has a lightweight web app, that users can either write the automation code (in python) in, or for those who can’t code, it has an interface to input the html element id/class along with actions (click, send_keys, etc.) and it has some of the best reporting I’ve seen in a pre-built framework. As I’m language agnostic, I’ve used Grails to build out specific automation utilities in telecom, but for web automation… I like using Golem. If you have a moment I’d like to tell you my personal opinions on Groovy as a QA choice. I respect your approach, but perhaps this might be worth considering:

      Groovy would be a fine choice, except the dev team behind it pitches Groovy to Java Devs. At some point you’ll want your QA entities to contribute to the infrastructure so you/devs don’t have to keep maintaining it while you’re busy with core dev projects. I was in this exact situation in 2010 at eHarmony. The problem with groovy was that each QA entity that approached learning it was pushed away by the Groovy resources themselves… which stated in almost every text, “this is for Java developers.” Instead of speaking to non-Java devs, Groovy resources assume a working knowledge of Java architecture and best practices. So we have a language that would benefit a niche of people who don’t need to know Java, but the resources behind it are pitched to people who only know Java. To complicate it even more… Java developers tend to resist Groovy because of it’s lack of architecture (hidden getters/setters, lack of private classes) – I mean yes, there are teams of Java devs that use Grails/Groovy… I’m on one right now… but most Java devs I know complain about the “strangeness” of the language, preferring the rigidity of Java. So how does a QA person, who has little code knowledge, jump in to contribute to a Groovy based framework? For that entity, it’s very tough to step up.

      Languages that are beginner friendly would be: Ruby, Python and JavaScript.. Those, in my humble opinion, are the best choices for a QA team, if the team has members who lack descent coding skills. It’s much easier to find resources to teach Ruby or Python as a first language, than to teach Groovy as a first language. Two caveats here:

      1. Now if your goal is to be a QA architect and you only exist to maintain and build on the infrastructure… and the testers never take over the project (which I think is a brittle option… if you leave it’s all gone) then you can do it in whatever language you prefer… Groovy, Kotlin, C, etc. Unfortunately I don’t have any resources to setup this up, other than GEB… which is a groovy framework making use of Spock, and selenium… however I don’t think it has reporting.

      2. if your QA team is already Groovy/Java fluent then you have no problem and sure, go ahead … again the resources on this are sparse as its not as common as doing this in Python, Ruby or JavaScript. GEB is a first step to see how they did it.

      I’ve had bosses who asked me, “why use ruby/javascript/python? we’re a java shop…” to which I answer, it’s easy for people to pick these languages up… they has more than one framework, and the automation doesn’t need to be the same language as the core dev. Web automation should be focused on user acceptance tests… it should replicate the user experience, and therefore shouldn’t be invoking the backend outside of the user flow. If there is a need for something to be done in the backend we create an API that is only available to internal IP’s of the company, and exposing it to the testers.

      # An Idea for using Grails #
      Now that I’ve said all that… You can do a lot of fast prototyping in Grails… if you take Python’s golem, it could be easily reproduced in Grails. Create a web app that has a user interface / scaffold to accept fields values for HTML css elements and what actions you have available. If I had to use Groovy/Grails… that’s how I’d probably do it. I’d manage the reporting by hand in Groovy/Grails.

      I might sound negative… I don’t mean to… I love Grails. I just remember what it was like in 2010 when our team of devs at eHarmony decided how QA would embrace automation… and it became a dev centered project, taking away the QA aspect… it was a burden. Most Groovy projects we used (like Spock) were poorly maintained and we got caught in positions with lacking community updates to the latest version of selenium / web browsers.

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Comments