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,16 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <title>DOM Viewer</title>
6
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
7
+ <link rel="stylesheet" type="text/css" href="dom-styles/default.css"/>
8
+ <script type="text/javascript" src="selenium-domviewer.js"></script>
9
+ </head>
10
+ <body onload="loadDomViewer();">
11
+ <h3>DOM Viewer</h3>
12
+ <p> This page is generated using JavaScript. If you see this text, your
13
+ browser doesn't support JavaScript.</p>
14
+ </body>
15
+
16
+ </html>
@@ -0,0 +1,75 @@
1
+ <html>
2
+ <head>
3
+ <title>DOM Level 3 XPath Example</title>
4
+ <script language="javascript" type="text/javascript" src="html-xpath.js"></script>
5
+ </head>
6
+ <body>
7
+ <div class="Test">
8
+ Test Node <span class="Number">1</span>
9
+ </div>
10
+
11
+ <span id="TestingGround">
12
+ <div class="SomeOtherClass">
13
+ <div class="Test" id="ContextNodeTest">
14
+ Test Node <span class="Number">2</span>
15
+ <p>Test Node <span class="Number">3</span>: Unclosed Paragraph tag
16
+ <div class="Test">
17
+ Test Node <span class="Number">4</span>: Nesting
18
+ </div>
19
+ <img src="rainbow.jpg" alt="Something I found in my backyard" width="100" height="200" alt="Test image" someOtherAttribute="someOtherValue" />
20
+ <img src="carnation.jpg" alt="Carnation" width="99" height="74">
21
+ </div>
22
+ </div>
23
+ </span>
24
+
25
+ <script language="javascript">
26
+
27
+ function showIterator(title, result)
28
+ {
29
+ var s = title;
30
+ var item;
31
+ while(item = result.iterateNext())
32
+ {
33
+ s += "<div class=\"XPathResultItem\">" + (item.nodeType == 1 ? item.innerHTML.replace(/</g, "&lt;").replace(/>/g, "&gt;") : item.nodeValue) + "</div>";
34
+ }
35
+ document.write(s);
36
+ }
37
+
38
+ // Evaluate 1
39
+ var result = document.evaluate("//div[@class='Test']", document, null, XPathResult.STRING_TYPE, null);
40
+ document.write("<h1>\"//div[@class='Test']\" as String</h1>" + result.getStringValue());
41
+
42
+ // Evaluate 2
43
+ document.evaluate("//img[@width < 100]/@height", document, null, XPathResult.NUMBER_TYPE, result);
44
+ document.write("<h1>\"//img[@width < 100]/@height\" as Number</h1>" + result.getNumberValue());
45
+
46
+ // Evaluate 3
47
+ showIterator
48
+ (
49
+ "<h1>\"//div[@class='Test']\" in context of document</h1>",
50
+ document.evaluate("//div[@class='Test']", document, null, XPathResult.ANY_TYPE, result)
51
+ );
52
+
53
+ // Evaluate 4
54
+ showIterator
55
+ (
56
+ "<h1>\"div[@class='Test']\" in context of a specific node (id=\"ContextNodeTest\")</h1>",
57
+ document.evaluate("div[@class='Test']", document.getElementById("ContextNodeTest"), null, XPathResult.ANY_TYPE, result)
58
+ );
59
+
60
+ // Evaluate 5
61
+ showIterator
62
+ (
63
+ "<h1>\"//div/@class\": Retrieve Attribute Values</h1>",
64
+ document.evaluate("//div/@class", document, null, 0, result)
65
+ );
66
+
67
+ // Evaluate 6
68
+ var result = document.evaluate("count(//span[@class='Number'])", document, null, XPathResult.NUMBER_TYPE, null);
69
+ document.write("<h1>\"count(//span[@class='Number'])\" as Number</h1>" + result.getNumberValue());
70
+
71
+ </script>
72
+
73
+
74
+ </body>
75
+ </html>
@@ -0,0 +1,657 @@
1
+ /*
2
+ html-xpath, an implementation of DOM Level 3 XPath for Internet Explorer 5+
3
+ Copyright (C) 2004 Dimitri Glazkov
4
+
5
+ This library is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU Lesser General Public
7
+ License as published by the Free Software Foundation; either
8
+ version 2.1 of the License, or (at your option) any later version.
9
+
10
+ This library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public
16
+ License along with this library; if not, write to the Free Software
17
+
18
+ */
19
+
20
+ /** SELENIUM:PATCH TO ALLOW USE WITH DOCUMENTS FROM OTHER WINDOWS: 2004-11-24
21
+ TODO resubmit this to http://sf.net/projects/html-xpath */
22
+ function addXPathSupport(document) {
23
+ /** END SELENIUM:PATCH */
24
+
25
+ var isIe = /MSIE [56789]/.test(navigator.userAgent) && (navigator.platform == "Win32");
26
+
27
+ // Mozilla has support by default, we don't have an implementation for the rest
28
+ if (isIe)
29
+ {
30
+ // release number
31
+ document.DomL3XPathRelease = "0.0.3.0";
32
+
33
+ // XPathException
34
+ // An Error object will be thrown, this is just a handler to instantiate that object
35
+ var XPathException = new _XPathExceptionHandler();
36
+ function _XPathExceptionHandler()
37
+ {
38
+ this.INVALID_EXPRESSION_ERR = 51;
39
+ this.TYPE_ERR = 52;
40
+ this.NOT_IMPLEMENTED_ERR = -1;
41
+ this.RUNTIME_ERR = -2;
42
+
43
+ this.ThrowNotImplemented = function(message)
44
+ {
45
+ ThrowError(this.NOT_IMPLEMENTED_ERR, "This functionality is not implemented.", message);
46
+ }
47
+
48
+ this.ThrowInvalidExpression = function(message)
49
+ {
50
+ ThrowError(this.INVALID_EXPRESSION_ERR, "Invalid expression", message);
51
+ }
52
+
53
+ this.ThrowType = function(message)
54
+ {
55
+ ThrowError(this.TYPE_ERR, "Type error", message);
56
+ }
57
+
58
+ this.Throw = function(message)
59
+ {
60
+ ThrowError(this.RUNTIME_ERR, "Run-time error", message);
61
+ }
62
+
63
+ function ThrowError(code, description, message)
64
+ {
65
+ var error = new Error(code, "DOM-L3-XPath " + document.DomL3XPathRelease + ": " + description + (message ? ", \"" + message + "\"": ""));
66
+ error.code = code;
67
+ error.name = "XPathException";
68
+ throw error;
69
+ }
70
+ }
71
+
72
+ // DOMException
73
+ // An Error object will be thrown, this is just a handler to instantiate that object
74
+ var DOMException = new _DOMExceptionHandler();
75
+ function _DOMExceptionHandler()
76
+ {
77
+ this.ThrowInvalidState = function(message)
78
+ {
79
+ ThrowError(13, "The state of the object is no longer valid", message);
80
+ }
81
+
82
+ function ThrowError(code, description, message)
83
+ {
84
+ var error = new Error(code, "DOM : " + description + (message ? ", \"" + message + "\"": ""));
85
+ error.code = code;
86
+ error.name = "DOMException";
87
+ throw error;
88
+ }
89
+ }
90
+
91
+ // XPathEvaluator
92
+ // implemented as document object methods
93
+
94
+ // XPathExpression createExpression(String expression, XPathNSResolver resolver)
95
+ document.createExpression = function
96
+ (
97
+ expression, // String
98
+ resolver // XPathNSResolver
99
+ )
100
+ {
101
+ // returns XPathExpression object
102
+ return new XPathExpression(expression, resolver);
103
+ }
104
+
105
+ // XPathNSResolver createNSResolver(nodeResolver)
106
+ document.createNSResolver = function
107
+ (
108
+ nodeResolver // Node
109
+ )
110
+ {
111
+ // returns XPathNSResolver
112
+ return new XPathNSResolver(nodeResolver);
113
+ }
114
+
115
+ // XPathResult evaluate(String expresison, Node contextNode, XPathNSResolver resolver, Number type, XPathResult result)
116
+ document.evaluate = function
117
+ (
118
+ expression, // String
119
+ contextNode, // Node
120
+ resolver, // XPathNSResolver
121
+ type, // Number
122
+ result // XPathResult
123
+ )
124
+ // can raise XPathException, DOMException
125
+ {
126
+ // return XPathResult
127
+ return document.createExpression(expression, resolver).evaluate(contextNode, type, result);
128
+ }
129
+
130
+ // XPathExpression
131
+ function XPathExpression
132
+ (
133
+ expression, // String
134
+ resolver // XPathNSResolver
135
+ )
136
+ {
137
+ this.expressionString = expression;
138
+ this.resolver = resolver;
139
+
140
+ // XPathResult evaluate(Node contextNode, Number type, XPathResult result)
141
+ this.evaluate = function
142
+ (
143
+ contextNode, // Node
144
+ type, // Number
145
+ result // XPathResult
146
+ )
147
+ // raises XPathException, DOMException
148
+ {
149
+ // return XPathResult
150
+ return (result && result.constructor == XPathResult ? result.initialize(this, contextNode, resolver, type) : new XPathResult(this, contextNode, resolver, type));
151
+ }
152
+
153
+ this.toString = function()
154
+ {
155
+ return "[XPathExpression]";
156
+ }
157
+ }
158
+
159
+ // XPathNSResolver
160
+ function XPathNSResolver(node)
161
+ {
162
+ this.node = node;
163
+
164
+ // String lookupNamespaceURI(String prefix)
165
+ this.lookupNamespaceURI = function
166
+ (
167
+ prefix // String
168
+ )
169
+ {
170
+ XPathException.ThrowNotImplemented();
171
+ // return String
172
+ return null;
173
+ }
174
+
175
+ this.toString = function()
176
+ {
177
+ return "[XPathNSResolver]";
178
+ }
179
+ }
180
+
181
+ // XPathResult
182
+ XPathResult.ANY_TYPE = 0;
183
+ XPathResult.NUMBER_TYPE = 1;
184
+ XPathResult.STRING_TYPE = 2;
185
+ XPathResult.BOOLEAN_TYPE = 3;
186
+ XPathResult.UNORDERED_NODE_ITERATOR_TYPE = 4;
187
+ XPathResult.ORDERED_NODE_ITERATOR_TYPE = 5;
188
+ XPathResult.UNORDERED_SNAPSHOT_TYPE = 6;
189
+ XPathResult.ORDERED_SNAPSHOT_TYPE = 7;
190
+ XPathResult.ANY_UNORDERED_NODE_TYPE = 8;
191
+ XPathResult.FIRST_ORDERED_NODE_TYPE = 9;
192
+
193
+ function XPathResult
194
+ (
195
+ expression, // XPathExpression
196
+ contextNode, // Node
197
+ resolver, // XPathNSResolver
198
+ type // Number
199
+ )
200
+ {
201
+ this.initialize = function(expression, contextNode, resolver, type)
202
+ {
203
+ this._domResult = null;
204
+ this._expression = expression;
205
+ this._contextNode = contextNode;
206
+ this._resolver = resolver;
207
+ if (type)
208
+ {
209
+ this.resultType = type;
210
+ this._isIterator = (type == XPathResult.UNORDERED_NODE_ITERATOR_TYPE ||
211
+ type == XPathResult.ORDERED_NODE_ITERATOR_TYPE ||
212
+ type == XPathResult.ANY_TYPE);
213
+ this._isSnapshot = (type == XPathResult.UNORDERED_SNAPSHOT_TYPE || type == XPathResult.ORDERED_SNAPSHOT_TYPE);
214
+ this._isNodeSet = type > XPathResult.BOOLEAN_TYPE;
215
+ }
216
+ else
217
+ {
218
+ this.resultType = XPathResult.ANY_TYPE;
219
+ this._isIterator = true;
220
+ this._isSnapshot = false;
221
+ this._isNodeSet = true;
222
+ }
223
+ return this;
224
+ }
225
+
226
+ this.initialize(expression, contextNode, resolver, type);
227
+
228
+ this.getInvalidIteratorState = function()
229
+ {
230
+ return documentChangeDetected() || !this._isIterator;
231
+ }
232
+
233
+ this.getSnapshotLength = function()
234
+ // raises XPathException
235
+ {
236
+ if (!this._isSnapshot)
237
+ {
238
+ XPathException.ThrowType("Snapshot is not an expected result type");
239
+ }
240
+ activateResult(this);
241
+ // return Number
242
+ return this._domResult.length;
243
+ }
244
+
245
+ // Node iterateNext()
246
+ this.iterateNext = function()
247
+ // raises XPathException, DOMException
248
+ {
249
+ if (!this._isIterator)
250
+ {
251
+ XPathException.ThrowType("Iterator is not an expected result type");
252
+ }
253
+ activateResult(this);
254
+ if (documentChangeDetected())
255
+ {
256
+ DOMException.ThrowInvalidState("iterateNext");
257
+ }
258
+ // return Node
259
+ return getNextNode(this);
260
+ }
261
+
262
+ // Node snapshotItem(Number index)
263
+ this.snapshotItem = function(index)
264
+ // raises XPathException
265
+ {
266
+ if (!this._isSnapshot)
267
+ {
268
+ XPathException.ThrowType("Snapshot is not an expected result type");
269
+ }
270
+ // return Node
271
+ return getItemNode(this, index);
272
+ }
273
+
274
+ this.toString = function()
275
+ {
276
+ return "[XPathResult]";
277
+ }
278
+
279
+ // returns string value of the result, if result type is STRING_TYPE
280
+ // otherwise throws an XPathException
281
+ this.getStringValue = function()
282
+ {
283
+ if (this.resultType != XPathResult.STRING_TYPE)
284
+ {
285
+ XPathException.ThrowType("The expression can not be converted to return String");
286
+ }
287
+ return getNodeText(this);
288
+ }
289
+
290
+ // returns number value of the result, if the result is NUMBER_TYPE
291
+ // otherwise throws an XPathException
292
+ this.getNumberValue = function()
293
+ {
294
+ if (this.resultType != XPathResult.NUMBER_TYPE)
295
+ {
296
+ XPathException.ThrowType("The expression can not be converted to return Number");
297
+ }
298
+ var number = parseInt(getNodeText(this));
299
+ if (isNaN(number))
300
+ {
301
+ XPathException.ThrowType("The result can not be converted to Number");
302
+ }
303
+ return number;
304
+ }
305
+
306
+ // returns boolean value of the result, if the result is BOOLEAN_TYPE
307
+ // otherwise throws an XPathException
308
+ this.getBooleanValue = function()
309
+ {
310
+ if (this.resultType != XPathResult.BOOLEAN_TYPE)
311
+ {
312
+ XPathException.ThrowType("The expression can not be converted to return Boolean");
313
+ }
314
+
315
+ var
316
+ text = getNodeText(this);
317
+ bool = (text ? text.toLowerCase() : null);
318
+ if (bool == "false" || bool == "true")
319
+ {
320
+ return bool;
321
+ }
322
+ XPathException.ThrowType("The result can not be converted to Boolean");
323
+ }
324
+
325
+ // returns single node, if the result is ANY_UNORDERED_NODE_TYPE or FIRST_ORDERED_NODE_TYPE
326
+ // otherwise throws an XPathException
327
+ this.getSingleNodeValue = function()
328
+ {
329
+ if (this.resultType != XPathResult.ANY_UNORDERED_NODE_TYPE &&
330
+ this.resultType != XPathResult.FIRST_ORDERED_NODE_TYPE)
331
+ {
332
+ XPathException.ThrowType("The expression can not be converted to return single Node value");
333
+ }
334
+ return getSingleNode(this);
335
+ }
336
+
337
+ function documentChangeDetected()
338
+ {
339
+ return document._XPathMsxmlDocumentHelper.documentChangeDetected();
340
+ }
341
+
342
+ function getNodeText(result)
343
+ {
344
+ activateResult(result);
345
+ return result._textResult;
346
+ // return ((node = getSingleNode(result)) ? (node.nodeType == 1 ? node.innerText : node.nodeValue) : null);
347
+ }
348
+
349
+ function findNode(result, current)
350
+ {
351
+ switch(current.nodeType)
352
+ {
353
+ case 1: // NODE_ELEMENT
354
+ var id = current.attributes.getNamedItem("id");
355
+ if (id)
356
+ {
357
+ return document.getElementById(id.value);
358
+ }
359
+ XPathException.Throw("unable to locate element in XML tree");
360
+ case 2: // NODE_ATTRIBUTE
361
+ var id = current.selectSingleNode("..").attributes.getNamedItem("id");
362
+ if (id)
363
+ {
364
+ var node = document.getElementById(id.text);
365
+ if (node)
366
+ {
367
+ return node.attributes.getNamedItem(current.nodeName);
368
+ }
369
+ }
370
+ XPathException.Throw("unable to locate attribute in XML tree");
371
+ case 3: // NODE_TEXT
372
+ var id = current.selectSingleNode("..").attributes.getNamedItem("id");
373
+ if (id)
374
+ {
375
+ var node = document.getElementById(id.value);
376
+ if (node)
377
+ {
378
+ for(child in node.childNodes)
379
+ {
380
+ if (child.nodeType == 3 && child.nodeValue == current.nodeValue)
381
+ {
382
+ return child;
383
+ }
384
+ }
385
+ }
386
+ }
387
+ XPathException.Throw("unable to locate text in XML tree");
388
+ }
389
+ XPathException.Throw("unknown node type");
390
+ }
391
+
392
+ function activateResult(result)
393
+ {
394
+ if (!result._domResult)
395
+ {
396
+ try
397
+ {
398
+ var expression = result._expression.expressionString;
399
+
400
+ // adjust expression if contextNode is not a document
401
+ if (result._contextNode != document && expression.indexOf("//") != 0)
402
+ {
403
+
404
+ expression = "//*[@id = '" + result._contextNode.id + "']" +
405
+ (expression.indexOf("/") == 0 ? "" : "/") + expression;
406
+ }
407
+
408
+ if (result._isNodeSet)
409
+ {
410
+ result._domResult = document._XPathMsxmlDocumentHelper.getDom().selectNodes(expression);
411
+ }
412
+ else
413
+ {
414
+ result._domResult = true;
415
+ result._textResult = document._XPathMsxmlDocumentHelper.getTextResult(expression);
416
+ }
417
+
418
+ }
419
+ catch(error)
420
+ {
421
+ alert(error.description);
422
+ XPathException.ThrowInvalidExpression(error.description);
423
+ }
424
+ }
425
+ }
426
+
427
+ function getSingleNode(result)
428
+ {
429
+ var node = getItemNode(result, 0);
430
+ result._domResult = null;
431
+ return node;
432
+ }
433
+
434
+ function getItemNode(result, index)
435
+ {
436
+ activateResult(result);
437
+ var current = result._domResult.item(index);
438
+ return (current ? findNode(result, current) : null);
439
+ }
440
+
441
+ function getNextNode(result)
442
+ {
443
+ var current = result._domResult.nextNode;
444
+ if (current)
445
+ {
446
+ return findNode(result, current);
447
+ }
448
+ result._domResult = null;
449
+ return null;
450
+ }
451
+ }
452
+
453
+ document.reloadDom = function()
454
+ {
455
+ document._XPathMsxmlDocumentHelper.reset();
456
+ }
457
+
458
+ document._XPathMsxmlDocumentHelper = new _XPathMsxmlDocumentHelper();
459
+ function _XPathMsxmlDocumentHelper()
460
+ {
461
+ this.getDom = function()
462
+ {
463
+ activateDom(this);
464
+ return this.dom;
465
+ }
466
+
467
+ this.getXml = function()
468
+ {
469
+ activateDom(this);
470
+ return this.dom.xml;
471
+ }
472
+
473
+ this.getTextResult = function(expression)
474
+ {
475
+ expression = expression.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "\"");
476
+ var xslText = "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" +
477
+ "<xsl:output method=\"text\"/><xsl:template match=\"*\"><xsl:value-of select=\"" + expression + "\"/>" +
478
+ "</xsl:template></xsl:stylesheet>";
479
+ var xsl = new ActiveXObject("Msxml2.DOMDocument");
480
+ xsl.loadXML(xslText);
481
+ try
482
+ {
483
+ var result = this.getDom().transformNode(xsl);
484
+ }
485
+ catch(error)
486
+ {
487
+ alert("Error: " + error.description);
488
+ }
489
+ return result;
490
+ }
491
+
492
+ this.reset = function()
493
+ {
494
+ this.dom = null;
495
+ }
496
+
497
+ function onPropertyChangeEventHandler()
498
+ {
499
+ document._propertyChangeDetected = true;
500
+ }
501
+
502
+ this.documentChangeDetected = function()
503
+ {
504
+ return (document.ignoreDocumentChanges ? false : this._currentElementCount != document.all.length || document._propertyChangeDetected);
505
+ }
506
+
507
+ function activateDom(helper)
508
+ {
509
+ if (!helper.dom)
510
+ {
511
+ var dom = new ActiveXObject("Msxml2.DOMDocument");
512
+ /** SELENIUM:PATCH TO ALLOW PROVIDE FULL XPATH SUPPORT */
513
+ dom.setProperty("SelectionLanguage", "XPath");
514
+ /** END SELENIUM:PATCH */
515
+ dom.async = false;
516
+ dom.resolveExternals = false;
517
+ loadDocument(dom, helper);
518
+ helper.dom = dom;
519
+ helper._currentElementCount = document.all.length;
520
+ document._propertyChangeDetected = false;
521
+ }
522
+ else
523
+ {
524
+ if (helper.documentChangeDetected())
525
+ {
526
+ var dom = helper.dom;
527
+ dom.load("");
528
+ loadDocument(dom, helper);
529
+ helper._currentElementCount = document.all.length;
530
+ document._propertyChangeDetected = false;
531
+ }
532
+ }
533
+ }
534
+
535
+ function loadDocument(dom, helper)
536
+ {
537
+ return loadNode(dom, dom, document.body, helper);
538
+ }
539
+
540
+
541
+ /** SELENIUM:PATCH for loadNode() - see SEL-68 */
542
+ function loadNode(dom, domParentNode, node, helper)
543
+ {
544
+ // Bad node scenarios
545
+ // 1. If the node contains a /, it's broken HTML
546
+ // 2. If the node doesn't have a name (typically from broken HTML), the node can't be loaded
547
+ // 3. Node types we can't deal with
548
+ //
549
+ // In all scenarios, we just skip the node. We won't be able to
550
+ // query on these nodes, but they're broken anyway.
551
+ if (node.nodeName.indexOf("/") > -1
552
+ || node.nodeName == ""
553
+ || node.nodeName == "#document"
554
+ || node.nodeName == "#document-fragment"
555
+ || node.nodeName == "#cdata-section"
556
+ || node.nodeName == "#xml-declaration"
557
+ || node.nodeName == "#whitespace"
558
+ || node.nodeName == "#significat-whitespace"
559
+ )
560
+ {
561
+ return;
562
+ }
563
+
564
+ // #comment is a <!-- comment -->, which must be created with createComment()
565
+ if (node.nodeName == "#comment")
566
+ {
567
+ try
568
+ {
569
+ domParentNode.appendChild(dom.createComment(node.nodeValue));
570
+ }
571
+ catch (ex)
572
+ {
573
+ // it's just a comment, we don't care
574
+ }
575
+ }
576
+ else if (node.nodeType == 3)
577
+ {
578
+ domParentNode.appendChild(dom.createTextNode(node.nodeValue));
579
+ }
580
+ else
581
+ {
582
+ var domNode = dom.createElement(node.nodeName.toLowerCase());
583
+ if (!node.id)
584
+ {
585
+ node.id = node.uniqueID;
586
+ }
587
+ domParentNode.appendChild(domNode);
588
+ loadAttributes(dom, domNode, node);
589
+ var length = node.childNodes.length;
590
+ for(var i = 0; i < length; i ++ )
591
+ {
592
+ loadNode(dom, domNode, node.childNodes[i], helper);
593
+ }
594
+ node.attachEvent("onpropertychange", onPropertyChangeEventHandler);
595
+ }
596
+ }
597
+ /** END SELENIUM:PATCH */
598
+
599
+ function loadAttributes(dom, domParentNode, node)
600
+ {
601
+ for (var i = 0; i < node.attributes.length; i ++ )
602
+ {
603
+ var attribute = node.attributes[i];
604
+ var attributeValue = attribute.nodeValue;
605
+ if (attributeValue && attribute.specified)
606
+ {
607
+ var domAttribute = dom.createAttribute(attribute.nodeName);
608
+ domAttribute.value = attributeValue;
609
+ domParentNode.setAttributeNode(domAttribute);
610
+ }
611
+ }
612
+ }
613
+
614
+ }
615
+ }
616
+ else
617
+ {
618
+ document.reloadDom = function() {}
619
+ XPathResult.prototype.getStringValue = function()
620
+ {
621
+ return this.stringValue;
622
+ }
623
+
624
+ XPathResult.prototype.getNumberValue = function()
625
+ {
626
+ return this.numberValue;
627
+ }
628
+
629
+ XPathResult.prototype.getBooleanValue = function()
630
+ {
631
+ return this.booleanValue;
632
+ }
633
+
634
+ XPathResult.prototype.getSingleNodeValue = function()
635
+ {
636
+ return this.singleNodeValue;
637
+ }
638
+
639
+ XPathResult.prototype.getInvalidIteratorState = function()
640
+ {
641
+ return this.invalidIteratorState;
642
+ }
643
+
644
+ XPathResult.prototype.getSnapshotLength = function()
645
+ {
646
+ return this.snapshotLength;
647
+ }
648
+
649
+ XPathResult.prototype.getResultType = function()
650
+ {
651
+ return this.resultType;
652
+ }
653
+ }
654
+ /** SELENIUM:PATCH TO ALLOW USE WITH CONTAINED DOCUMENTS */
655
+ }
656
+ /** END SELENIUM:PATCH */
657
+