Hello.
I had not found in selenium functionality for testing prompts
(window.prompt) and added it by myself.
If you will find my changes useful and correct I'll will be happy to see
them committed. The patch is in the attachment.
Alex Dvoretskiy
Index: code/javascript/selenium-browserbot.js
===================================================================
--- code/javascript/selenium-browserbot.js (revision 611)
+++ code/javascript/selenium-browserbot.js (working copy)
@@ -50,8 +50,10 @@
this.modalDialogTest = null;
this.recordedAlerts = new Array();
this.recordedConfirmations = new Array();
+ this.recordedPrompts = new Array();
this.openedWindows = {};
this.nextConfirmResult = true;
+ this.nextPromptResult = '';
this.newPageLoaded = false;
var self = this;
@@ -95,6 +97,10 @@
this.nextConfirmResult = false;
};
+BrowserBot.prototype.setNextPromptResult = function(result) {
+ this.nextPromptResult = result;
+};
+
BrowserBot.prototype.hasAlerts = function() {
return (this.recordedAlerts.length > 0) ;
};
@@ -111,7 +117,14 @@
return this.recordedConfirmations.shift();
};
+BrowserBot.prototype.hasPrompts = function() {
+ return (this.recordedPrompts.length > 0) ;
+};
+BrowserBot.prototype.getNextPrompt = function() {
+ return this.recordedPrompts.shift();
+};
+
BrowserBot.prototype.getFrame = function() {
return this.frame;
};
@@ -164,6 +177,14 @@
return result;
};
+ windowToModify.prompt = function(message) {
+ browserBot.recordedPrompts.push(message);
+ var result = !browserBot.nextConfirmResult ? null :
browserBot.nextPromptResult;
+ browserBot.nextConfirmResult = true;
+ browserBot.nextPromptResult = '';
+ return result;
+ };
+
// Keep a reference to all popup windows by name
// note that in IE the "windowName" argument must be a valid javascript
identifier, it seems.
var originalOpen = windowToModify.open;
Index: code/javascript/tests/html/test_prompt.html
===================================================================
--- code/javascript/tests/html/test_prompt.html (revision 0)
+++ code/javascript/tests/html/test_prompt.html (revision 0)
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<!--
+Copyright 2004 ThoughtWorks, Inc
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+ <script type="text/javascript">
+
+ function confirmLeaving() {
+ if (prompt("Type 'yes' and click OK") == 'yes') {
+ document.location = "test_dummy_page.html";
+ }
+ }
+
+ </script>
+ <title>Test Prompt</title>
+</head>
+<body>
+<img style="width: 644px; height: 41px;" alt="banner" src="banner.gif"><br>
+<a id="promptAndLeave" href="javascript:confirmLeaving();">click to navigate
to a new page</a>
+</body>
+</html>
Index: code/javascript/tests/TestSuite-Konqueror.html
===================================================================
--- code/javascript/tests/TestSuite-Konqueror.html (revision 611)
+++ code/javascript/tests/TestSuite-Konqueror.html (working copy)
@@ -57,6 +57,7 @@
<tr><td><a
href="./TestFocusOnBlur.html">TestFocusOnBlur</a></td></tr>
<tr><td><a
href="./TestVerifyAlerts.html">TestVerifyAlerts</a></td></tr>
<tr><td><a
href="./TestConfirmations.html">TestVerifyConfirmations</a></td></tr>
+ <tr><td><a
href="./TestPrompting.html">TestVerifyPrompt</a></td></tr>
<!-- <tr><td><a
href="./TestVisibility.html">TestVisibility</a></td></tr>-->
<tr><td><a
href="./TestVerifyEditable.html">TestVerifyEditable</a></td></tr>
Index: code/javascript/tests/TestPrompting.html
===================================================================
--- code/javascript/tests/TestPrompting.html (revision 0)
+++ code/javascript/tests/TestPrompting.html (revision 0)
@@ -0,0 +1,82 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<!--
+Copyright 2004 ThoughtWorks, Inc
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html>
+<head>
+ <meta content="text/html; charset=ISO-8859-1"
+ http-equiv="content-type">
+ <title>Test Prompting Verifification</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+ <tbody>
+ <tr>
+ <td rowspan="1" colspan="3">Test verify Prompting<br>
+ </td>
+ </tr>
+
+ <tr>
+ <td>open</td>
+ <td>./tests/html/test_prompt.html</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>answerOnNextPrompt</td>
+ <td>no</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>click</td>
+ <td>promptAndLeave</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>verifyPrompt</td>
+ <td>Type 'yes' and click OK</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>verifyTitle</td>
+ <td>Test Prompt</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>answerOnNextPrompt</td>
+ <td>yes</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>clickAndWait</td>
+ <td>promptAndLeave</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>verifyPrompt</td>
+ <td>*'yes'*</td>
+ <td></td>
+ </tr>
+
+ <tr>
+ <td>verifyTitle</td>
+ <td>Dummy Page</td>
+ <td></td>
+ </tr>
+
+
+ </tbody>
+</table>
+</body>
+</html>
Index: code/javascript/tests/TestSuite.html
===================================================================
--- code/javascript/tests/TestSuite.html (revision 611)
+++ code/javascript/tests/TestSuite.html (working copy)
@@ -57,6 +57,7 @@
<tr><td><a
href="./TestFocusOnBlur.html">TestFocusOnBlur</a></td></tr>
<tr><td><a
href="./TestVerifyAlerts.html">TestVerifyAlerts</a></td></tr>
<tr><td><a
href="./TestConfirmations.html">TestVerifyConfirmations</a></td></tr>
+ <tr><td><a
href="./TestPrompting.html">TestVerifyPrompt</a></td></tr>
<tr><td><a
href="./TestVisibility.html">TestVisibility</a></td></tr>
<tr><td><a
href="./TestVerifyEditable.html">TestVerifyEditable</a></td></tr>
Index: code/javascript/tests/TestSuite-Safari.html
===================================================================
--- code/javascript/tests/TestSuite-Safari.html (revision 611)
+++ code/javascript/tests/TestSuite-Safari.html (working copy)
@@ -57,6 +57,7 @@
<tr><td><a
href="./TestFocusOnBlur.html">TestFocusOnBlur</a></td></tr>
<tr><td><a
href="./TestVerifyAlerts.html">TestVerifyAlerts</a></td></tr>
<tr><td><a
href="./TestConfirmations.html">TestVerifyConfirmations</a></td></tr>
+ <tr><td><a
href="./TestPrompting.html">TestVerifyPrompt</a></td></tr>
<!-- <tr><td><a
href="./TestVisibility.html">TestVisibility</a></td></tr>-->
<tr><td><a
href="./TestVerifyEditable.html">TestVerifyEditable</a></td></tr>
Index: code/javascript/tests/TestSuite-InternetExplorer.html
===================================================================
--- code/javascript/tests/TestSuite-InternetExplorer.html (revision 611)
+++ code/javascript/tests/TestSuite-InternetExplorer.html (working copy)
@@ -57,6 +57,7 @@
<tr><td><a
href="./TestFocusOnBlur.html">TestFocusOnBlur</a></td></tr>
<tr><td><a
href="./TestVerifyAlerts.html">TestVerifyAlerts</a></td></tr>
<tr><td><a
href="./TestConfirmations.html">TestVerifyConfirmations</a></td></tr>
+ <tr><td><a
href="./TestPrompting.html">TestVerifyPrompt</a></td></tr>
<tr><td><a
href="./TestVisibility.html">TestVisibility</a></td></tr>
<tr><td><a
href="./TestVerifyEditable.html">TestVerifyEditable</a></td></tr>
Index: code/javascript/selenium-api.js
===================================================================
--- code/javascript/selenium-api.js (revision 611)
+++ code/javascript/selenium-api.js (working copy)
@@ -99,6 +99,13 @@
};
/*
+ * Instruct Selenium what to answear on the next prompt dialog it encounters
+ */
+Selenium.prototype.doAnswerOnNextPrompt = function(answer) {
+ this.browserbot.setNextPromptResult(answer);
+};
+
+/*
* Simulate the browser back button
*/
Selenium.prototype.doGoBack = function() {
@@ -149,6 +156,20 @@
};
/*
+ * Asserts that the supplied message was received as a prompt
+ */
+Selenium.prototype.assertPrompt = function(promptPattern) {
+ if (this.browserbot.hasPrompts()) {
+ receivedPrompt = this.browserbot.getNextPrompt();
+ if (! PatternMatcher.matches(promptPattern, receivedPrompt)) {
+ Assert.fail("The prompt message was [" + receivedPrompt + "]");
+ }
+ } else {
+ Assert.fail("There were no prompts");
+ }
+};
+
+/*
* Verify the location of the current page.
*/
Selenium.prototype.assertAbsoluteLocation = function(expectedLocation) {
begin:vcard
fn:Alex Dvoretskiy
n:Dvoretskiy;Alex
email;internet:[EMAIL PROTECTED]
version:2.1
end:vcard
_______________________________________________
Selenium-devel mailing list
Selenium-devel@lists.public.thoughtworks.org
http://lists.public.thoughtworks.org/mailman/listinfo/selenium-devel