I was looking at 
http://saucelabs.com/blog/index.php/2009/12/running-your-selenium-tests-in-parallel-clojure/
and in the comments, :Scott suggested that a macro could reduce some
of the boilerplate that you see here:

(def test-google
  {
   :name "google"
   :test (fn [client]
           (doto client
             (.open "http://www.google.com";)
             (.type "q" "Sauce Labs")
             (.click "btnG")
             (.waitForPageToLoad "5000"))
           (.isTextPresent client "Selenium"))})

(def test-yahoo
  {
   :name "yahoo"
   :test (fn [client]
           (doto client
             (.open "http://yahoo.com";)
             (.type "p" "Sauce Labs")
             (.click "search-submit")
             (.waitForPageToLoad "5000"))
           (.isTextPresent client "Selenium"))})

You can see the boilerplate of defining the map, typing the names of
the two keys, calling the thing "test-<name>" ... So I tried writing a
macro for this. But when I use my first attempt, it says Can't use
qualified name as parameter. Here's my first attempt:

(defmacro deftest [name & body]
  (let [test-n (symbol (str "test-" name))
        n (str name)]
    `(def ~test-n
          {:name ~n
           :test (fn [client]
                   ~@body)})))

The macro expansion of the following looks good, but actually running
it yields the complaint mentioned above:

  (deftest google
    (doto client
      (.open "http://www.google.com";)
      (.type "q" "Sauce Labs")
      (.click "btnG")
      (.waitForPageToLoad "5000"))
    (.isTextPresent client "Selenium"))

My second attempt works ......

(defmacro deftest [name client & body]
  (let [test-n (symbol (str "test-" name))
        n (str name)]
    `(def ~test-n
          {:name ~n
           :test (fn [~client]
                   ~@body)})))

... but now the user has to mention the client twice:

  (deftest google client
    (doto client
      (.open "http://www.google.com";)
      (.type "q" "Sauce Labs")
      (.click "btnG")
      (.waitForPageToLoad "5000"))
    (.isTextPresent client "Selenium"))

How do I get around this?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to