Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Start templating Taxi API tests to test for both optional and explici…

…t driver parameter to Taxi API functions
  • Loading branch information...
commit 47eeb5459c3df0d4d1cc667aa7f9c1e1f0f3d5c9 1 parent 56ad730
@semperos authored
Showing with 106 additions and 75 deletions.
  1. +106 −75 test/clj_webdriver/test/taxi.clj
View
181 test/clj_webdriver/test/taxi.clj
@@ -1,58 +1,67 @@
(ns clj-webdriver.test.taxi
(:use clojure.test
- clj-webdriver.taxi :reload
+ clj-webdriver.taxi
[clj-webdriver.test.config :only [test-base-url]]
- [clj-webdriver.test.util :only [start-server exclusive-between]]
- [clj-webdriver.test.util :only [thrown?]]
+ [clj-webdriver.test.util :only [deftest-template-param start-server exclusive-between thrown?]]
[clojure.string :only [lower-case]])
(:require [clj-webdriver.core :as core]
[clj-webdriver.test.example-app.core :as web-app])
(:import [org.openqa.selenium TimeoutException NoAlertPresentException]))
+;; Alternate driver (not used with Taxi's set-driver!)
+(def alt-driver (atom nil))
+
(defn start-browser-fixture
[f]
(set-driver! {:browser :firefox})
+ (reset! alt-driver (core/new-driver {:browser :firefox}))
(f))
(defn reset-browser-fixture
[f]
(to test-base-url)
+ (to @alt-driver test-base-url)
(f))
(defn quit-browser-fixture
[f]
(f)
- (quit))
+ (quit)
+ (quit @alt-driver))
(use-fixtures :once start-server start-browser-fixture quit-browser-fixture)
(use-fixtures :each reset-browser-fixture)
;; RUN TESTS HERE
-(deftest test-browser-basics
- (is (= (class clj-webdriver.taxi/*driver*) clj_webdriver.driver.Driver))
- (is (= (current-url) test-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")))
- (back)
- (is (= (current-url) test-base-url))
- (forward)
- (is (= (current-url) (str test-base-url "example-form")))
- (click (find-element {:tag :a, :text "clojure"}))
- (back 2)
- (is (= (current-url) (str test-base-url)))
- (forward 2)
- (is (= (current-url) (str test-base-url "clojure"))))
-
-(deftest to-should-open-given-url-in-browser
+(deftest-template-param
+ test-browser-basics @alt-driver
+ (is (= (class *driver*) clj_webdriver.driver.Driver))
+ (is (= (current-url __) test-base-url))
+ (is (= (title __) "Ministache"))
+ (is (re-find #"(?i)html>" (page-source __))))
+
+(deftest-template-param
+ back-forward-should-traverse-browser-history @alt-driver
+ (click __ (find-element __ {:tag :a, :text "example form"}))
+ (is (= (current-url __) (str test-base-url "example-form")))
+ (back __)
+ (is (= (current-url __) test-base-url))
+ (forward __)
+ (is (= (current-url __) (str test-base-url "example-form")))
+ (click __ (find-element __ {:tag :a, :text "clojure"}))
+ (back __ 2)
+ (is (= (current-url __) (str test-base-url)))
+ (forward __ 2)
+ (is (= (current-url __) (str test-base-url "clojure"))))
+
+(deftest-template-param
+ to-should-open-given-url-in-browser @alt-driver
(to (str test-base-url "example-form"))
(is (= (current-url) (str test-base-url "example-form")))
(is (= (title) "Ministache")))
-(deftest test-cookie-handling
+(deftest-template-param
+ test-cookie-handling @alt-driver
(add-cookie {:name "my_cookie" :value "my_cookie_value"})
(is (> (count (cookies)) 0))
(is (= (:value (cookie "my_cookie")) "my_cookie_value"))
@@ -61,7 +70,8 @@
(delete-all-cookies)
(is (zero? (count (cookies)))))
-(deftest test-finding-elements-with-CSS
+(deftest-template-param
+ test-finding-elements-with-CSS @alt-driver
(click (find-element {:tag :a, :text "example form"}))
(is (= (attribute "#first_name" :id) "first_name"))
(is (= (attribute "*[type='text']" :id) "first_name"))
@@ -91,7 +101,8 @@
(is (= (count (elements "a[class*='-item']")) 5))
(is (= (count (elements "a[class*='exter'][href*='github']")) 2)))
-(deftest test-querying-under-elements
+(deftest-template-param
+ test-querying-under-elements @alt-driver
(is (= (text (find-element-under "div#content" (core/by-css "a.external"))) "Moustache"))
(is (= (text (find-element-under "div#content" {:css "a.external"})) "Moustache"))
(is (= (text (find-element-under "div#content" {:tag :a, :class "external"})) "Moustache"))
@@ -101,7 +112,8 @@
(is (= (count (find-elements-under "#footer" {:tag :a})) 5))
(is (= (count (find-elements-under "div#content" {:css "a[class*='exter']"})) 2)))
-(deftest text-exists-visible-present
+(deftest-template-param
+ text-exists-visible-present @alt-driver
(is (exists? "a"))
(is (not (exists? "area")))
(is (exists? "a[href='#pages']"))
@@ -112,22 +124,22 @@
(is (present? "a.external"))
(is (not (present? "a[href='#pages']"))))
-(deftest test-drag-and-drop
- ;; TODO: Implement locally
+(deftest-template-param
+ test-drag-and-drop @alt-driver
(click (find-element {:tag :a, :text "javascript playground"}))
- ;; since it's an external site, make sure that draggable div is still there
(is (present? "#draggable"))
(let [el-to-drag (element {:id "draggable"})
- {o-x :x o-y :y} (location el-to-drag)
- {n-x :x n-y :y} (do
- (drag-and-drop-by el-to-drag {:x 20 :y 20})
- (location el-to-drag))
- x-diff (Math/abs (- n-x o-x))
- y-diff (Math/abs (- n-y o-y))]
+ {o-x :x o-y :y} (location el-to-drag)
+ {n-x :x n-y :y} (do
+ (drag-and-drop-by el-to-drag {:x 20 :y 20})
+ (location el-to-drag))
+ x-diff (Math/abs (- n-x o-x))
+ y-diff (Math/abs (- n-y o-y))]
(is (= x-diff 20))
(is (= y-diff 20))))
-(deftest drag-and-drop-on-elements-should-work
+(deftest-template-param
+ drag-and-drop-on-elements-should-work @alt-driver
(click (find-element {:tag :a, :text "javascript playground"}))
;; Just check to make sure this page still has the element we expect,
;; since it's an external site
@@ -143,18 +155,22 @@
(not= o-y n-y)))
(is (re-find #"ui-state-highlight" (attribute droppable :class)))))
-(deftest test-element-intersection
+(deftest-template-param
+ test-element-intersection @alt-driver
(click (find-element {:tag :a, :text "example form"}))
(is (intersects? "#first_name" "#personal-info-wrapper"))
(is (not (intersects? "#first_name" "#last_name"))))
-(deftest test-xpath-output
+(deftest-template-param
+ test-xpath-output @alt-driver
(is (= (xpath "a.external") "/html/body/div[2]/div/p/a")))
-(deftest test-html-output
+(deftest-template-param
+ test-html-output @alt-driver
(is (re-find #"href=\"https://github\.com/cgrand/moustache\"" (html "a.external"))))
-(deftest test-table-finding
+(deftest-template-param
+ test-table-finding @alt-driver
(is (= (current-url) test-base-url))
(is (exists? "#pages-table"))
(is (= (lower-case (tag (find-table-cell "#pages-table" [0 0]))) "th"))
@@ -165,7 +181,8 @@
(is (= (lower-case (tag (first (find-table-row (element "#pages-table") 0)))) "th"))
(is (= (lower-case (tag (first (find-table-row (element"#pages-table") 1)))) "td")))
-(deftest form-elements
+(deftest-template-param
+ form-elements @alt-driver
(click (find-element {:tag :a :text, "example form"}))
;; Clear
(clear "form#example_form input[id^='last_']")
@@ -188,9 +205,8 @@
;; Text fields
(input-text "input#first_name" "foobar")
(is (= (value "input#first_name") "foobar"))
- (-> "input#first_name"
- clear
- (input-text "clojurian"))
+ (clear "input#first_name")
+ (input-text "input#first_name" "clojurian")
(is (= (value "input#first_name") "clojurian"))
;; "Boolean" element attributes (e.g., readonly="readonly")
(is (= (attribute "#disabled_field" :disabled) "disabled"))
@@ -245,9 +261,11 @@
(deselect-all q)
(is (zero? (count (selected-options q))))))
-(deftest test-quickfill
+(deftest-template-param
+ test-quickfill @alt-driver
(click (find-element {:tag :a :text, "example form"}))
- (is (= (count (quick-fill {"#first_name" clear}
+ (is (= (count (quick-fill
+ {"#first_name" clear}
{"#first_name" "Richard"}
{"#last_name" clear}
{"#last_name" "Hickey"}
@@ -256,7 +274,8 @@
{"input[type='radio'][value='female']" click}
{"select#countries" #(select-by-value % "france")})) 8))
(is (= (count (distinct
- (quick-fill {"#first_name" clear}
+ (quick-fill
+ {"#first_name" clear}
{"#first_name" "Richard"}
{"#last_name" clear}
{"#last_name" "Hickey"}
@@ -269,16 +288,18 @@
(is (= (value "textarea[name='bio']") "Creator of Clojure"))
(is (selected? "input[type='radio'][value='female']"))
(is (selected? "option[value='france']"))
- (is (nil? (quick-fill-submit {"#first_name" clear}
- {"#first_name" "Richard"}
- {"#last_name" clear}
- {"#last_name" "Hickey"}
- {"*[name='bio']" clear}
- {"*[name='bio']" #(input-text % "Creator of Clojure")}
- {"input[type='radio'][value='female']" click}
- {"select#countries" #(select-by-value % "france")}))))
-
-(deftest test-window-handling
+ (is (nil? (quick-fill-submit
+ {"#first_name" clear}
+ {"#first_name" "Richard"}
+ {"#last_name" clear}
+ {"#last_name" "Hickey"}
+ {"*[name='bio']" clear}
+ {"*[name='bio']" #(input-text % "Creator of Clojure")}
+ {"input[type='radio'][value='female']" click}
+ {"select#countries" #(select-by-value % "france")}))))
+
+(deftest-template-param
+ test-window-handling @alt-driver
(is (= (count (windows)) 1))
(is (= (:title (window)) "Ministache"))
(click "a[target='_blank'][href*='clojure']")
@@ -292,21 +313,22 @@
(close)
(is (= (:url (window)) test-base-url)))
-(deftest test-waiting-until
+(deftest-template-param
+ test-waiting-until @alt-driver
(is (= (title) "Ministache"))
(execute-script "setTimeout(function () { window.document.title = \"asdf\"}, 3000)")
- (wait-until #(= (title) "asdf"))
+ (wait-until #(= (title) "asdf") 5000 0)
(is (thrown? TimeoutException
(do
(execute-script "setTimeout(function () { window.document.title = \"test\"}, 6000)")
- (wait-until #(= (title) "test")))))
- ;; TODO: This *should* throw the exception
+ (wait-until #(= (title) "test") 5000 0))))
(is (not (thrown? TimeoutException
(do
(execute-script "setTimeout(function () { window.document.title = \"test\"}, 7000)")
- (wait-until #(= (title) "test") 1000))))))
+ (wait-until #(= (title) "test") 1000 0))))))
-(deftest test-implicit-wait
+(deftest-template-param
+ test-implicit-wait @alt-driver
(implicit-wait 3000)
(execute-script "setTimeout(function () { window.document.body.innerHTML = \"<div id='test'>hi!</div>\"}, 1000)")
(is (= (attribute "#test" :id) "test")))
@@ -316,7 +338,7 @@
;; is different at page start. Disabling for now, as this usage is not
;; as cross-browser compatible or reliable.
;;
-;; (deftest test-frames-by-index
+;; (deftest-template-param test-frames-by-index
;; (to "http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html")
;; (is (= (count (elements "frame")) 3))
;; (switch-to-frame 0)
@@ -328,7 +350,8 @@
;; (switch-to-frame 2)
;; (is (exclusive-between (count (elements "a")) 50 100)))
-(deftest test-frames-by-element
+(deftest-template-param
+ test-frames-by-element @alt-driver
(to "http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html")
(is (= (count (elements "frame")) 3))
(switch-to-frame "frame[name='packageListFrame']")
@@ -340,10 +363,12 @@
(switch-to-frame "frame[name='classFrame']")
(is (exclusive-between (count (elements "a")) 50 100)))
-(deftest test-flash
+(deftest-template-param
+ test-flash @alt-driver
(is (= (attribute (flash "a.external") :class) "external")))
-(deftest test-using-xpath-instead-of-css
+(deftest-template-param
+ test-using-xpath-instead-of-css @alt-driver
(set-finder! xpath-finder)
(click (find-element {:tag :a :text, "example form"}))
(is (= (text {:tag :a, :text "home"}) "home"))
@@ -353,7 +378,8 @@
(is (= (attribute "//*[text()='Moustache']" :href) "https://github.com/cgrand/moustache"))
(is (exists? (find-element {:text "File's Name"}))))
-(deftest test-alert-dialog-handling
+(deftest-template-param
+ test-alert-dialog-handling @alt-driver
(click (find-element {:tag :a, :text "example form"}))
(let [act (fn [] (click "button"))]
(act)
@@ -368,7 +394,8 @@
(is (thrown? NoAlertPresentException
(alert-obj)))))
-(deftest test-window-size
+(deftest-template-param
+ test-window-size @alt-driver
(let [orig-size (window-size)
small {:width 500 :height 400}
large {:width 1024 :height 800}]
@@ -379,7 +406,8 @@
(window-resize orig-size)
(is (= (window-size) orig-size))))
-(deftest test-window-resize-with-one-dimension
+(deftest-template-param
+ test-window-resize-with-one-dimension @alt-driver
(let [orig-size (window-size)
small {:height 400}
large {:width 1024}]
@@ -390,7 +418,8 @@
(window-resize large)
(is (= (:height (window-size)) (:height orig-size)))))
-(deftest test-window-position
+(deftest-template-param
+ test-window-position @alt-driver
(let [origin (window-position)
new-position {:x 100 :y 245}]
(window-reposition new-position)
@@ -398,7 +427,8 @@
(window-reposition origin)
(is (= (window-position) origin))))
-(deftest test-window-reposition-with-one-coordinate
+(deftest-template-param
+ test-window-reposition-with-one-coordinate @alt-driver
(let [origin (window-position)
position-y {:y 245}
position-x {:x 100}]
@@ -409,7 +439,8 @@
(window-reposition position-x)
(is (= (:y (window-position)) (:y origin)))))
-(deftest test-window-maximizing
+(deftest-template-param
+ test-window-maximizing @alt-driver
(let [orig-size (window-size (window-resize {:width 300 :height 300}))
max-size (window-size (window-maximize))]
(is (> (:width max-size) (:width orig-size)))
Please sign in to comment.
Something went wrong with that request. Please try again.