> While trying out clj-webdriver (for testing web pages), I got the impulse to
> reduce some of my boilerplate. I'd like your advice on best practices.
I would start with the main test macro, web-test. I would replace your
local variable b with a dynamically bound var *browser* that web-test
is responsible for setting. The options is a map that allows you to
specify browser and implicit-wait timeout like {:browser :firefox
:timeout 60000} but has reasonable defaults so that you can usually
use {} instead.
(defvar ^:dynamic *browser* nil)
(defmacro web-test [name options & actions]
...)
(web-test test-login {}
(-> *browser* (find-it {:text "Login"})
click)
(-> *browser* (find-it {:class "text", :name "login"})
(input-text "username"))
(-> *browser* (find-it {:class "text", :name "password"})
(input-text "password"))
(-> *browser* (find-it :input {:value "Log in"})
click)
(is (-> *browser* (find-it {:href "/logout"})
present?)))
Next, I'd factor our the "(-> *browser* (find-it" pattern with another macro.
(defmacro web-action [search-parameters & actions]
...)
This converts
(-> *browser* (find-it {:text "Login"})
click)
into
(web-action {:text "Login"} click)
If there is a lot of clicking and entering text in fields, I might
also create click-it and write-it macros so that you can say:
(click-it {:text "Login"})
(write-it {:class "text", :name "login"} "username")
After all these changes, the original example becomes:
(web-test test-login {}
(click-it {:text "Login"})
(write-it {:class "text", :name "login"} "username")
(write-it {:class "text", :name "password"} "password")
(click-it {:value "Log in"})
(is (-> *browser* (find-it {:href "/logout"})
present?)))
Hmm, maybe needs an is-present macro as well?
(is-present {:href "/logout"})
If you have a lot of tests related to the same form, you can also make
shortcuts for commonly references elements:
(def login-text {:class "text", :name "login"})
After all these changes, tests like these should be very easy to write.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en