Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move alert into core_driver, add tests

  • Loading branch information...
commit b8a97bb720bbe149f2583fb84d2ec4b130a0fd44 1 parent bc600e2
@semperos authored
View
2  resources/form.html
@@ -103,7 +103,7 @@
</div>
<div class="element-wrapper">
- <button class="button-button">
+ <button class="button-button" onclick="alertFunction()" type="button">
<strong>Button Button</strong>
</button>
<input type="button" class="input-button" id="input-input-button" value="Input Button Button" />
View
6 resources/page.html
@@ -67,6 +67,12 @@
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
+ <script>
+ function alertFunction() {
+ confirm("Testing alerts.");
+ return false;
+ }
+ </script>
</head>
<body>
View
8 src/clj_webdriver/core.clj
@@ -66,6 +66,14 @@
(switch-to-default [driver] "Switch focus to the first first frame of the page, or the main document if the page contains iframes")
(switch-to-active [driver] "Switch to element that currently has focus, or to the body if this cannot be detected"))
+;; ### Alert Popups ###
+(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)")
+ (dismiss [driver] "Dismiss the dialog. Equivalent to pressing 'Cancel'")
+ (alert-text [driver] "Get the text of the popup dialog's message"))
+
;; ### Finding Elements on Page ###
(defprotocol IFind
"Functions used to locate elements on a given page"
View
8 src/clj_webdriver/core_alert.clj
@@ -0,0 +1,8 @@
+;; ## Core Functions for Alert Dialogs ##
+
+;; This namespace provides the implementations for the following
+;; protocols:
+
+;; * IAlert
+(in-ns 'clj-webdriver.core)
+
View
15 src/clj_webdriver/core_driver.clj
@@ -5,6 +5,7 @@
;; * IDriver
;; * ITargetLocator
+;; * IAlert
;; * IOptions
;; * IFind
(in-ns 'clj-webdriver.core)
@@ -178,7 +179,21 @@
(let [cookie-obj (.getCookieNamed (.manage (:webdriver driver)) cookie-name)]
(init-cookie {:cookie cookie-obj})))
+ ;; Alert dialogs
+ IAlert
+ (accept [driver]
+ (-> driver :webdriver .switchTo .alert .accept))
+ (alert [driver]
+ (-> driver :webdriver .switchTo .alert))
+
+ (dismiss [driver]
+ (-> driver :webdriver .switchTo .alert .dismiss))
+
+ (alert-text [driver]
+ (-> driver :webdriver .switchTo .alert .getText))
+
+
;; Find Functions
IFind
(find-element-by [driver by-value]
View
19 test/clj_webdriver/test/common.clj
@@ -9,7 +9,7 @@
[clojure.java.io :as io]
[clojure.tools.logging :as log])
(:import [clj_webdriver.driver.Driver]
- [org.openqa.selenium TimeoutException]))
+ [org.openqa.selenium TimeoutException NoAlertPresentException]))
;;;;;;;;;;;;;;;;;;;;;;;;
;;; ;;;
@@ -493,6 +493,22 @@
(is (= test-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)
+ (is (alert driver) "No alert dialog could be located")
+ (accept driver)
+ (is (thrown? NoAlertPresentException
+ (alert driver)))
+ (act)
+ (is (= (alert-text driver)
+ "Testing alerts."))
+ (dismiss driver)
+ (is (thrown? NoAlertPresentException
+ (alert driver)))))
+
(defn wait-until-should-wait-for-condition
[driver]
(is (= "Ministache" (title driver)))
@@ -612,6 +628,7 @@
quick-fill-should-accept-special-seq-and-perform-batch-actions-on-form
quick-fill-submit-should-always-return-nil
should-be-able-to-toggle-between-open-windows
+ test-alert-dialog-handling
wait-until-should-wait-for-condition
wait-until-should-throw-on-timeout
wait-until-should-allow-timeout-argument
Please sign in to comment.
Something went wrong with that request. Please try again.