Permalink
Browse files

Allow for customizing the app-under-test from command-line

Replace use of hardcoded test-base-url with base-url function that checks for a TEST_BASE_URL variable in the environment and gives preference to that. This is in preparation for support for testing with things like SauceLabs.
  • Loading branch information...
1 parent 1d5c21f commit 334f3eb9281dbe8f92536ba9a634a926b39a423f @semperos committed Dec 18, 2012
@@ -3,7 +3,7 @@
[clj-webdriver.core :only [start new-driver to quit]]
[clj-webdriver.test.common :only [run-common-tests]]
[clj-webdriver.test.util :only [start-server]]
- [clj-webdriver.test.config :only [test-base-url]])
+ [clj-webdriver.test.config :only [base-url]])
(:require [clojure.tools.logging :as log]))
;; Driver definitions
@@ -19,7 +19,7 @@
(defn reset-browser-fixture
[f]
- (to @chrome-driver test-base-url)
+ (to @chrome-driver (base-url))
(f))
(defn quit-browser-fixture
@@ -3,7 +3,7 @@
(:use clojure.test
[clj-webdriver core util wait options form-helpers]
[clj-webdriver.test.util :only [thrown? exclusive-between]]
- [clj-webdriver.test.config :only [test-base-url]])
+ [clj-webdriver.test.config :only [base-url]])
(:require [clj-webdriver.cache :as cache]
[clj-webdriver.window :as win]
[clojure.java.io :as io]
@@ -19,7 +19,7 @@
(defn test-browser-basics
[driver]
(is (= clj_webdriver.driver.Driver (class driver)))
- (is (= test-base-url (current-url driver)))
+ (is (= (base-url) (current-url driver)))
(is (= "Ministache" (title driver)))
(is (boolean (re-find #"(?i)html>" (page-source driver)))))
@@ -29,16 +29,16 @@
(find-element {:tag :a, :text "example form"})
click)
(Thread/sleep 500) ;; race condition issue with OperaDriver (on my machine, at least)
- (is (= (str test-base-url "example-form") (current-url driver)))
+ (is (= (str (base-url) "example-form") (current-url driver)))
(back driver)
- (is (= test-base-url (current-url driver)))
+ (is (= (base-url) (current-url driver)))
(forward driver)
- (is (= (str test-base-url "example-form") (current-url driver))))
+ (is (= (str (base-url) "example-form") (current-url driver))))
(defn to-should-open-given-url-in-browser
[driver]
- (to driver (str test-base-url "example-form"))
- (is (= (str test-base-url "example-form") (current-url driver)))
+ (to driver (str (base-url) "example-form"))
+ (is (= (str (base-url) "example-form") (current-url driver)))
(is (= "Ministache" (title driver))))
(defn should-be-able-to-find-element-bys-using-low-level-by-wrappers
@@ -70,7 +70,7 @@
(attribute (find-element-by driver (by-attr-ends :option :value "_media")) :value)))
(is (= "france"
(attribute (find-element-by driver (by-has-attr :option :value)) :value)))
- (to driver test-base-url)
+ (to driver (base-url))
(is (= "first odd"
(attribute (find-element-by driver (by-class-name "first odd")) :class)))
;; (is (= "http://clojure.blip.tv/file/4824610/"
@@ -257,7 +257,7 @@
(defn test-form-elements
[driver]
- (to driver (str test-base-url "example-form"))
+ (to driver (str (base-url) "example-form"))
;; Clear element
;; (-> driver
;; (find-element [{:tag :form, :id "example_form"}, {:tag :input, :name #"last_"}])
@@ -332,7 +332,7 @@
(defn select-element-functions-should-behave-as-expected
[driver]
- (to driver (str test-base-url "example-form"))
+ (to driver (str (base-url) "example-form"))
(let [select-el (find-element driver {:tag "select", :id "countries"})]
(is (= 4
(count (all-options select-el))))
@@ -433,7 +433,7 @@
(defn quick-fill-should-accept-special-seq-and-perform-batch-actions-on-form
[driver]
- (to driver (str test-base-url "example-form"))
+ (to driver (str (base-url) "example-form"))
(quick-fill driver
[{"first_name" clear}
{"first_name" "Richard"}
@@ -456,7 +456,7 @@
(defn quick-fill-submit-should-always-return-nil
[driver]
- (to driver (str test-base-url "example-form"))
+ (to driver (str (base-url) "example-form"))
(is (nil?
(quick-fill-submit driver
[{"first_name" clear}
@@ -482,22 +482,22 @@
(is (= 2
(count (windows driver))))
(switch-to-window driver (second (windows driver)))
- (is (= (str test-base-url "clojure")
+ (is (= (str (base-url) "clojure")
(:url (window driver))))
(switch-to-other-window driver)
- (is (= test-base-url
+ (is (= (base-url)
(:url (window driver))))
(-> driver
- (switch-to-window (find-window driver {:url (str test-base-url "clojure")})))
+ (switch-to-window (find-window driver {:url (str (base-url) "clojure")})))
(close driver)
- (is (= test-base-url
+ (is (= (base-url)
(:url (window driver)))))
(defn test-alert-dialog-handling
[driver]
(click (find-element driver {:text "example form"}))
(let [act (fn [] (click (find-element driver {:tag :button})))]
- (act)
+ (act)
(is (alert-obj driver) "No alert dialog could be located")
(accept driver)
(is (thrown? NoAlertPresentException
@@ -592,7 +592,7 @@
;;; Fixture fn's ;;;
(defn reset-driver
[driver]
- (to driver test-base-url))
+ (to driver (base-url)))
(defn seed-driver-cache
[driver]
@@ -3,4 +3,9 @@
;; ## Setup ##
(def test-port 5744)
(def test-host "localhost")
-(def test-base-url (str "http://" test-host ":" test-port "/"))
+(def test-base-url (str "http://" test-host ":" test-port "/"))
+
+(defn base-url
+ "Allow overriding base URL for testing from command line."
+ []
+ (get (System/getenv) "TEST_BASE_URL" test-base-url))
@@ -5,7 +5,7 @@
[clj-webdriver.cache :only [get-cache]]
[clj-webdriver.test.common :only [run-common-tests]]
[clj-webdriver.test.util :only [start-server]]
- [clj-webdriver.test.config :only [test-base-url]])
+ [clj-webdriver.test.config :only [base-url]])
(:require [clj-webdriver.cache :as cache]
[clj-webdriver.firefox :as ff]
[clojure.java.io :as io]
@@ -31,8 +31,8 @@
(defn reset-browser-fixture
[f]
- (to @firefox-driver test-base-url)
- (to @firefox-driver-no-cache test-base-url)
+ (to @firefox-driver (base-url))
+ (to @firefox-driver-no-cache (base-url))
(f))
(defn quit-browser-fixture
@@ -99,7 +99,7 @@
:cache-spec {:strategy :basic,
:args [{}],
:exclude [ {:css "ol#pages"} ]}}
- test-base-url)]
+ (base-url))]
(is (not (cache/cacheable? temp-dr {:css "ol#pages"})))
(find-elements temp-dr {:css "ol#pages"})
(is (empty? (dissoc @(get-in temp-dr [:cache-spec :cache]) :url)))
@@ -110,14 +110,14 @@
(deftest firefox-should-support-custom-profiles
(is (with-browser [tmp-dr (start {:browser :firefox
:profile (ff/new-profile)}
- test-base-url)]
+ (base-url))]
(log/info "[x] Starting Firefox with custom profile.")
(driver? tmp-dr))))
(deftest firefox-should-support-extensions
(is (with-browser [tmp-dr (start {:browser :firefox
:profile (doto (ff/new-profile)
(ff/enable-extension :firebug))}
- test-base-url)]
+ (base-url))]
(log/info "[x] Starting Firefox with extensions.")
(driver? tmp-dr))))
@@ -2,7 +2,7 @@
clj-webdriver.test.remote
(:use clojure.test
[clj-webdriver.core :only [quit to]]
- [clj-webdriver.test.config :only [test-base-url]]
+ [clj-webdriver.test.config :only [base-url]]
[clj-webdriver.test.util :only [start-server]]
[clj-webdriver.test.common :only [run-common-tests]]
[clj-webdriver.remote.server :only [new-remote-session stop]])
@@ -23,7 +23,7 @@
(defn reset-browser-fixture
[f]
- (to @driver test-base-url)
+ (to @driver (base-url))
(f))
(defn quit-fixture
@@ -2,7 +2,7 @@
clj-webdriver.test.remote-capabilities
(:use clojure.test
[clj-webdriver.core :only [quit to]]
- [clj-webdriver.test.config :only [test-base-url]]
+ [clj-webdriver.test.config :only [base-url]]
[clj-webdriver.test.util :only [start-server]]
[clj-webdriver.test.common :only [run-common-tests]]
[clj-webdriver.remote.server :only [new-remote-session stop]])
@@ -23,7 +23,7 @@
(defn reset-browser-fixture
[f]
- (to @driver test-base-url)
+ (to @driver (base-url))
(f))
(defn quit-fixture
@@ -2,7 +2,7 @@
(ns clj-webdriver.test.remote-existing
(:use clojure.test
[clj-webdriver.core :only [quit to]]
- [clj-webdriver.test.config :only [test-base-url]]
+ [clj-webdriver.test.config :only [base-url]]
[clj-webdriver.test.util :only [start-server]]
[clj-webdriver.test.common :only [run-common-tests]]
[clj-webdriver.remote.server :only [new-remote-session stop]]))
@@ -35,7 +35,7 @@
(defn reset-browser-fixture
[f]
- (to @driver test-base-url)
+ (to @driver (base-url))
(f))
(defn quit-fixture
@@ -1,7 +1,7 @@
(ns clj-webdriver.test.taxi
(:use clojure.test
clj-webdriver.taxi
- [clj-webdriver.test.config :only [test-base-url]]
+ [clj-webdriver.test.config :only [base-url]]
[clj-webdriver.test.util :only [deftest-template-param start-server exclusive-between thrown?]]
[clojure.string :only [lower-case]])
(:require [clj-webdriver.core :as core]
@@ -15,7 +15,7 @@
(defn reset-browser-fixture
[f]
- (to test-base-url)
+ (to (base-url))
(f))
(defn quit-browser-fixture
@@ -29,26 +29,26 @@
;; RUN TESTS HERE
(deftest test-browser-basics
(is (= (class *driver*) clj_webdriver.driver.Driver))
- (is (= (current-url) test-base-url))
+ (is (= (current-url) (base-url)))
(is (= (title) "Ministache"))
(is (re-find #"(?i)html>" (page-source))))
(deftest back-forward-should-traverse-browser-history
(click (find-element {:tag :a, :text "example form"}))
- (is (= (current-url) (str test-base-url "example-form")))
+ (is (= (current-url) (str (base-url) "example-form")))
(back)
- (is (= (current-url) test-base-url))
+ (is (= (current-url) (base-url)))
(forward)
- (is (= (current-url) (str test-base-url "example-form")))
+ (is (= (current-url) (str (base-url) "example-form")))
(click (find-element {:tag :a, :text "clojure"}))
(back 2)
- (is (= (current-url) (str test-base-url)))
+ (is (= (current-url) (str (base-url))))
(forward 2)
- (is (= (current-url) (str test-base-url "clojure"))))
+ (is (= (current-url) (str (base-url) "clojure"))))
(deftest to-should-open-given-url-in-browser
- (to (str test-base-url "example-form"))
- (is (= (current-url) (str test-base-url "example-form")))
+ (to (str (base-url) "example-form"))
+ (is (= (current-url) (str (base-url) "example-form")))
(is (= (title) "Ministache")))
(deftest test-cookie-handling
@@ -152,7 +152,7 @@
(is (re-find #"href=\"https://github\.com/cgrand/moustache\"" (html "a.external"))))
(deftest test-table-finding
- (is (= (current-url) test-base-url))
+ (is (= (current-url) (base-url)))
(is (exists? "#pages-table"))
(is (= (lower-case (tag (find-table-cell "#pages-table" [0 0]))) "th"))
(is (= (lower-case (tag (find-table-cell "#pages-table" [0 1]))) "th"))
@@ -284,12 +284,12 @@
(is (= (:title (window)) "Ministache"))
(is (= (count (windows)) 2))
(switch-to-window (second (windows)))
- (is (= (:url (window)) (str test-base-url "clojure")))
+ (is (= (:url (window)) (str (base-url) "clojure")))
(switch-to-other-window)
- (is (= (:url (window)) test-base-url))
- (switch-to-window (find-window {:url (str test-base-url "clojure")}))
+ (is (= (:url (window)) (base-url)))
+ (switch-to-window (find-window {:url (str (base-url) "clojure")}))
(close)
- (is (= (:url (window)) test-base-url)))
+ (is (= (:url (window)) (base-url))))
(deftest test-waiting-until
(is (= (title) "Ministache"))
@@ -1,7 +1,7 @@
(ns clj-webdriver.test.window
(:use [clojure.test]
[clj-webdriver.core :only [new-driver title current-url to quit]]
- [clj-webdriver.test.config :only [test-base-url]]
+ [clj-webdriver.test.config :only [base-url]]
clj-webdriver.window))
(def driver (atom nil))
@@ -15,7 +15,7 @@
(defn reset-browser-fixture
[f]
- (to @driver test-base-url)
+ (to @driver (base-url))
(f))
(defn quit-browser-fixture
@@ -2,7 +2,7 @@
(ns clj-webdriver.test.wire
(:use clojure.test
[clj-webdriver.core :only [quit to]]
- [clj-webdriver.test.config :only [test-base-url]]
+ [clj-webdriver.test.config :only [base-url]]
[clj-webdriver.test.util :only [start-server]]
[clj-webdriver.remote.server :only [new-remote-session stop]]
[clj-webdriver.remote.driver :only [session-id]]
@@ -21,7 +21,7 @@
(defn reset-browser-fixture
[f]
- (to @driver test-base-url)
+ (to @driver (base-url))
(f))
(defn quit-fixture
@@ -46,5 +46,5 @@
(deftest execute-url-should-return-successfully
(let [sessid (session-id @driver)
resp (execute @server ["session" sessid "url"])]
- (is (= test-base-url
+ (is (= (base-url)
(get-in resp [:body :value])))))

0 comments on commit 334f3eb

Please sign in to comment.