Permalink
Browse files

Remove new-from-webdriver, add conditional logic to init-driver

  • Loading branch information...
1 parent bdda5c7 commit 633867adf2933edd62cb59b7c4abaccbca2e2f9e @semperos committed Feb 11, 2013
Showing with 14 additions and 11 deletions.
  1. +1 −5 src/clj_webdriver/core.clj
  2. +13 −6 src/clj_webdriver/driver.clj
@@ -198,17 +198,13 @@
:profile profile})
:cache-spec cache-spec}))))
-(defn new-from-webdriver
- ([webdriver]
- (Driver. webdriver nil nil nil)))
-
;; Chrome binary, common location of Chromium on Linux
(comment
(do
(import 'org.openqa.selenium.remote.DesiredCapabilities)
(let [cap (DesiredCapabilities/chrome)]
(.setCapability cap "chrome.binary" "/usr/lib/chromium-browser/chromium-browser")
- (new-from-webdriver (ChromeDriver. cap))))
+ (init-driver (ChromeDriver. cap))))
)
(defn start
@@ -20,17 +20,24 @@
(:args cache-spec)))))))
(defn init-driver
- "Constructor for Driver records. Accepts a `driver-spec` map with the following keys:
+ "Constructor for Driver records. Accepts either an existing WebDriver instance, or a `driver-spec` map with the following keys:
webdriver - WebDriver instance
cache-spec - map with keys :strategy, :args, :include and :exclude, used to setup caching rules"
([] (init-driver {}))
([driver-spec]
- (let [{:keys [webdriver capabilities cache-spec]} driver-spec]
- (Driver. webdriver
- capabilities
- (assoc cache-spec :cache (init-cache cache-spec))
- (Actions. webdriver)))))
+ (let [wd-class (Class/forName "org.openqa.selenium.WebDriver")
+ uppers (supers (.getClass driver-spec))]
+ (if (some #{wd-class} uppers)
+ (Driver. driver-spec
+ nil
+ nil
+ (Actions. driver-spec))
+ (let [{:keys [webdriver capabilities cache-spec]} driver-spec]
+ (Driver. webdriver
+ capabilities
+ (assoc cache-spec :cache (init-cache cache-spec))
+ (Actions. webdriver)))))))
(defn driver?
"Function to check class of a Driver, to prevent needing to import it"

0 comments on commit 633867a

Please sign in to comment.