aspose file tools*
The moose likes Clojure and the fly likes WebDriver powered by Clojure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Languages » Clojure
Bookmark "WebDriver powered by Clojure" Watch "WebDriver powered by Clojure" New topic
Author

WebDriver powered by Clojure

Sean Corfield
Ranch Hand

Joined: Feb 09, 2011
Posts: 231
    
    3

Back in October, I mentioned that we were using Clojure to drive our WebDriver tests (Selenium) but I didn't go into much detail. I actually wrote a blog post back then about it which shows how I controlled when the browser opened and closed (for a single test or a suite of tests), as well as showing what a test looked like:

Automated Browser-based Testing with Clojure

We're really liking Clojure as a testing language since we can easily create domain-specific functions that encapsulate certain actions within our web site so that our tests read much more cleanly. An example from that blog post:

And by way of explanation:
The login and go-to functions are just conveniences (in testsuite.core) to login to a specified website with a given username and password (:eg represents eligiblegreeks.com) and go to a specific URL. This test verifies that if you make a change (on this test profile), you get the success message and you still get the partial profile message.

One of the real pleasures of working with WebDriver in Clojure is that it's easy to develop tests in the REPL, driving the web browser interactively as you type in code and evaluate it, form by form. You can tell the browser to navigate around your application, develop domain specific functions to encapsulate that logic, and verify assumptions about the application's behavior, directly and interactively - without any sort of edit, compile, run cycle.

We've also been using Clojure to test-drive the development of a new REST API we are working on. We wrote simple Clojure functions to perform GET and POST operations on the REST API endpoint (using clj-http) and then we can write tests like:

Very clear and expressive. This code is using Jay Fields' "Expectations" library for a more BDD-style of test. The WebDriver test above uses Clojure's built-in testing library.
Gary Deer
Greenhorn

Joined: Aug 20, 2010
Posts: 26

Wow that is a lot nicer than the automated gui regression testing framework I'm having to deal with at the moment. Thanks for sharing.

I really like how I was able to show your code snippets to someone who had never seen Clojure before and they were still able to explain what is going on in the "edit-my-profile" test in a matter of seconds -- quite a beautiful thing.

Is Browser-based testing one of those boring things you use Clojure for, or is this the start of a new series on doing the interesting things in Clojure?



When all you have is a hammer, everything looks like a thumb.
Sean Corfield
Ranch Hand

Joined: Feb 09, 2011
Posts: 231
    
    3

Gary Deer wrote:Is Browser-based testing one of those boring things you use Clojure for, or is this the start of a new series on doing the interesting things in Clojure?

I consider it to be another boring thing that we're using an exciting language for
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: WebDriver powered by Clojure
 
Similar Threads
Clojure for boring stuff
Better Automated Testing Tool
New Automation Testing Tool
Selenium 2 Best Practice
Non J2EE transactional management in Java