Talking testing, automation... and anything else.


A Better Way To Handle Checkboxes in Geb

checkboxGeb is a great automation tool with a lean API but in some cases, perhaps a bit too lean. Case-in-point, checkboxes. Here’s how you handle checkboxes in Geb:

Not the end of the world but IMO, not good enough. It doesn’t read overly well and requiring you to know the value of the checkbox to verify it’s checked, is less than ideal. We can do better… by using modules.

Using a module, we can add methods for handling checkboxes, that are, IMO, easier to read and use.

CheckboxModule

Pretty simple; create a module and add four methods to it. Two that let us check or uncheck a checkbox, and two that verify it’s checked or unchecked. Because isChecked() would require knowing the value of the checkbox (lame), we simply check that is not, not checked (yeah, it hurts my head too).

Now we add the module to our page object and then use the methods in a test…

CLSearchResultsPage

CLSearchSpec

As usual, this code is available on GitHub

Plusone Linkedin Facebook Twitter Digg Email

1 comment

  1. This is a great little class!

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.