Permalink
Browse files

Add new quick-fill-submit function, take out support for submit? para…

…meter in quick-fill
  • Loading branch information...
1 parent 79e13ed commit 416e102a04fbe02f1201f040ee6708bbcddcbd4d @semperos semperos committed Jan 6, 2012
Showing with 32 additions and 33 deletions.
  1. +32 −33 src/clj_webdriver/form_helpers.clj
@@ -9,52 +9,51 @@
(:import org.openqa.selenium.WebDriver))
(defn- quick-fill*
- [driver k v submit?]
- ;; shortcuts:
- ;; k as string => element's id attribute
- ;; v as string => text to input
- (let [query-map (if (string? k)
- {:id k}
- k)
- action (if (string? v)
- #(input-text % v)
- v)
- target-els (find-them driver query-map)]
- (if submit?
- (doseq [el target-els]
- (action el))
- (apply action target-els))))
+ ([driver k v] (quick-fill* driver k v false))
+ ([driver k v submit?]
+ ;; shortcuts:
+ ;; k as string => element's id attribute
+ ;; v as string => text to input
+ (let [query-map (if (string? k)
+ {:id k}
+ k)
+ action (if (string? v)
+ #(input-text % v)
+ v)
+ target-els (find-them driver query-map)]
+ (if submit?
+ (doseq [el target-els]
+ (action el))
+ (apply action target-els)))))
(defprotocol IFormHelper
"Useful functions for dealing with HTML forms"
(quick-fill
[driver query-action-maps]
- [driver query-action-maps submit?]
"`driver` - browser driver
`query-action-maps` - a seq of maps of queries to actions (queries find HTML elements, actions are fn's that act on them)
- `submit?` - (WARNING: CHANGES RETURN TYPE) boolean, whether or not the call to this function will submit the form in question
- Note that an \"action\" that is just a String will be interpreted as a call to `input-text` on that String for the target text field
+ Note that a \"query\" that is just a String will be interpreted as the id attribute of your target element.
+ Note that an \"action\" that is just a String will be interpreted as a call to `input-text` with that String for the target text field.
Example usage:
(quick-fill a-driver
[{\"first_name\" \"Rich\"}
- {{:class \"foobar\"} click}])"))
+ {{:class \"foobar\"} click}])")
+ (quick-fill-submit
+ [driver query-action-maps]
+ "Same as `quick-fill`, but expects that the final step in your sequence will submit the form, and therefore clj-webdriver will not return a value (since all page WebElement objects are lost in Selenium-WebDriver's cache after a new page loads)"))
(extend-type Driver
IFormHelper
(quick-fill
- ([driver query-action-maps] (quick-fill driver query-action-maps false))
- ([driver query-action-maps submit?]
- (doseq [entries query-action-maps,
- [k v] entries]
- (quick-fill* driver k v submit?)))))
-
-(extend-type WebDriver
- IFormHelper
- (quick-fill
- ([driver query-action-maps] (quick-fill driver query-action-maps false))
- ([driver query-action-maps submit?]
- (doseq [entries query-action-maps,
- [k v] entries]
- (quick-fill* driver k v submit?)))))
+ [driver query-action-maps]
+ (doseq [entries query-action-maps
+ [k v] entries]
+ (quick-fill* driver k v)))
+
+ (quick-fill-submit
+ [driver query-action-maps]
+ (doseq [entries query-action-maps
+ [k v] entries]
+ (quick-fill* driver k v true))))

0 comments on commit 416e102

Please sign in to comment.