This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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:
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.
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.