Browse files

Fix Firefox-specific functions, add support for a few more in Firefox…

  • Loading branch information...
1 parent 2987cce commit e315cb983e32ecb631c2f51be250d9ce82230993 @semperos semperos committed Jan 4, 2012
Showing with 37 additions and 21 deletions.
  1. +37 −21 src/clj_webdriver/firefox.clj
@@ -4,34 +4,30 @@
(:require [ :as io])
(:import org.openqa.selenium.firefox.FirefoxProfile))
-(defn new-firefox-driver
- "Create new Driver given a browser type. If an additional profile object or string is passed in, Firefox will be started with the given profile instead of the default.
- This is the preferred method for starting up a browser, as it leverages clj-webdriver-specific functionality not available with vanilla WebDriver instances. You can always access the underlying WebDriver instance with the :webdriver key of your Driver record."
- ([]
- (init-driver (new-webdriver* :firefox)))
- ([profile]
- (init-driver (new-webdriver* :firefox profile)))
- ([profile cache-spec]
- (init-driver (new-webdriver* :firefox profile) cache-spec))
- ([profile cache-spec cache-args]
- (init-driver (new-webdriver* :firefox profile) cache-spec cache-args)))
(defn new-profile
"Create an instance of `FirefoxProfile`"
- []
- (FirefoxProfile.))
+ ([] (FirefoxProfile.))
+ ([profile-dir] (FirefoxProfile. (io/file profile-dir))))
(defn enable-extension
- "Given a `FirefoxProfile` object, enable an extension located at `extension-location`."
- [profile extension-location]
- (let [ext-file (io/as-file extension-location)]
+ "Given a `FirefoxProfile` object, enable an extension.
+ The `extension` parameter should either be (1) a File object pointing to an extension, (2) a String representation of the full path to an object, or (3) a keyword like `:firebug` which, by convention, will make clj-webdriver check an environment variable `FIREFOX_EXTENSION_FIREBUG`, hence `FIREFOX_EXTENSION_` plus the name of the plugin (keyword to string, dashes to underscores and uppercase)"
+ [profile extension]
+ (let [ext-file (if (keyword? extension)
+ (io/file (System/getenv
+ (-> extension
+ name
+ (.replace "-" "_")
+ .toUpperCase))))
+ (io/file extension))]
(.addExtension profile ext-file)))
(defn set-preferences
"Given a `FirefoxProfile` object and a map of preferences, set the preferences for the profile."
- [profile pref-m]
- (doseq [entry pref-m]
+ [profile pref-map]
+ (doseq [entry pref-map]
(.setPreference profile (name (key entry)) (val entry))))
(defn accept-untrusted-certs
@@ -42,4 +38,24 @@
(defn enable-native-events
"Set whether or not native events should be enabled (true by default on Windows, false on other platforms)."
[profile bool]
- (.setEnableNativeEvents profile bool))
+ (.setEnableNativeEvents profile bool))
+(defn is-running
+ "Return true if the profile in the given `profile-dir` is the one running"
+ [profile profile-dir]
+ (.isRunning profile (io/file profile-dir)))
+(defn write-to-disk
+ "Write the given profile to disk. Makes sense when building up an anonymous profile via clj-webdriver."
+ [profile]
+ (.layoutOnDisk profile))
+(defn json
+ "Return JSON representation of the given `profile` (can be used to read the profile back in via `profile-from-json`"
+ [profile]
+ (.toJson profile))
+(defn profile-from-json
+ "Instantiate a new FirefoxProfile from a proper JSON representation."
+ [^String json]
+ (FirefoxProfile/fromJson json))

0 comments on commit e315cb9

Please sign in to comment.