Skip to content

Commit

Permalink
Merge pull request #3 from weissjeffm/master
Browse files Browse the repository at this point in the history
Fix fill-form to allow filling in-order, also do non-standard inputs
  • Loading branch information
Jeff Weiss committed May 17, 2012
2 parents 462d8b8 + 8c27d85 commit 41e6362
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject com.redhat.qe/extended-selenium "1.0.3" (defproject com.redhat.qe/extended-selenium "1.0.3.1"
:description "An extension of the selenium RC client with extra logging and convenience methods" :description "An extension of the selenium RC client with extra logging and convenience methods"
:java-source-path "src" :java-source-path "src"
:dependencies [[org.seleniumhq.selenium.client-drivers/selenium-java-client-driver "1.0.2"] :dependencies [[org.seleniumhq.selenium.client-drivers/selenium-java-client-driver "1.0.2"]
Expand Down
40 changes: 26 additions & 14 deletions src/com/redhat/qe/auto/selenium/selenium.clj
Expand Up @@ -50,23 +50,35 @@ will be looked up and converted to String locators (see locator-args)"
(defn load-wait [] (defn load-wait []
(browser waitForPageToLoad "60000")) (browser waitForPageToLoad "60000"))


(defn fill-item [el val] (defn fill-item
(let [eltype (browser getElementType el)] "If el is a function, assume vals are args, and call el with args. Otherwise,
(cond (= eltype "selectlist") (browser select el val) el is an element, and it's filled in with val depending on what
(= eltype "checkbox") (browser checkUncheck el (boolean val)) type it is."
:else (browser setText el val)))) [el val]
(if (fn? el)
(apply el val)
(let [eltype (browser getElementType el)]
(cond (= eltype "selectlist") (browser select el val)
(= eltype "checkbox") (browser checkUncheck el (boolean val))
:else (browser setText el val)))))


(defn fill-form (defn fill-form
"Fills in a standard HTML form. items-map is a mapping of locators "Fills in a standard HTML form. items is a mapping of locators of
of form elements, to the string values that should be selected or form elements, to the string values that should be selected or
entered. 'submit' is a locator for the submit button to click at entered. You can also map function names to arglists, to perform
the end. Optional no-arg fn argument post-fn will be called after the other tasks while filling in the form. If you care about the order
submit click." the items are filled in, use a list instead of a map. 'submit' is a
[items-map submit & [post-fn]] locator for the submit button to click at the end. Optional no-arg
(let [filtered (select-keys items-map fn argument post-fn will be called after the submit click.
(for [[k v] items-map :when (not (nil? v))] k))] Example:
(fill-form [:user 'joe' :password 'blow' choose-type ['manager']] :submit)"
[items submit & [post-fn]]
(let [ordered-items (if (sequential? items)
(partition 2 items)
(into [] items))
filtered (filter #(not= nil (second %)) ordered-items )]
(when (-> filtered count (> 0)) (when (-> filtered count (> 0))
(doseq [[el val] filtered] (doseq [[el val] ordered-items]
(fill-item el val)) (fill-item el val))
(browser click submit) (browser click submit)
((or post-fn load-wait))) ((or post-fn load-wait)))
Expand Down

0 comments on commit 41e6362

Please sign in to comment.