Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix rest of bugs and errors produced by existing tests

  • Loading branch information...
commit 8f0793190311e7b045d11a8b0a78d7829fe7e061 1 parent ba196e0
@semperos semperos authored
View
23 src/clj_webdriver/core.clj
@@ -88,7 +88,8 @@
(find-elements [driver by] "Retrieve a seq of element objects described by `by`")
(find-elements-by-regex-alone [driver tag attr-val] "Given an `attr-val` pair with a regex value, find the elements that match")
(find-elements-by-regex [driver tag attr-val])
- (find-window-handles [driver attr-val] "Given a browser `driver` and a map of attributes, return the WindowHandle that matches")
+ (find-windows [driver attr-val] "Given a browser `driver` and a map of attributes, return the WindowHandles that matche")
+ (find-window [driver attr-val] "Given a browser `driver` and a map of attributes, return the WindowHandles that matche")
(find-semantic-buttons [driver attr-val] "Find HTML element that is either a `<button>` or an `<input>` of type submit, reset, image or button")
(find-semantic-buttons-by-regex [driver attr-val] "Semantic buttons are things that look or behave like buttons but do not necessarily consist of a `<button>` tag")
(find-checkables-by-text [driver attr-val] "Finding the 'text' of a radio or checkbox is complex. Handle it here.")
@@ -132,6 +133,24 @@
(send-keys [element s] "Type the string of keys into the element object")
(toggle [element] "If the given element object is a checkbox, this will toggle its selected/unselected state. In Selenium 2, `.toggle()` was deprecated and replaced in usage by `.click()`."))
+(defprotocol ISelectElement
+ "Actions specific to select lists"
+ (all-options [select-element] "Retrieve all options from the given select list")
+ (all-selected-options [select-element] "Retrieve a seq of all selected options from the select list described by `by`")
+ (deselect-option [select-element attr-val] "Deselect an option from a select list, either by `:value`, `:index` or `:text`")
+ (deselect-all [select-element] "Deselect all options for a given select list. Does not leverage WebDriver method because WebDriver's isMultiple method is faulty.")
+ (deselect-by-index [select-element idx] "Deselect the option at index `idx` for the select list described by `by`. Indeces begin at 0")
+ (deselect-by-text [select-element text] "Deselect all options with visible text `text` for the select list described by `by`")
+ (deselect-by-value [select-element value] "Deselect all options with value `value` for the select list described by `by`")
+ (first-selected-option [select-element] "Retrieve the first selected option (or the only one for single-select lists) from the given select list")
+ (multiple? [select-element] "Return true if the given select list allows for multiple selections")
+ (select-option [select-element attr-val] "Select an option from a select list, either by `:value`, `:index` or `:text`")
+ (select-all [select-element] "Select all options for a given select list")
+ (select-by-index [select-element idx] "Select an option by its index in the given select list. Indeces begin at 0.")
+ (select-by-text [select-element text] "Select all options with visible text `text` in the select list described by `by`")
+ (select-by-value [select-element value] "Select all options with value `value` in the select list described by `by`"))
+
+
(defn start
"Shortcut to instantiate a driver, navigate to a URL, and return the driver for further use"
([browser url] (start browser url :driver))
@@ -188,7 +207,7 @@
(.executeScript driver js (to-array js-args)))
;; ## Select Helpers ##
-(load "core_select")
+;;(load "core_select")
;; Helper function to find-*
(defn filter-elements-by-regex
View
6 src/clj_webdriver/core_driver.clj
@@ -167,7 +167,7 @@
elements (find-them driver tag attr-vals-without-regex)]
(filter-elements-by-regex elements attr-val))))
- (find-window-handles [driver attr-val]
+ (find-windows [driver attr-val]
(if (contains? attr-val :index)
[(nth (window-handles driver) (:index attr-val))] ; vector for consistency below
(filter #(every? (fn [[k v]] (if (= java.util.regex.Pattern (class v))
@@ -175,6 +175,9 @@
(= (k %) v)))
attr-val) (window-handles driver))))
+ (find-window [driver attr-val]
+ (first (find-windows driver attr-val)))
+
(find-semantic-buttons [driver attr-val]
(let [xpath-parts ["//input[@type='submit']"
"//input[@type='reset']"
@@ -274,7 +277,6 @@
(= "checkbox" (:type attr-val)))
(or (contains? attr-val :text)
(contains? attr-val :label))) (find-checkables-by-text driver attr-val)
- (= tag :window) (find-window-handles driver attr-val)
(= tag :button*) (if (contains-regex? attr-val)
(find-semantic-buttons-by-regex driver attr-val)
(find-semantic-buttons driver attr-val))
View
79 src/clj_webdriver/core_element.clj
@@ -113,4 +113,81 @@
(toggle [element]
(.click (:webelement element))
- element))
+
+
+ ISelectElement
+ (all-options [element]
+ (let [select-list (Select. (:webelement element))]
+ (lazy-seq (.getOptions select-list))))
+
+ (all-selected-options [element]
+ (let [select-list (Select. (:webelement element))]
+ (lazy-seq (.getAllSelectedOptions select-list))))
+
+ (deselect-option [element attr-val]
+ (case (first (keys attr-val))
+ :index (deselect-by-index element (:index attr-val))
+ :value (deselect-by-value element (:value attr-val))
+ :text (deselect-by-text element (:text attr-val))))
+
+ (deselect-all [element]
+ (let [cnt-range (->> (all-options element)
+ count
+ (range 0))]
+ (doseq [idx cnt-range]
+ (deselect-by-index element idx))
+ element))
+
+ (deselect-by-index [element idx]
+ (let [select-list (Select. (:webelement element))]
+ (.deselectByIndex select-list idx)
+ element))
+
+ (deselect-by-text [element text]
+ (let [select-list (Select. (:webelement element))]
+ (.deselectByVisibleText select-list text)
+ element))
+
+ (deselect-by-value [element value]
+ (let [select-list (Select. (:webelement element))]
+ (.deselectByValue select-list value)
+ element))
+
+ (first-selected-option [element]
+ (let [select-list (Select. (:webelement element))]
+ (.getFirstSelectedOption select-list)))
+
+ (multiple? [element]
+ (let [value (attribute element "multiple")]
+ (or (= value "true")
+ (= value "multiple"))))
+
+ (select-option [element attr-val]
+ (case (first (keys attr-val))
+ :index (select-by-index element (:index attr-val))
+ :value (select-by-value element (:value attr-val))
+ :text (select-by-text element (:text attr-val))))
+
+ (select-all [element]
+ (let [cnt-range (->> (all-options element)
+ count
+ (range 0))]
+ (doseq [idx cnt-range]
+ (select-by-index element idx))
+ element))
+
+ (select-by-index [element idx]
+ (let [select-list (Select. (:webelement element))]
+ (.selectByIndex select-list idx)
+ element))
+
+ (select-by-text [element text]
+ (let [select-list (Select. (:webelement element))]
+ (.selectByVisibleText select-list text)
+ element))
+
+ (select-by-value [element value]
+ (let [select-list (Select. (:webelement element))]
+ (.selectByValue select-list value)
+ element)))
View
24 src/clj_webdriver/core_select.clj
@@ -33,6 +33,17 @@
(.deselectByVisibleText select-list text)
element))
+(defn deselect
+ [element attr-val]
+ {:pre (let [k (first (keys attr-val))]
+ (or (= k :index)
+ (= k :value)
+ (= k :text)))}
+ (case (first (keys attr-val))
+ :index (deselect-by-index element (:index attr-val))
+ :value (deselect-by-value element (:value attr-val))
+ :text (deselect-by-text element (:text attr-val))))
+
(defn all-selected-options
"Retrieve a seq of all selected options from the select list described by `by`"
[element]
@@ -88,4 +99,15 @@
[element text]
(let [select-list (Select. element)]
(.selectByVisibleText select-list text)
- element))
+
+(defn select
+ [element attr-val]
+ {:pre (let [k (first (keys attr-val))]
+ (or (= k :index)
+ (= k :value)
+ (= k :text)))}
+ (case (first (keys attr-val))
+ :index (select-by-index element (:index attr-val))
+ :value (select-by-value element (:value attr-val))
+ :text (select-by-text element (:text attr-val))))
View
4 test/clj_webdriver/test/core.clj
@@ -287,7 +287,7 @@
(is (= test-base-url
(:url (window-handle dr))))
(-> dr
- (switch-to-window (find-it dr :window {:url (str test-base-url "clojure")})))
+ (switch-to-window (find-window dr {:url (str test-base-url "clojure")})))
(close dr)
(is (= test-base-url
(:url (window-handle dr)))))
@@ -606,7 +606,7 @@
(is (= test-base-url
(:url (window-handle dr-plain))))
(-> dr-plain
- (switch-to-window (find-it dr-plain :window {:url (str test-base-url "clojure")})))
+ (switch-to-window (find-window dr-plain {:url (str test-base-url "clojure")})))
(close dr-plain)
(is (= test-base-url
(:url (window-handle dr-plain)))))
Please sign in to comment.
Something went wrong with that request. Please try again.