Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Move alert into core_driver, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
semperos committed Nov 3, 2012
1 parent bc600e2 commit b8a97bb
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion resources/form.html
Expand Up @@ -103,7 +103,7 @@ <h1>Example Form</h1>
</div> </div>


<div class="element-wrapper"> <div class="element-wrapper">
<button class="button-button"> <button class="button-button" onclick="alertFunction()" type="button">
<strong>Button Button</strong> <strong>Button Button</strong>
</button> </button>
<input type="button" class="input-button" id="input-input-button" value="Input Button Button" /> <input type="button" class="input-button" id="input-input-button" value="Input Button Button" />
Expand Down
6 changes: 6 additions & 0 deletions resources/page.html
Expand Up @@ -67,6 +67,12 @@
</style> </style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <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 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> </head>


<body> <body>
Expand Down
8 changes: 8 additions & 0 deletions src/clj_webdriver/core.clj
Expand Up @@ -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-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")) (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 ### ;; ### Finding Elements on Page ###
(defprotocol IFind (defprotocol IFind
"Functions used to locate elements on a given page" "Functions used to locate elements on a given page"
Expand Down
8 changes: 8 additions & 0 deletions 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)

15 changes: 15 additions & 0 deletions src/clj_webdriver/core_driver.clj
Expand Up @@ -5,6 +5,7 @@


;; * IDriver ;; * IDriver
;; * ITargetLocator ;; * ITargetLocator
;; * IAlert
;; * IOptions ;; * IOptions
;; * IFind ;; * IFind
(in-ns 'clj-webdriver.core) (in-ns 'clj-webdriver.core)
Expand Down Expand Up @@ -178,7 +179,21 @@
(let [cookie-obj (.getCookieNamed (.manage (:webdriver driver)) cookie-name)] (let [cookie-obj (.getCookieNamed (.manage (:webdriver driver)) cookie-name)]
(init-cookie {:cookie cookie-obj}))) (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 ;; Find Functions
IFind IFind
(find-element-by [driver by-value] (find-element-by [driver by-value]
Expand Down
19 changes: 18 additions & 1 deletion test/clj_webdriver/test/common.clj
Expand Up @@ -9,7 +9,7 @@
[clojure.java.io :as io] [clojure.java.io :as io]
[clojure.tools.logging :as log]) [clojure.tools.logging :as log])
(:import [clj_webdriver.driver.Driver] (:import [clj_webdriver.driver.Driver]
[org.openqa.selenium TimeoutException])) [org.openqa.selenium TimeoutException NoAlertPresentException]))


;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;
;;; ;;; ;;; ;;;
Expand Down Expand Up @@ -493,6 +493,22 @@
(is (= test-base-url (is (= test-base-url
(:url (window driver))))) (: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 (defn wait-until-should-wait-for-condition
[driver] [driver]
(is (= "Ministache" (title driver))) (is (= "Ministache" (title driver)))
Expand Down Expand Up @@ -612,6 +628,7 @@
quick-fill-should-accept-special-seq-and-perform-batch-actions-on-form quick-fill-should-accept-special-seq-and-perform-batch-actions-on-form
quick-fill-submit-should-always-return-nil quick-fill-submit-should-always-return-nil
should-be-able-to-toggle-between-open-windows should-be-able-to-toggle-between-open-windows
test-alert-dialog-handling
wait-until-should-wait-for-condition wait-until-should-wait-for-condition
wait-until-should-throw-on-timeout wait-until-should-throw-on-timeout
wait-until-should-allow-timeout-argument wait-until-should-allow-timeout-argument
Expand Down

0 comments on commit b8a97bb

Please sign in to comment.