Permalink
Browse files

Fixes #80, Add alert handling to Taxi, change alert to alert-obj

  • Loading branch information...
1 parent bc99658 commit 64be2e8ad9d8545fbaf33ac2435c7bfa9ad904ab @semperos committed Nov 3, 2012
@@ -71,7 +71,7 @@
(defprotocol IAlert
"Simple interactions with alert popups"
(accept [driver] "Accept the dialog. Equivalent to pressing 'Ok'")
- (alert [driver] "Return the underlying Java object that can be used with the Alert Java API (exposed until all functionality is ported)")
+ (alert-obj [driver] "Return the underlying Java object that can be used with the Alert Java API (exposed until all functionality is ported)")
(alert-text [driver] "Get the text of the popup dialog's message")
;; (authenticate-using [driver username password] "Enter `username` and `password` into fields from a Basic Access Authentication popup dialog")
(dismiss [driver] "Dismiss the dialog. Equivalent to pressing 'Cancel'"))
@@ -184,7 +184,7 @@
(accept [driver]
(-> driver :webdriver .switchTo .alert .accept))
- (alert [driver]
+ (alert-obj [driver]
(-> driver :webdriver .switchTo .alert))
(alert-text [driver]
View
@@ -1466,6 +1466,26 @@
[k v] entry]
(quick-fill* k v true)))
+(defn accept
@smidas

smidas Nov 3, 2012

Contributor

Daniel,

Do you want to call driver on these functions? Or just the driver passed to them?

-Nathan

@smidas

smidas Nov 3, 2012

Contributor

Markdown removed my earmuffs :-)

@semperos

semperos Nov 3, 2012

Owner

I keep doing that...thanks for catching it. I'll make a change and push in a sec.

@semperos

semperos Nov 3, 2012

Owner

I should really set up a second set of Taxi API tests that use the explicit driver argument so that I'd catch that.

+ "Accept an alert popup dialog. Equivalent to pressing its 'Ok' button."
+ ([] (accept *driver*))
+ ([driver] (core/accept *driver*)))
+
+(defn alert-obj
+ "Retrieve the underlying Java object used to identify an alert popup dialog. Exposed to allow you to use methods not yet exposed via clj-webdriver's API's."
+ ([] (alert-obj *driver*))
+ ([driver] (core/alert-obj *driver*)))
+
+(defn alert-text
+ "Get the text of the alert popup dialog's message."
+ ([] (alert-text *driver*))
+ ([driver] (core/alert-text *driver*)))
+
+(defn dismiss
+ "Dismiss the alert popup dialog. Equivalent to pressing its 'Cancel' button."
+ ([] (dismiss *driver*))
+ ([driver] (core/dismiss *driver*)))
+
(defn window-position
"Get the position of the top-left corner of the browser's window relative to the top-left corner of your primary display, returned as a map of `:x` and `:y` integers.
@@ -498,16 +498,16 @@
(click (find-element driver {:text "example form"}))
(let [act (fn [] (click (find-element driver {:tag :button})))]
(act)
- (is (alert driver) "No alert dialog could be located")
+ (is (alert-obj driver) "No alert dialog could be located")
(accept driver)
(is (thrown? NoAlertPresentException
- (alert driver)))
+ (alert-obj driver)))
(act)
(is (= (alert-text driver)
"Testing alerts."))
(dismiss driver)
(is (thrown? NoAlertPresentException
- (alert driver)))))
+ (alert-obj driver)))))
(defn wait-until-should-wait-for-condition
[driver]
@@ -7,7 +7,7 @@
[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]))
+ (:import [org.openqa.selenium TimeoutException NoAlertPresentException]))
(defn start-browser-fixture
[f]
@@ -353,6 +353,21 @@
(is (= (attribute "//*[text()='Moustache']" :href) "https://github.com/cgrand/moustache"))
(is (exists? (find-element {:text "File's Name"}))))
+(deftest test-alert-dialog-handling
+ (click (find-element {:tag :a, :text "example form"}))
+ (let [act (fn [] (click "button"))]
+ (act)
+ (is (alert-obj) "No alert dialog could be located")
+ (accept)
+ (is (thrown? NoAlertPresentException
+ (alert-obj)))
+ (act)
+ (is (= (alert-text)
+ "Testing alerts."))
+ (dismiss)
+ (is (thrown? NoAlertPresentException
+ (alert-obj)))))
+
(deftest test-window-size
(let [orig-size (window-size)
small {:width 500 :height 400}

0 comments on commit 64be2e8

Please sign in to comment.