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:
- Download the Selenium standalone server jar & the Selenium Java jar
- Create a new Groovy project in Intellij
- In the new Intellij Groovy Project, click File | Project Structure
- Click On Libraries
- Click the + Sign and select where you downloaded the Selenium standalone server jar file
- 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:
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.