Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update documentation, especially files loaded within core namespace

  • Loading branch information...
commit 85e4fbf2dd47e79356b1cd856e44b37e51b60455 1 parent 99a4f3a
@semperos authored
View
4 src/clj_webdriver/core.clj
@@ -1,4 +1,4 @@
-;; # Clojure Wrapper for Selenium-WebDriver #
+;; # Clojure API for Selenium-WebDriver #
;;
;; WebDriver is a library that allows for easy manipulation of the Firefox,
;; Chrome, Safari and Internet Explorer graphical browsers, as well as the
@@ -220,7 +220,6 @@
(remove #(= % (window-handle* driver))
(doall (window-handles* driver))))
-;; ## By* Functions ##
(load "core_by")
;; ## Actions on WebElements ##
@@ -248,5 +247,4 @@
[driver js & js-args]
(.executeScript driver js (to-array js-args)))
-;; API with clj-webdriver's Driver implementation
(load "core_driver")
View
6 src/clj_webdriver/core_by.clj
@@ -1,3 +1,9 @@
+;; ## Core by-* Functions ##
+;;
+;; These functions are low-level equivalents for the
+;; `ByFoo` classes that make up the Java API, with a few
+;; notable exceptions that provide more flexible matching
+;; (see the `by-attr*` functions at the bottom)
(in-ns 'clj-webdriver.core)
(defn by-id
View
40 src/clj_webdriver/core_driver.clj
@@ -1,3 +1,12 @@
+;; ## Core Driver-related Functions ##
+
+;; This namespace provides the implementations for the following
+;; protocols:
+
+;; * IDriver
+;; * ITargetLocator
+;; * IOptions
+;; * IFind
(in-ns 'clj-webdriver.core)
;; Utility used below
@@ -22,15 +31,15 @@
elements))]
(recur matching-elements (dissoc attr-vals-with-regex attr)))))))
-(extend-type Driver
+(extend-type Driver
- ;;; Basic Functions ;;;
+ ;; Basic Functions
IDriver
(back [driver]
(.back (.navigate (:webdriver driver)))
(cache/seed driver)
driver)
-
+
(close [driver]
(let [handles (window-handles* (:webdriver driver))]
(if (> (count handles) 1) ; get back to a window that is open before proceeding
@@ -55,7 +64,7 @@
(.forward (.navigate (:webdriver driver)))
(cache/seed driver)
driver)
-
+
(get-url [driver url]
(.get (:webdriver driver) url)
(cache/seed driver)
@@ -101,7 +110,7 @@
driver)
- ;;; Window and Frame Handling ;;;
+ ;; Window and Frame Handling
ITargetLocator
(window-handle [driver]
(init-window-handle (:webdriver driver)
@@ -158,7 +167,7 @@
(.activeElement (.switchTo (:webdriver driver))))
- ;;; Options Interface (cookies) ;;;
+ ;; Options Interface (cookies)
IOptions
(add-cookie [driver cookie]
(.addCookie (.manage (:webdriver driver)) cookie))
@@ -174,17 +183,17 @@
(.getCookieNamed (.manage (:webdriver driver)) name))
- ;;; Find Functions ;;;
+ ;; Find Functions
IFind
(find-element [driver by]
(init-element (.findElement (:webdriver driver) by)))
-
+
(find-elements [driver by]
(let [els (.findElements (:webdriver driver) by)]
(if (seq els)
(lazy-seq (map init-element els))
(lazy-seq (map init-element [nil])))))
-
+
(find-elements-by-regex-alone [driver tag attr-val]
(let [entry (first attr-val)
attr (key entry)
@@ -258,7 +267,6 @@
text-xpath (str non-text-xpath "[contains(..,'" (text-kw attr-val) "')]")]
(find-elements driver (by-xpath text-xpath)))))
- ;; TODO: needs test coverage
(find-table-cell [driver table coords]
(when (not= (count coords) 2)
(throw (IllegalArgumentException.
@@ -273,7 +281,6 @@
complete-xpath (str table-xpath row-xpath col-xpath)]
(find-element driver (by-xpath complete-xpath))))
- ;; TODO: needs test coverage
(find-table-row [driver table row]
(let [table-xpath (build-xpath :table table)
row-xpath (str table-xpath "//tr[" (inc row) "]")
@@ -283,7 +290,7 @@
(str row-xpath "//td"))]
(find-elements driver (by-xpath complete-xpath))))
- ;; There is no find-table-col due to XPath irregularity regarding tr counts
+ ;; NOTE: There is no find-table-col due to XPath irregularity regarding tr counts
(find-by-hierarchy [driver hierarchy-vec]
(if (query-with-ancestry-has-regex? hierarchy-vec)
@@ -295,8 +302,8 @@
(find-elements driver (by-xpath (str (build-xpath-with-ancestry hierarchy-vec) "//*")))
(last hierarchy-vec)))
(find-elements driver (by-xpath (build-xpath-with-ancestry hierarchy-vec)))))
-
- ;; NoSuchElementException caught so that `exists?` will behave as expected
+
+
(find-them
([driver attr-val]
(when (keyword? driver) ; I keep forgetting to pass in the WebDriver instance while testing
@@ -347,8 +354,9 @@
(contains-regex? attr-val) (find-elements-by-regex driver (:tag attr-val) attr-val)
:else (find-elements driver (by-xpath (build-xpath (:tag attr-val) attr-val))))
(catch org.openqa.selenium.NoSuchElementException e
+ ;; NoSuchElementException caught here, so we can have functions like `exist?`
(lazy-seq (init-element nil)))))))
-
+
(find-it
([driver attr-val]
(if (and (cache/cache-enabled? driver) (cache/in-cache? driver attr-val))
@@ -362,5 +370,3 @@
(cache/insert driver attr-val el)
el)
el))))))
-
-
View
7 src/clj_webdriver/core_element.clj
@@ -1,3 +1,10 @@
+;; ## Core Element-related Functions ##
+;;
+;; This namespace implements the following protocols:
+;;
+;; * IElement
+;; * IFormElement
+;; * ISelectElement
(in-ns 'clj-webdriver.core)
(extend-type Element
View
10 src/clj_webdriver/js/browserbot.clj
@@ -1,6 +1,14 @@
+;; ## Browserbot ##
+;;
+;; WARNING: Any functions based on JavaScript execution
+;; have no guaranteed behavior across browsers.
+;;
+;; This bit of JavaScript was borred from Watir-WebDriver, which
+;; borrowed it from injectableSelenium.js within Selenium-WebDriver's
+;; own codebase. The `getXpath` function was borrowed from
+;; http://208.91.135.51/posts/show/3754
(ns clj-webdriver.js.browserbot)
-;; Borrowed from Watir-WebDriver, borrowed from injectableSelenium.js in WebDriver, additional getXpath borrowed from http://208.91.135.51/posts/show/3754
(def script
"
var browserbot = {
View
2  src/clj_webdriver/wait.clj
@@ -5,7 +5,7 @@
[org.openqa.selenium.support.ui ExpectedCondition WebDriverWait]
[java.util.concurrent TimeUnit]))
-;;; ## Wait Functionality ##
+;; ## Wait Functionality ##
(defprotocol IWait
"Implicit and explicit waiting"
(implicit-wait [driver timeout] "Specify the amount of time the `driver` should wait when searching for an element if it is not immediately present. This setting holds for the lifetime of the driver across all requests. Units in milliseconds.")
Please sign in to comment.
Something went wrong with that request. Please try again.