• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

WebDriver powered by Clojure

 
Rancher
Posts: 379
22
Mac OS X Monad Clojure Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 27
Android Clojure Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?


 
Sean Corfield
Rancher
Posts: 379
22
Mac OS X Monad Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic