rubinium 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. data/CHANGES +7 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +137 -0
  4. data/Rakefile +139 -0
  5. data/TODO +7 -0
  6. data/doc/examples/rtc_site_live.rb +12 -0
  7. data/doc/examples/rts_main.rb +9 -0
  8. data/doc/examples/rts_shared_code.rb +25 -0
  9. data/lib/rubinium.rb +9 -0
  10. data/lib/rubinium/string.rb +3 -0
  11. data/lib/rubinium/test_base.rb +80 -0
  12. data/lib/rubinium/test_suite.rb +53 -0
  13. data/lib/rubinium/validator.rb +16 -0
  14. data/test/selenium_tests/test_click.rb +22 -0
  15. data/test/selenium_tests/test_open.rb +11 -0
  16. data/test/tc_file_creation.rb +60 -0
  17. data/test/ts_rubinium.rb +1 -0
  18. data/vendor/selenium-0.6.0/install-readme.txt +9 -0
  19. data/vendor/selenium-0.6.0/selenium/SeleneseRunner.html +253 -0
  20. data/vendor/selenium-0.6.0/selenium/SeleniumLog.html +61 -0
  21. data/vendor/selenium-0.6.0/selenium/TestRunner-splash.html +55 -0
  22. data/vendor/selenium-0.6.0/selenium/TestRunner.hta +146 -0
  23. data/vendor/selenium-0.6.0/selenium/TestRunner.html +146 -0
  24. data/vendor/selenium-0.6.0/selenium/devtests/TestClickInFrame.html +58 -0
  25. data/vendor/selenium-0.6.0/selenium/devtests/TestOpenInFrame.html +48 -0
  26. data/vendor/selenium-0.6.0/selenium/devtests/TestOpenInNewWindow.html +78 -0
  27. data/vendor/selenium-0.6.0/selenium/devtests/TestOpenMeta.html +43 -0
  28. data/vendor/selenium-0.6.0/selenium/devtests/TestSuite.html +39 -0
  29. data/vendor/selenium-0.6.0/selenium/devtests/meta/page.html +5 -0
  30. data/vendor/selenium-0.6.0/selenium/dom-images/butmin.gif +0 -0
  31. data/vendor/selenium-0.6.0/selenium/dom-images/butplus.gif +0 -0
  32. data/vendor/selenium-0.6.0/selenium/dom-styles/default.css +298 -0
  33. data/vendor/selenium-0.6.0/selenium/domviewer.html +16 -0
  34. data/vendor/selenium-0.6.0/selenium/html-xpath/carnation.jpg +0 -0
  35. data/vendor/selenium-0.6.0/selenium/html-xpath/example.html +75 -0
  36. data/vendor/selenium-0.6.0/selenium/html-xpath/html-xpath-patched.js +657 -0
  37. data/vendor/selenium-0.6.0/selenium/html-xpath/html-xpath.js +610 -0
  38. data/vendor/selenium-0.6.0/selenium/html-xpath/license.txt +504 -0
  39. data/vendor/selenium-0.6.0/selenium/html-xpath/rainbow.jpg +0 -0
  40. data/vendor/selenium-0.6.0/selenium/htmlutils.js +283 -0
  41. data/vendor/selenium-0.6.0/selenium/index.html +60 -0
  42. data/vendor/selenium-0.6.0/selenium/jsmock/mock-tests.html +205 -0
  43. data/vendor/selenium-0.6.0/selenium/jsmock/mock.js +124 -0
  44. data/vendor/selenium-0.6.0/selenium/selenium-api.js +683 -0
  45. data/vendor/selenium-0.6.0/selenium/selenium-browserbot.js +930 -0
  46. data/vendor/selenium-0.6.0/selenium/selenium-commandhandlers.js +286 -0
  47. data/vendor/selenium-0.6.0/selenium/selenium-domviewer.js +188 -0
  48. data/vendor/selenium-0.6.0/selenium/selenium-executionloop.js +250 -0
  49. data/vendor/selenium-0.6.0/selenium/selenium-fitrunner.js +597 -0
  50. data/vendor/selenium-0.6.0/selenium/selenium-logging.js +88 -0
  51. data/vendor/selenium-0.6.0/selenium/selenium-logo.png +0 -0
  52. data/vendor/selenium-0.6.0/selenium/selenium-tableparser.js +50 -0
  53. data/vendor/selenium-0.6.0/selenium/selenium.css +211 -0
  54. data/vendor/selenium-0.6.0/selenium/tests/ErrorCheckingTestSuite.html +36 -0
  55. data/vendor/selenium-0.6.0/selenium/tests/GoogleTestSearch.html +69 -0
  56. data/vendor/selenium-0.6.0/selenium/tests/GoogleTestSuite.html +32 -0
  57. data/vendor/selenium-0.6.0/selenium/tests/JsUnitSuite.html +38 -0
  58. data/vendor/selenium-0.6.0/selenium/tests/TestClick.html +128 -0
  59. data/vendor/selenium-0.6.0/selenium/tests/TestClickJavascriptHref.html +115 -0
  60. data/vendor/selenium-0.6.0/selenium/tests/TestCommandError.html +79 -0
  61. data/vendor/selenium-0.6.0/selenium/tests/TestConfirmations.html +77 -0
  62. data/vendor/selenium-0.6.0/selenium/tests/TestErrorChecking.html +71 -0
  63. data/vendor/selenium-0.6.0/selenium/tests/TestFailingAssert.html +59 -0
  64. data/vendor/selenium-0.6.0/selenium/tests/TestFailingVerifications.html +198 -0
  65. data/vendor/selenium-0.6.0/selenium/tests/TestFocusOnBlur.html +53 -0
  66. data/vendor/selenium-0.6.0/selenium/tests/TestGoBack.html +81 -0
  67. data/vendor/selenium-0.6.0/selenium/tests/TestImplicitLocators.html +81 -0
  68. data/vendor/selenium-0.6.0/selenium/tests/TestJavascriptParameters.html +91 -0
  69. data/vendor/selenium-0.6.0/selenium/tests/TestLocators.html +161 -0
  70. data/vendor/selenium-0.6.0/selenium/tests/TestModalDialog.html +58 -0
  71. data/vendor/selenium-0.6.0/selenium/tests/TestModalDialogDialog.html +48 -0
  72. data/vendor/selenium-0.6.0/selenium/tests/TestOpen.html +66 -0
  73. data/vendor/selenium-0.6.0/selenium/tests/TestPatternMatching.html +127 -0
  74. data/vendor/selenium-0.6.0/selenium/tests/TestPause.html +78 -0
  75. data/vendor/selenium-0.6.0/selenium/tests/TestPrompting.html +82 -0
  76. data/vendor/selenium-0.6.0/selenium/tests/TestProxy.html +62 -0
  77. data/vendor/selenium-0.6.0/selenium/tests/TestSelect.html +111 -0
  78. data/vendor/selenium-0.6.0/selenium/tests/TestSelectWindow.html +106 -0
  79. data/vendor/selenium-0.6.0/selenium/tests/TestStore.html +165 -0
  80. data/vendor/selenium-0.6.0/selenium/tests/TestSuite-InternetExplorer.html +79 -0
  81. data/vendor/selenium-0.6.0/selenium/tests/TestSuite-Konqueror.html +75 -0
  82. data/vendor/selenium-0.6.0/selenium/tests/TestSuite-Safari.html +75 -0
  83. data/vendor/selenium-0.6.0/selenium/tests/TestSuite.html +75 -0
  84. data/vendor/selenium-0.6.0/selenium/tests/TestType.html +79 -0
  85. data/vendor/selenium-0.6.0/selenium/tests/TestUserExtensions.html +81 -0
  86. data/vendor/selenium-0.6.0/selenium/tests/TestVerifications.html +164 -0
  87. data/vendor/selenium-0.6.0/selenium/tests/TestVerifyAlerts.html +80 -0
  88. data/vendor/selenium-0.6.0/selenium/tests/TestVerifyAlertsFailures.html +108 -0
  89. data/vendor/selenium-0.6.0/selenium/tests/TestVerifyConfirmationFailures.html +86 -0
  90. data/vendor/selenium-0.6.0/selenium/tests/TestVerifyEditable.html +70 -0
  91. data/vendor/selenium-0.6.0/selenium/tests/TestVerifyEditableFailures.html +95 -0
  92. data/vendor/selenium-0.6.0/selenium/tests/TestVisibility.html +91 -0
  93. data/vendor/selenium-0.6.0/selenium/tests/TestVisibilityFailures.html +131 -0
  94. data/vendor/selenium-0.6.0/selenium/tests/TestWait.html +112 -0
  95. data/vendor/selenium-0.6.0/selenium/tests/TestWaitFor.html +63 -0
  96. data/vendor/selenium-0.6.0/selenium/tests/TestWaitInPopupWindow.html +94 -0
  97. data/vendor/selenium-0.6.0/selenium/tests/TestXPathLocators.html +98 -0
  98. data/vendor/selenium-0.6.0/selenium/tests/browserbot/alert-handling-tests.html +79 -0
  99. data/vendor/selenium-0.6.0/selenium/tests/browserbot/assert-tests.html +113 -0
  100. data/vendor/selenium-0.6.0/selenium/tests/browserbot/browserbot-tests.html +123 -0
  101. data/vendor/selenium-0.6.0/selenium/tests/browserbot/command-factory-tests.html +290 -0
  102. data/vendor/selenium-0.6.0/selenium/tests/browserbot/command-handler-tests.html +115 -0
  103. data/vendor/selenium-0.6.0/selenium/tests/browserbot/confirm-handling-tests.html +97 -0
  104. data/vendor/selenium-0.6.0/selenium/tests/browserbot/error-checking-command-tests.html +198 -0
  105. data/vendor/selenium-0.6.0/selenium/tests/browserbot/event-bubble-tests.html +106 -0
  106. data/vendor/selenium-0.6.0/selenium/tests/browserbot/optionlocator-tests.html +180 -0
  107. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-accessor-tests.html +65 -0
  108. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-action-tests.html +200 -0
  109. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-attribute-tests.html +98 -0
  110. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-locator-tests-include.html +33 -0
  111. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-locator-tests.html +258 -0
  112. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-property-tests.html +49 -0
  113. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pattern-matcher-tests.html +66 -0
  114. data/vendor/selenium-0.6.0/selenium/tests/browserbot/selenium-api-tests.html +412 -0
  115. data/vendor/selenium-0.6.0/selenium/tests/browserbot/selenium-parameter-tests.html +98 -0
  116. data/vendor/selenium-0.6.0/selenium/tests/browserbot/suite.html +52 -0
  117. data/vendor/selenium-0.6.0/selenium/tests/browserbot/testloop-handle-error-tests.html +74 -0
  118. data/vendor/selenium-0.6.0/selenium/tests/events/TestButtonEvents.html +72 -0
  119. data/vendor/selenium-0.6.0/selenium/tests/events/TestCheckboxEvents.html +107 -0
  120. data/vendor/selenium-0.6.0/selenium/tests/events/TestFireEvents.html +75 -0
  121. data/vendor/selenium-0.6.0/selenium/tests/events/TestLinkEvents.html +43 -0
  122. data/vendor/selenium-0.6.0/selenium/tests/events/TestRadioEvents.html +149 -0
  123. data/vendor/selenium-0.6.0/selenium/tests/events/TestSelectEvents.html +122 -0
  124. data/vendor/selenium-0.6.0/selenium/tests/events/TestTextEvents.html +87 -0
  125. data/vendor/selenium-0.6.0/selenium/tests/events/readme.txt +26 -0
  126. data/vendor/selenium-0.6.0/selenium/tests/html/banner.gif +0 -0
  127. data/vendor/selenium-0.6.0/selenium/tests/html/test_async_event.html +36 -0
  128. data/vendor/selenium-0.6.0/selenium/tests/html/test_click_javascript_page.html +34 -0
  129. data/vendor/selenium-0.6.0/selenium/tests/html/test_click_page1.html +31 -0
  130. data/vendor/selenium-0.6.0/selenium/tests/html/test_click_page2.html +30 -0
  131. data/vendor/selenium-0.6.0/selenium/tests/html/test_confirm.html +34 -0
  132. data/vendor/selenium-0.6.0/selenium/tests/html/test_dummy_page.html +26 -0
  133. data/vendor/selenium-0.6.0/selenium/tests/html/test_editable.html +36 -0
  134. data/vendor/selenium-0.6.0/selenium/tests/html/test_focus_on_blur.html +33 -0
  135. data/vendor/selenium-0.6.0/selenium/tests/html/test_form_events.html +98 -0
  136. data/vendor/selenium-0.6.0/selenium/tests/html/test_framed_page.html +7 -0
  137. data/vendor/selenium-0.6.0/selenium/tests/html/test_just_text.html +22 -0
  138. data/vendor/selenium-0.6.0/selenium/tests/html/test_locators.html +34 -0
  139. data/vendor/selenium-0.6.0/selenium/tests/html/test_modal_dialog.html +29 -0
  140. data/vendor/selenium-0.6.0/selenium/tests/html/test_modal_dialog_dialog.html +35 -0
  141. data/vendor/selenium-0.6.0/selenium/tests/html/test_open.html +23 -0
  142. data/vendor/selenium-0.6.0/selenium/tests/html/test_prompt.html +34 -0
  143. data/vendor/selenium-0.6.0/selenium/tests/html/test_reload_onchange_page.html +32 -0
  144. data/vendor/selenium-0.6.0/selenium/tests/html/test_select.html +35 -0
  145. data/vendor/selenium-0.6.0/selenium/tests/html/test_select_window.html +29 -0
  146. data/vendor/selenium-0.6.0/selenium/tests/html/test_select_window_popup.html +28 -0
  147. data/vendor/selenium-0.6.0/selenium/tests/html/test_slowloading_page.html +27 -0
  148. data/vendor/selenium-0.6.0/selenium/tests/html/test_store_value.html +23 -0
  149. data/vendor/selenium-0.6.0/selenium/tests/html/test_type_page1.html +37 -0
  150. data/vendor/selenium-0.6.0/selenium/tests/html/test_type_page2.html +61 -0
  151. data/vendor/selenium-0.6.0/selenium/tests/html/test_verifications.html +42 -0
  152. data/vendor/selenium-0.6.0/selenium/tests/html/test_verify_alert.html +46 -0
  153. data/vendor/selenium-0.6.0/selenium/tests/html/test_visibility.html +53 -0
  154. data/vendor/selenium-0.6.0/selenium/tests/readme.txt +1 -0
  155. data/vendor/selenium-0.6.0/selenium/tests/tableparser/tableparser-tests.html +122 -0
  156. data/vendor/selenium-0.6.0/selenium/tests/tinyWebServer.py +70 -0
  157. data/vendor/selenium-0.6.0/selenium/user-extensions.js.sample +62 -0
  158. data/vendor/selenium-0.6.0/selenium/version.txt +1 -0
  159. data/vendor/selenium-0.6.0/selenium/xmlextras.js +153 -0
  160. data/vendor/selenium-0.6.0/selenium/xpath.js +3910 -0
  161. metadata +216 -0
