Talking testing, automation... and anything else.


Organizing User Data In Your Geb Tests

gebGeb offers a number of conveniences for writing Selenium Webdriver tests but it draws the line at organizing data. Lacking a sanctioned solution, I rolled my own, making use of Groovy maps (hashes).

Here’s an example of how I’ve been organizing my user data. The following code is a working example (thanks Moodle!) and you can download the full example code from GitHub.

Pretty simple. I created a package named data, added a UserData class file to it, and filled it with four maps, one for each user our example app.

Then we use it thusly…

We assign one of the user maps to a static property, admin(line 6), then use that property to log in (line 13), and then to verify we’re logged in (line 20).

This approach can really help improve code readability and offers one location to organize all of your data. It can also help with test maintenance, as changes to data need not require updating your tests. This works well for user data but should work with just about any kind of data.

Plusone Linkedin Facebook Twitter Digg Email

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.