@@ -0,0 +1,124 @@
1
+ /*
2
+ * Copyright 2004 ThoughtWorks, Inc
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ // A simple mock library for Javascript
19
+ //
20
+ // Original code by Aslak Hellesoy and Ji Wang
21
+
22
+ Mock = function() {
23
+ this.expectedInvocations = {};
24
+ this.expectedArgs = {};
25
+ this.returnValues = {};
26
+ this.attrs = [];
27
+ this.expectedProperties = {};
28
+
29
+ this.expects = function() {
30
+ functionName = arguments[0];
31
+ this.expectedArgs[functionName] = [];
32
+ for(i = 1; i < arguments.length; i++) {
33
+ this.expectedArgs[functionName][i-1] = arguments[i];
34
+ }
35
+ javascriptCode = "this." + functionName + " = function() {\n" +
36
+ " // mark this function as \"executed\"\n" +
37
+ " this.expectedInvocations[\"" + functionName + "\"] = true;\n" +
38
+ " assertEquals(\"" + functionName + ": Wrong number of arguments.\", " + this.expectedArgs[functionName].length + ", arguments.length);\n" +
39
+ " for(i = 0; i < arguments.length; i++) {\n" +
40
+ " assertEquals(this.expectedArgs[\"" + functionName + "\"][i], arguments[i]);\n" +
41
+ " };\n" +
42
+ " var returnValue = this.returnValues[\"" + functionName + "\"];\n" +
43
+ " if (returnValue && returnValue.isMockError) { throw returnValue };\n" +
44
+ " return returnValue;\n" +
45
+ "}";
46
+ eval(javascriptCode);
47
+ // initially mark this function as "not yet executed"
48
+ this.expectedInvocations[functionName] = false;
49
+ this.attrs[this.attrs.length] = "dummy";
50
+ return new Returner(this, functionName);
51
+ };
52
+
53
+ this.expectsProperty = function() {
54
+ var propertyName = arguments[0];
55
+ if(arguments.length == 2) {
56
+ expectedPropertyValue = arguments[1];
57
+ this.expectedProperties[propertyName] = expectedPropertyValue;
58
+ this.attrs[this.attrs.length] = "dummy";
59
+ } else {
60
+ return new PropertySetter(this, propertyName);
61
+ }
62
+ };
63
+
64
+ this.verify = function() {
65
+ // loop over all expected invocations and see if they were called
66
+ for(var functionName in this.expectedInvocations) {
67
+ var wasCalled = this.expectedInvocations[functionName];
68
+ if(!wasCalled) {
69
+ fail("Expected function not called:" + functionName);
70
+ }
71
+ }
72
+ var currentAttrs = [];
73
+ var currentAttrCount = 0;
74
+
75
+ // verify that all expected properties are set
76
+ // for(var attr in this) {
77
+ // currentAttrs[currentAttrCount] = attr;
78
+ // currentAttrCount++;
79
+ // }
80
+ // if(this.attrs.length < currentAttrCount) {
81
+ // unexpectedAttr = currentAttrs[this.attrs.length]
82
+ // fail("Unexpected property was set: " + unexpectedAttr + "=" + eval("this." + unexpectedAttr))
83
+ // }
84
+
85
+ // verify that all expected properties are set with the right value
86
+ // for(var attr in this.expectedProperties) {
87
+ // if(this.expectedProperties[attr] != eval("this." + attr)) {
88
+ // fail("Expected property was not set: " + attr + "=" + this.expectedProperties[attr])
89
+ // }
90
+ // }
91
+ };
92
+
93
+ var attrCount = 0;
94
+ for(var attr in this) {
95
+ this.attrs[attrCount] = attr;
96
+ attrCount++;
97
+ }
98
+ };
99
+
100
+ Returner = function(mock, functionName) {
101
+ this.mock = mock;
102
+ this.functionName = functionName;
103
+ };
104
+
105
+ Returner.prototype.returns = function(returnValue) {
106
+ this.mock.returnValues[this.functionName] = returnValue;
107
+ };
108
+
109
+ Returner.prototype.andThrows = function(message) {
110
+ var error = new Error(message);
111
+ error.isMockError = true;
112
+ this.mock.returnValues[this.functionName] = error;
113
+ };
114
+
115
+ PropertySetter = function(mock, propertyName) {
116
+ this.mock = mock;
117
+ this.propertyName = propertyName;
118
+ };
119
+
120
+ PropertySetter.prototype.returns = function(returnValue) {
121
+ var ref = new Object();
122
+ ref.value = returnValue;
123
+ eval("this.mock." + this.propertyName + "=ref.value");
124
+ };
@@ -0,0 +1,683 @@
1
+ /*
2
+ * Copyright 2004 ThoughtWorks, Inc
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ storedVars = new Object();
19
+
20
+ function Selenium(browserbot) {
21
+ this.browserbot = browserbot;
22
+ this.optionLocatorFactory = new OptionLocatorFactory();
23
+ this.page = function() {
24
+ return browserbot.getCurrentPage();
25
+ };
26
+ }
27
+
28
+ Selenium.createForFrame = function(frame) {
29
+ return new Selenium(BrowserBot.createForFrame(frame));
30
+ };
31
+
32
+ /*
33
+ * Reset the browserbot when an error occurs..
34
+ */
35
+ Selenium.prototype.reset = function() {
36
+ storedVars = new Object();
37
+ this.browserbot.selectWindow("null");
38
+ };
39
+
40
+ /*
41
+ * Click on the located element, and attach a callback to notify
42
+ * when the page is reloaded.
43
+ */
44
+ Selenium.prototype.doModalDialogTest = function(returnValue) {
45
+ this.browserbot.doModalDialogTest(returnValue);
46
+ };
47
+
48
+ /*
49
+ * Click on the located element, and attach a callback to notify
50
+ * when the page is reloaded.
51
+ */
52
+ Selenium.prototype.doClick = function(locator) {
53
+ var element = this.page().findElement(locator);
54
+ this.page().clickElement(element);
55
+ };
56
+
57
+ /**
58
+ * Overwrite the text in the located text element.
59
+ * TODO fail if it can't be typed into.
60
+ */
61
+ Selenium.prototype.doType = function(locator, newText) {
62
+ var element = this.page().findElement(locator);
63
+ this.page().replaceText(element, newText);
64
+ };
65
+
66
+ /**
67
+ * Select the option from the located select element.
68
+ */
69
+ Selenium.prototype.doSelect = function(locator, optionLocator) {
70
+ var element = this.page().findElement(locator);
71
+ if (!("options" in element)) {
72
+ throw new SeleniumError("Specified element is not a Select (has no options)");
73
+ }
74
+ var locator = this.optionLocatorFactory.fromLocatorString(optionLocator);
75
+ var option = locator.findOption(element);
76
+ this.page().selectOption(element, option);
77
+ };
78
+
79
+ /*
80
+ * Open the browser to a new location.
81
+ */
82
+ Selenium.prototype.doOpen = function(newLocation) {
83
+ this.browserbot.openLocation(newLocation);
84
+ return SELENIUM_PROCESS_WAIT;
85
+ };
86
+
87
+ /*
88
+ * Select the named window to be the active window.
89
+ */
90
+ Selenium.prototype.doSelectWindow = function(windowName) {
91
+ this.browserbot.selectWindow(windowName);
92
+ };
93
+
94
+ /*
95
+ * Instruct Selenium to click Cancel on the next confirm dialog it encounters
96
+ */
97
+ Selenium.prototype.doChooseCancelOnNextConfirmation = function() {
98
+ this.browserbot.cancelNextConfirmation();
99
+ };
100
+
101
+ /*
102
+ * Instruct Selenium what to answear on the next prompt dialog it encounters
103
+ */
104
+ Selenium.prototype.doAnswerOnNextPrompt = function(answer) {
105
+ this.browserbot.setNextPromptResult(answer);
106
+ };
107
+
108
+ /*
109
+ * Simulate the browser back button
110
+ */
111
+ Selenium.prototype.doGoBack = function() {
112
+ this.page().goBack();
113
+ };
114
+
115
+ /*
116
+ * Close the browser window or tab
117
+ */
118
+ Selenium.prototype.doClose = function() {
119
+ this.page().close();
120
+ };
121
+
122
+ /*
123
+ * Explicitly fire an event
124
+ */
125
+ Selenium.prototype.doFireEvent = function(locator, event) {
126
+ var element = this.page().findElement(locator);
127
+ triggerEvent(element, event, false);
128
+ };
129
+
130
+ /*
131
+ * Get an alert message, or fail if there were no alerts.
132
+ */
133
+ Selenium.prototype.getAlert = function() {
134
+ if (!this.browserbot.hasAlerts()) {
135
+ Assert.fail("There were no alerts");
136
+ }
137
+ return this.browserbot.getNextAlert();
138
+ };
139
+
140
+ /*
141
+ * Get a confirmation message, or fail if there were no confirmations.
142
+ */
143
+ Selenium.prototype.getConfirmation = function() {
144
+ if (!this.browserbot.hasConfirmations()) {
145
+ Assert.fail("There were no confirmations");
146
+ }
147
+ return this.browserbot.getNextConfirmation();
148
+ };
149
+
150
+ /*
151
+ * Get a prompt message, or fail if there were no prompts.
152
+ */
153
+ Selenium.prototype.getPrompt = function() {
154
+ if (! this.browserbot.hasPrompts()) {
155
+ Assert.fail("There were no prompts");
156
+ }
157
+ return this.browserbot.getNextPrompt();
158
+ };
159
+
160
+ /*
161
+ * Get the location of the current page.
162
+ */
163
+ Selenium.prototype.getAbsoluteLocation = function() {
164
+ return this.page().location;
165
+ };
166
+
167
+ /*
168
+ * Verify the location of the current page ends with the expected location.
169
+ * If a querystring is provided, this is checked as well.
170
+ */
171
+ Selenium.prototype.assertLocation = function(expectedLocation) {
172
+ var docLocation = this.page().location;
173
+ var searchPos = expectedLocation.lastIndexOf('?');
174
+
175
+ if (searchPos == -1) {
176
+ Assert.matches('*' + expectedLocation, docLocation.pathname);
177
+ }
178
+ else {
179
+ var expectedPath = expectedLocation.substring(0, searchPos);
180
+ Assert.matches('*' + expectedPath, docLocation.pathname);
181
+
182
+ var expectedQueryString = expectedLocation.substring(searchPos);
183
+ Assert.equals(expectedQueryString, docLocation.search);
184
+ }
185
+ };
186
+
187
+ /*
188
+ * Get the title of the current page.
189
+ */
190
+ Selenium.prototype.getTitle = function() {
191
+ return this.page().title();
192
+ };
193
+
194
+
195
+ /*
196
+ * Get the (trimmed) value of a form element.
197
+ * This is used to generate assertValue, verifyValue, ...
198
+ */
199
+ Selenium.prototype.getValue = function(locator) {
200
+ var element = this.page().findElement(locator)
201
+ return getInputValue(element).trim();
202
+ }
203
+
204
+ /**
205
+ * Get the (trimmed) text of a form element.
206
+ * This is used to generate assertText, verifyText, ...
207
+ */
208
+ Selenium.prototype.getText = function(locator) {
209
+ var element = this.page().findElement(locator);
210
+ return getText(element).trim();
211
+ };
212
+
213
+ /*
214
+ * Return the text for a single cell within an HTML table.
215
+ * The table locator syntax is table.row.column.
216
+ */
217
+ Selenium.prototype.getTable = function(tableLocator) {
218
+ // This regular expression matches "tableName.row.column"
219
+ // For example, "mytable.3.4"
220
+ pattern = /(.*)\.(\d+)\.(\d+)/;
221
+
222
+ if(!pattern.test(tableLocator)) {
223
+ throw new SeleniumError("Invalid target format. Correct format is tableName.rowNum.columnNum");
224
+ }
225
+
226
+ pieces = tableLocator.match(pattern);
227
+
228
+ tableName = pieces[1];
229
+ row = pieces[2];
230
+ col = pieces[3];
231
+
232
+ var table = this.page().findElement(tableName);
233
+ if (row > table.rows.length) {
234
+ Assert.fail("Cannot access row " + row + " - table has " + table.rows.length + " rows");
235
+ }
236
+ else if (col > table.rows[row].cells.length) {
237
+ Assert.fail("Cannot access column " + col + " - table row has " + table.rows[row].cells.length + " columns");
238
+ }
239
+ else {
240
+ actualContent = getText(table.rows[row].cells[col]);
241
+ return actualContent.trim();
242
+ }
243
+ };
244
+
245
+ /**
246
+ * Verify that the selected option satisfies the option locator.
247
+ */
248
+ Selenium.prototype.assertSelected = function(target, optionLocator) {
249
+ var element = this.page().findElement(target);
250
+ var locator = this.optionLocatorFactory.fromLocatorString(optionLocator);
251
+ locator.assertSelected(element);
252
+ };
253
+
254
+ String.prototype.parseCSV = function() {
255
+ var values = this.replace(/\\,/g, "\n").split(",");
256
+ // Restore escaped commas
257
+ for (var i = 0; i < values.length; i++) {
258
+ values[i] = values[i].replace(/\n/g, ",").trim();
259
+ }
260
+ return values;
261
+ };
262
+
263
+ /**
264
+ * Verify the label of all of the options in the drop=down.
265
+ */
266
+ Selenium.prototype.assertSelectOptions = function(target, options) {
267
+ var element = this.page().findElement(target);
268
+
269
+ var expectedOptionLabels = options.parseCSV();
270
+ Assert.equals("Wrong number of options", expectedOptionLabels.length, element.options.length);
271
+
272
+ for (var i = 0; i < element.options.length; i++) {
273
+ Assert.matches(expectedOptionLabels[i], element.options[i].text);
274
+ }
275
+ };
276
+
277
+ /**
278
+ * Get the value of an element attribute. The syntax for returning an element attribute
279
+ * is <element-locator>@attribute-name. Used to generate assert, verify, assertNot...
280
+ */
281
+ Selenium.prototype.getAttribute = function(target) {
282
+ return this.page().findAttribute(target);
283
+ };
284
+
285
+ /*
286
+ * Asserts that the specified text is present in the page content.
287
+ */
288
+ Selenium.prototype.assertTextPresent = function(expectedText) {
289
+ var allText = this.page().bodyText();
290
+
291
+ if(allText == "") {
292
+ Assert.fail("Page text not found");
293
+ } else if(allText.indexOf(expectedText) == -1) {
294
+ Assert.fail("'" + expectedText + "' not found in page text.");
295
+ }
296
+ };
297
+
298
+ /*
299
+ * Asserts that the specified text is NOT present in the page content.
300
+ */
301
+ Selenium.prototype.assertTextNotPresent = function(unexpectedText) {
302
+ var allText = this.page().bodyText();
303
+
304
+ if(allText == "") {
305
+ Assert.fail("Page text not found");
306
+ } else if(allText.indexOf(unexpectedText) != -1) {
307
+ Assert.fail("'" + unexpectedText + "' was found in page text.");
308
+ }
309
+ };
310
+
311
+ /*
312
+ * Asserts that the specified element can be found.
313
+ */
314
+ Selenium.prototype.assertElementPresent = function(locator) {
315
+ try {
316
+ this.page().findElement(locator);
317
+ } catch (e) {
318
+ Assert.fail("Element " + locator + " not found.");
319
+ }
320
+ };
321
+
322
+ /*
323
+ * Asserts that the specified element cannot be found.
324
+ */
325
+ Selenium.prototype.assertElementNotPresent = function(locator) {
326
+ try {
327
+ this.page().findElement(locator);
328
+ }
329
+ catch (e) {
330
+ return;
331
+ }
332
+ Assert.fail("Element " + locator + " found.");
333
+ };
334
+
335
+ /*
336
+ * Asserts that the specified element is visible
337
+ */
338
+ Selenium.prototype.assertVisible = function(locator) {
339
+ var element;
340
+ try {
341
+ element = this.page().findElement(locator);
342
+ } catch (e) {
343
+ Assert.fail("Element " + locator + " not present.");
344
+ }
345
+ if (! this.isVisible(element)) {
346
+ Assert.fail("Element " + locator + " not visible.");
347
+ }
348
+ };
349
+
350
+ /*
351
+ * Asserts that the specified element is visible
352
+ */
353
+ Selenium.prototype.assertNotVisible = function(locator) {
354
+ var element;
355
+ try {
356
+ element = this.page().findElement(locator);
357
+ } catch (e) {
358
+ return;
359
+ }
360
+ if (this.isVisible(element)) {
361
+ Assert.fail("Element " + locator + " is visible.");
362
+ }
363
+ };
364
+
365
+ Selenium.prototype.isVisible = function(element) {
366
+ var visibility = this.getEffectiveStyleProperty(element, "visibility");
367
+ var isDisplayed = this.isDisplayed(element);
368
+ return (visibility != "hidden" && isDisplayed);
369
+ };
370
+
371
+ Selenium.prototype.getEffectiveStyleProperty = function(element, property) {
372
+ var effectiveStyle = this.getEffectiveStyle(element);
373
+ var propertyValue = effectiveStyle[property];
374
+ if (propertyValue == 'inherit' && element.parentNode.style) {
375
+ return this.getEffectiveStyleProperty(element.parentNode, property);
376
+ }
377
+ return propertyValue;
378
+ };
379
+
380
+ Selenium.prototype.isDisplayed = function(element) {
381
+ var display = this.getEffectiveStyleProperty(element, "display");
382
+ if (display == "none") return false;
383
+ if (element.parentNode.style) {
384
+ return this.isDisplayed(element.parentNode);
385
+ }
386
+ return true;
387
+ };
388
+
389
+ Selenium.prototype.getEffectiveStyle = function(element) {
390
+ if (element.style == undefined) {
391
+ return undefined; // not a styled element
392
+ }
393
+ var window = this.browserbot.getContentWindow();
394
+ if (window.getComputedStyle) {
395
+ // DOM-Level-2-CSS
396
+ return window.getComputedStyle(element, null);
397
+ }
398
+ if (element.currentStyle) {
399
+ // non-standard IE alternative
400
+ return element.currentStyle;
401
+ // TODO: this won't really work in a general sense, as
402
+ // currentStyle is not identical to getComputedStyle()
403
+ // ... but it's good enough for "visibility"
404
+ }
405
+ throw new SeleniumError("cannot determine effective stylesheet in this browser");
406
+ };
407
+
408
+ /**
409
+ * Asserts that the specified element accepts user input visible
410
+ */
411
+ Selenium.prototype.assertEditable = function(locator) {
412
+ var element = this.page().findElement(locator);
413
+ if (element.value == undefined) {
414
+ Assert.fail("Element " + locator + " is not an input.");
415
+ }
416
+ if (element.disabled) {
417
+ Assert.fail("Element " + locator + " is disabled.");
418
+ }
419
+ };
420
+
421
+ /**
422
+ * Asserts that the specified element does not accept user input
423
+ */
424
+ Selenium.prototype.assertNotEditable = function(locator) {
425
+ var element = this.page().findElement(locator);
426
+ if (element.value == undefined) {
427
+ return; // not an input
428
+ }
429
+ if (element.disabled == false) {
430
+ Assert.fail("Element " + locator + " is editable.");
431
+ }
432
+ };
433
+
434
+ /*
435
+ * Return all buttons on the screen.
436
+ */
437
+ Selenium.prototype.getAllButtons = function() {
438
+ return this.page().getAllButtons();
439
+ };
440
+
441
+ /*
442
+ * Return all links on the screen.
443
+ */
444
+ Selenium.prototype.getAllLinks = function() {
445
+ return this.page().getAllLinks();
446
+ };
447
+
448
+ /*
449
+ * Return all fields on the screen.
450
+ */
451
+ Selenium.prototype.getAllFields = function() {
452
+ return this.page().getAllFields();
453
+ };
454
+
455
+ /*
456
+ * Set the context for the current Test
457
+ */
458
+ Selenium.prototype.doContext = function(context) {
459
+ return this.page().setContext(context);
460
+ };
461
+
462
+ /*
463
+ * Store the value of a form input in a variable
464
+ */
465
+ Selenium.prototype.doStoreValue = function(target, varName) {
466
+ if (!varName) {
467
+ // Backward compatibility mode: read the ENTIRE text of the page
468
+ // and stores it in a variable with the name of the target
469
+ value = this.page().bodyText();
470
+ storedVars[target] = value;
471
+ return;
472
+ }
473
+ var element = this.page().findElement(target);
474
+ storedVars[varName] = getInputValue(element);
475
+ };
476
+
477
+ /*
478
+ * Store the text of an element in a variable
479
+ */
480
+ Selenium.prototype.doStoreText = function(target, varName) {
481
+ var element = this.page().findElement(target);
482
+ storedVars[varName] = getText(element);
483
+ };
484
+
485
+ /*
486
+ * Store the value of an element attribute in a variable
487
+ */
488
+ Selenium.prototype.doStoreAttribute = function(target, varName) {
489
+ storedVars[varName] = this.page().findAttribute(target);
490
+ };
491
+
492
+ /*
493
+ * Store the result of a literal value
494
+ */
495
+ Selenium.prototype.doStore = function(value, varName) {
496
+ storedVars[varName] = value;
497
+ };
498
+
499
+
500
+ /*
501
+ * Wait for the target to have the specified value by polling.
502
+ * The polling is done in TestLoop.kickoffNextCommandExecution()
503
+ */
504
+ Selenium.prototype.doWaitForValue = function (target, value) {
505
+ var e = this.page().findElement(target);
506
+ testLoop.waitForCondition = function () {
507
+ return (e.value == value);
508
+ };
509
+ };
510
+
511
+ /**
512
+ * Evaluate a parameter, performing javascript evaluation and variable substitution.
513
+ * If the string matches the pattern "javascript{ ... }", evaluate the string between the braces.
514
+ */
515
+ Selenium.prototype.preprocessParameter = function(value) {
516
+ var match = value.match(/^javascript\{(.+)\}$/);
517
+ if (match && match[1]) {
518
+ return eval(match[1]).toString();
519
+ }
520
+ return this.replaceVariables(value);
521
+ };
522
+
523
+ /*
524
+ * Search through str and replace all variable references ${varName} with their
525
+ * value in storedVars.
526
+ */
527
+ Selenium.prototype.replaceVariables = function(str) {
528
+ var stringResult = str;
529
+
530
+ // Find all of the matching variable references
531
+ var match = stringResult.match(/\$\{\w+\}/g);
532
+ if (!match) {
533
+ return stringResult;
534
+ }
535
+
536
+ // For each match, lookup the variable value, and replace if found
537
+ for (var i = 0; match && i < match.length; i++) {
538
+ var variable = match[i]; // The replacement variable, with ${}
539
+ var name = variable.substring(2, variable.length - 1); // The replacement variable without ${}
540
+ var replacement = storedVars[name];
541
+ if (replacement != undefined) {
542
+ stringResult = stringResult.replace(variable, replacement);
543
+ }
544
+ }
545
+ return stringResult;
546
+ };
547
+
548
+
549
+ /**
550
+ * Factory for creating "Option Locators".
551
+ * An OptionLocator is an object for dealing with Select options (e.g. for
552
+ * finding a specified option, or asserting that the selected option of
553
+ * Select element matches some condition.
554
+ * The type of locator returned by the factory depends on the locator string:
555
+ * label=<exp> (OptionLocatorByLabel)
556
+ * value=<exp> (OptionLocatorByValue)
557
+ * index=<exp> (OptionLocatorByIndex)
558
+ * id=<exp> (OptionLocatorById)
559
+ * <exp> (default is OptionLocatorByLabel).
560
+ */
561
+ function OptionLocatorFactory() {
562
+ }
563
+
564
+ OptionLocatorFactory.prototype.fromLocatorString = function(locatorString) {
565
+ var locatorType = 'label';
566
+ var locatorValue = locatorString;
567
+ // If there is a locator prefix, use the specified strategy
568
+ var result = locatorString.match(/^([a-zA-Z]+)=(.*)/);
569
+ if (result) {
570
+ locatorType = result[1];
571
+ locatorValue = result[2];
572
+ }
573
+ if (this.optionLocators == undefined) {
574
+ this.registerOptionLocators();
575
+ }
576
+ if (this.optionLocators[locatorType]) {
577
+ return new this.optionLocators[locatorType](locatorValue);
578
+ }
579
+ throw new SeleniumError("Unkown option locator type: " + locatorType);
580
+ };
581
+
582
+ /**
583
+ * To allow for easy extension, all of the option locators are found by
584
+ * searching for all methods of OptionLocatorFactory.prototype that start
585
+ * with "OptionLocatorBy".
586
+ * TODO: Consider using the term "Option Specifier" instead of "Option Locator".
587
+ */
588
+ OptionLocatorFactory.prototype.registerOptionLocators = function() {
589
+ this.optionLocators={};
590
+ for (var functionName in this) {
591
+ var result = /OptionLocatorBy([A-Z].+)$/.exec(functionName);
592
+ if (result != null) {
593
+ var locatorName = result[1].lcfirst();
594
+ this.optionLocators[locatorName] = this[functionName];
595
+ }
596
+ }
597
+ };
598
+
599
+ /**
600
+ * OptionLocator for options identified by their labels.
601
+ */
602
+ OptionLocatorFactory.prototype.OptionLocatorByLabel = function(label) {
603
+ this.label = label;
604
+ this.labelMatcher = new PatternMatcher(this.label);
605
+ this.findOption = function(element) {
606
+ for (var i = 0; i < element.options.length; i++) {
607
+ if (this.labelMatcher.matches(element.options[i].text)) {
608
+ return element.options[i];
609
+ }
610
+ }
611
+ throw new SeleniumError("Option with label '" + this.label + "' not found");
612
+ };
613
+
614
+ this.assertSelected = function(element) {
615
+ var selectedLabel = element.options[element.selectedIndex].text;
616
+ Assert.matches(this.label, selectedLabel);
617
+ };
618
+ };
619
+
620
+ /**
621
+ * OptionLocator for options identified by their values.
622
+ */
623
+ OptionLocatorFactory.prototype.OptionLocatorByValue = function(value) {
624
+ this.value = value;
625
+ this.valueMatcher = new PatternMatcher(this.value);
626
+ this.findOption = function(element) {
627
+ for (var i = 0; i < element.options.length; i++) {
628
+ if (this.valueMatcher.matches(element.options[i].value)) {
629
+ return element.options[i];
630
+ }
631
+ }
632
+ throw new SeleniumError("Option with value '" + this.value + "' not found");
633
+ };
634
+
635
+ this.assertSelected = function(element) {
636
+ var selectedValue = element.options[element.selectedIndex].value;
637
+ Assert.matches(this.value, selectedValue);
638
+ };
639
+ };
640
+
641
+ /**
642
+ * OptionLocator for options identified by their index.
643
+ */
644
+ OptionLocatorFactory.prototype.OptionLocatorByIndex = function(index) {
645
+ this.index = Number(index);
646
+ if (isNaN(this.index) || this.index < 0) {
647
+ throw new SeleniumError("Illegal Index: " + index);
648
+ }
649
+
650
+ this.findOption = function(element) {
651
+ if (element.options.length <= this.index) {
652
+ throw new SeleniumError("Index out of range. Only " + element.options.length + " options available");
653
+ }
654
+ return element.options[this.index];
655
+ };
656
+
657
+ this.assertSelected = function(element) {
658
+ Assert.equals(this.index, element.selectedIndex);
659
+ };
660
+ };
661
+
662
+ /**
663
+ * OptionLocator for options identified by their id.
664
+ */
665
+ OptionLocatorFactory.prototype.OptionLocatorById = function(id) {
666
+ this.id = id;
667
+ this.idMatcher = new PatternMatcher(this.id);
668
+ this.findOption = function(element) {
669
+ for (var i = 0; i < element.options.length; i++) {
670
+ if (this.idMatcher.matches(element.options[i].id)) {
671
+ return element.options[i];
672
+ }
673
+ }
674
+ throw new SeleniumError("Option with id '" + this.id + "' not found");
675
+ };
676
+
677
+ this.assertSelected = function(element) {
678
+ var selectedId = element.options[element.selectedIndex].id;
679
+ Assert.matches(this.id, selectedId);
680
+ };
681
+ };
682
+
683
+