rainux-selenium-webdriver 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. data/COPYING +204 -0
  2. data/chrome/prebuilt/Win32/Release/npchromedriver.dll +0 -0
  3. data/chrome/prebuilt/x64/Release/npchromedriver.dll +0 -0
  4. data/chrome/src/extension/background.html +9 -0
  5. data/chrome/src/extension/background.js +995 -0
  6. data/chrome/src/extension/content_script.js +1321 -0
  7. data/chrome/src/extension/icons/busy.png +0 -0
  8. data/chrome/src/extension/icons/free.png +0 -0
  9. data/chrome/src/extension/manifest-nonwin.json +19 -0
  10. data/chrome/src/extension/manifest-win.json +20 -0
  11. data/chrome/src/extension/utils.js +231 -0
  12. data/chrome/src/rb/lib/selenium/webdriver/chrome.rb +8 -0
  13. data/chrome/src/rb/lib/selenium/webdriver/chrome/bridge.rb +358 -0
  14. data/chrome/src/rb/lib/selenium/webdriver/chrome/command_executor.rb +124 -0
  15. data/chrome/src/rb/lib/selenium/webdriver/chrome/launcher.rb +135 -0
  16. data/common/src/js/abstractcommandprocessor.js +134 -0
  17. data/common/src/js/asserts.js +296 -0
  18. data/common/src/js/by.js +149 -0
  19. data/common/src/js/command.js +304 -0
  20. data/common/src/js/context.js +58 -0
  21. data/common/src/js/core/Blank.html +7 -0
  22. data/common/src/js/core/InjectedRemoteRunner.html +8 -0
  23. data/common/src/js/core/RemoteRunner.html +101 -0
  24. data/common/src/js/core/SeleniumLog.html +109 -0
  25. data/common/src/js/core/TestPrompt.html +145 -0
  26. data/common/src/js/core/TestRunner-splash.html +55 -0
  27. data/common/src/js/core/TestRunner.html +165 -0
  28. data/common/src/js/core/icons/all.png +0 -0
  29. data/common/src/js/core/icons/continue.png +0 -0
  30. data/common/src/js/core/icons/continue_disabled.png +0 -0
  31. data/common/src/js/core/icons/pause.png +0 -0
  32. data/common/src/js/core/icons/pause_disabled.png +0 -0
  33. data/common/src/js/core/icons/selected.png +0 -0
  34. data/common/src/js/core/icons/step.png +0 -0
  35. data/common/src/js/core/icons/step_disabled.png +0 -0
  36. data/common/src/js/core/lib/cssQuery/cssQuery-p.js +6 -0
  37. data/common/src/js/core/lib/cssQuery/src/cssQuery-level2.js +142 -0
  38. data/common/src/js/core/lib/cssQuery/src/cssQuery-level3.js +150 -0
  39. data/common/src/js/core/lib/cssQuery/src/cssQuery-standard.js +53 -0
  40. data/common/src/js/core/lib/cssQuery/src/cssQuery.js +356 -0
  41. data/common/src/js/core/lib/prototype.js +2006 -0
  42. data/common/src/js/core/lib/scriptaculous/builder.js +101 -0
  43. data/common/src/js/core/lib/scriptaculous/controls.js +815 -0
  44. data/common/src/js/core/lib/scriptaculous/dragdrop.js +915 -0
  45. data/common/src/js/core/lib/scriptaculous/effects.js +958 -0
  46. data/common/src/js/core/lib/scriptaculous/scriptaculous.js +47 -0
  47. data/common/src/js/core/lib/scriptaculous/slider.js +283 -0
  48. data/common/src/js/core/lib/scriptaculous/unittest.js +383 -0
  49. data/common/src/js/core/lib/snapsie.js +91 -0
  50. data/common/src/js/core/scripts/find_matching_child.js +69 -0
  51. data/common/src/js/core/scripts/htmlutils.js +8716 -0
  52. data/common/src/js/core/scripts/injection.html +72 -0
  53. data/common/src/js/core/scripts/selenium-api.js +3291 -0
  54. data/common/src/js/core/scripts/selenium-browserbot.js +2457 -0
  55. data/common/src/js/core/scripts/selenium-browserdetect.js +153 -0
  56. data/common/src/js/core/scripts/selenium-commandhandlers.js +379 -0
  57. data/common/src/js/core/scripts/selenium-executionloop.js +175 -0
  58. data/common/src/js/core/scripts/selenium-logging.js +148 -0
  59. data/common/src/js/core/scripts/selenium-remoterunner.js +695 -0
  60. data/common/src/js/core/scripts/selenium-testrunner.js +1362 -0
  61. data/common/src/js/core/scripts/selenium-version.js +5 -0
  62. data/common/src/js/core/scripts/ui-doc.html +808 -0
  63. data/common/src/js/core/scripts/ui-element.js +1644 -0
  64. data/common/src/js/core/scripts/ui-map-sample.js +979 -0
  65. data/common/src/js/core/scripts/user-extensions.js +3 -0
  66. data/common/src/js/core/scripts/user-extensions.js.sample +75 -0
  67. data/common/src/js/core/scripts/xmlextras.js +153 -0
  68. data/common/src/js/core/selenium-logo.png +0 -0
  69. data/common/src/js/core/selenium-test.css +43 -0
  70. data/common/src/js/core/selenium.css +316 -0
  71. data/common/src/js/core/xpath/dom.js +566 -0
  72. data/common/src/js/core/xpath/javascript-xpath-0.1.11.js +2816 -0
  73. data/common/src/js/core/xpath/util.js +549 -0
  74. data/common/src/js/core/xpath/xmltoken.js +149 -0
  75. data/common/src/js/core/xpath/xpath.js +2481 -0
  76. data/common/src/js/extension/README +2 -0
  77. data/common/src/js/extension/dommessenger.js +152 -0
  78. data/common/src/js/factory.js +55 -0
  79. data/common/src/js/future.js +141 -0
  80. data/common/src/js/jsunit.js +40 -0
  81. data/common/src/js/jsunit/app/css/jsUnitStyle.css +50 -0
  82. data/common/src/js/jsunit/app/css/readme +10 -0
  83. data/common/src/js/jsunit/app/emptyPage.html +11 -0
  84. data/common/src/js/jsunit/app/jsUnitCore.js +534 -0
  85. data/common/src/js/jsunit/app/jsUnitMockTimeout.js +81 -0
  86. data/common/src/js/jsunit/app/jsUnitTestManager.js +705 -0
  87. data/common/src/js/jsunit/app/jsUnitTestSuite.js +44 -0
  88. data/common/src/js/jsunit/app/jsUnitTracer.js +102 -0
  89. data/common/src/js/jsunit/app/jsUnitVersionCheck.js +59 -0
  90. data/common/src/js/jsunit/app/main-counts-errors.html +12 -0
  91. data/common/src/js/jsunit/app/main-counts-failures.html +13 -0
  92. data/common/src/js/jsunit/app/main-counts-runs.html +13 -0
  93. data/common/src/js/jsunit/app/main-counts.html +21 -0
  94. data/common/src/js/jsunit/app/main-data.html +178 -0
  95. data/common/src/js/jsunit/app/main-errors.html +23 -0
  96. data/common/src/js/jsunit/app/main-frame.html +19 -0
  97. data/common/src/js/jsunit/app/main-loader.html +45 -0
  98. data/common/src/js/jsunit/app/main-progress.html +25 -0
  99. data/common/src/js/jsunit/app/main-results.html +67 -0
  100. data/common/src/js/jsunit/app/main-status.html +13 -0
  101. data/common/src/js/jsunit/app/testContainer.html +16 -0
  102. data/common/src/js/jsunit/app/testContainerController.html +77 -0
  103. data/common/src/js/jsunit/app/xbDebug.js +306 -0
  104. data/common/src/js/jsunit/changelog.txt +60 -0
  105. data/common/src/js/jsunit/css/jsUnitStyle.css +83 -0
  106. data/common/src/js/jsunit/images/green.gif +0 -0
  107. data/common/src/js/jsunit/images/logo_jsunit.gif +0 -0
  108. data/common/src/js/jsunit/images/powerby-transparent.gif +0 -0
  109. data/common/src/js/jsunit/images/red.gif +0 -0
  110. data/common/src/js/jsunit/licenses/JDOM_license.txt +56 -0
  111. data/common/src/js/jsunit/licenses/Jetty_license.html +213 -0
  112. data/common/src/js/jsunit/licenses/MPL-1.1.txt +470 -0
  113. data/common/src/js/jsunit/licenses/gpl-2.txt +340 -0
  114. data/common/src/js/jsunit/licenses/index.html +141 -0
  115. data/common/src/js/jsunit/licenses/lgpl-2.1.txt +504 -0
  116. data/common/src/js/jsunit/licenses/mpl-tri-license-c.txt +35 -0
  117. data/common/src/js/jsunit/licenses/mpl-tri-license-html.txt +35 -0
  118. data/common/src/js/jsunit/readme.txt +19 -0
  119. data/common/src/js/jsunit/testRunner.html +167 -0
  120. data/common/src/js/jsunit/version.txt +1 -0
  121. data/common/src/js/key.js +117 -0
  122. data/common/src/js/localcommandprocessor.js +185 -0
  123. data/common/src/js/testcase.js +217 -0
  124. data/common/src/js/timing.js +89 -0
  125. data/common/src/js/webdriver.js +890 -0
  126. data/common/src/js/webelement.js +485 -0
  127. data/common/src/rb/README +30 -0
  128. data/common/src/rb/lib/selenium-webdriver.rb +1 -0
  129. data/common/src/rb/lib/selenium/webdriver.rb +67 -0
  130. data/common/src/rb/lib/selenium/webdriver/bridge_helper.rb +91 -0
  131. data/common/src/rb/lib/selenium/webdriver/child_process.rb +180 -0
  132. data/common/src/rb/lib/selenium/webdriver/core_ext/dir.rb +41 -0
  133. data/common/src/rb/lib/selenium/webdriver/driver.rb +252 -0
  134. data/common/src/rb/lib/selenium/webdriver/driver_extensions/takes_screenshot.rb +24 -0
  135. data/common/src/rb/lib/selenium/webdriver/element.rb +262 -0
  136. data/common/src/rb/lib/selenium/webdriver/error.rb +67 -0
  137. data/common/src/rb/lib/selenium/webdriver/find.rb +89 -0
  138. data/common/src/rb/lib/selenium/webdriver/keys.rb +84 -0
  139. data/common/src/rb/lib/selenium/webdriver/navigation.rb +27 -0
  140. data/common/src/rb/lib/selenium/webdriver/options.rb +50 -0
  141. data/common/src/rb/lib/selenium/webdriver/platform.rb +86 -0
  142. data/common/src/rb/lib/selenium/webdriver/target_locator.rb +70 -0
  143. data/firefox/prebuilt/Win32/Release/webdriver-firefox.dll +0 -0
  144. data/firefox/prebuilt/linux/Release/libwebdriver-firefox.so +0 -0
  145. data/firefox/prebuilt/linux/Release/x_ignore_nofocus.so +0 -0
  146. data/firefox/prebuilt/linux64/Release/libwebdriver-firefox.so +0 -0
  147. data/firefox/prebuilt/linux64/Release/x_ignore_nofocus.so +0 -0
  148. data/firefox/prebuilt/nsICommandProcessor.xpt +0 -0
  149. data/firefox/prebuilt/nsINativeEvents.xpt +0 -0
  150. data/firefox/prebuilt/nsIResponseHandler.xpt +0 -0
  151. data/firefox/src/extension/chrome.manifest +3 -0
  152. data/firefox/src/extension/components/badCertListener.js +294 -0
  153. data/firefox/src/extension/components/context.js +37 -0
  154. data/firefox/src/extension/components/driver-component.js +127 -0
  155. data/firefox/src/extension/components/firefoxDriver.js +810 -0
  156. data/firefox/src/extension/components/json2.js +273 -0
  157. data/firefox/src/extension/components/keytest.html +554 -0
  158. data/firefox/src/extension/components/nsCommandProcessor.js +643 -0
  159. data/firefox/src/extension/components/promptService.js +208 -0
  160. data/firefox/src/extension/components/screenshooter.js +81 -0
  161. data/firefox/src/extension/components/socketListener.js +185 -0
  162. data/firefox/src/extension/components/utils.js +1263 -0
  163. data/firefox/src/extension/components/webLoadingListener.js +57 -0
  164. data/firefox/src/extension/components/webdriverserver.js +106 -0
  165. data/firefox/src/extension/components/wrappedElement.js +683 -0
  166. data/firefox/src/extension/content/fxdriver.xul +30 -0
  167. data/firefox/src/extension/content/server.js +95 -0
  168. data/firefox/src/extension/idl/nsICommandProcessor.idl +38 -0
  169. data/firefox/src/extension/idl/nsIResponseHandler.idl +34 -0
  170. data/firefox/src/extension/install.rdf +29 -0
  171. data/firefox/src/rb/lib/selenium/webdriver/firefox.rb +31 -0
  172. data/firefox/src/rb/lib/selenium/webdriver/firefox/binary.rb +107 -0
  173. data/firefox/src/rb/lib/selenium/webdriver/firefox/bridge.rb +484 -0
  174. data/firefox/src/rb/lib/selenium/webdriver/firefox/extension_connection.rb +90 -0
  175. data/firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb +155 -0
  176. data/firefox/src/rb/lib/selenium/webdriver/firefox/profile.rb +233 -0
  177. data/firefox/src/rb/lib/selenium/webdriver/firefox/profiles_ini.rb +59 -0
  178. data/firefox/src/rb/lib/selenium/webdriver/firefox/util.rb +23 -0
  179. data/jobbie/prebuilt/Win32/Release/InternetExplorerDriver.dll +0 -0
  180. data/jobbie/prebuilt/x64/Release/InternetExplorerDriver.dll +0 -0
  181. data/jobbie/src/rb/lib/selenium/webdriver/ie.rb +14 -0
  182. data/jobbie/src/rb/lib/selenium/webdriver/ie/bridge.rb +565 -0
  183. data/jobbie/src/rb/lib/selenium/webdriver/ie/lib.rb +99 -0
  184. data/jobbie/src/rb/lib/selenium/webdriver/ie/util.rb +147 -0
  185. data/remote/client/src/rb/lib/selenium/webdriver/remote.rb +16 -0
  186. data/remote/client/src/rb/lib/selenium/webdriver/remote/bridge.rb +408 -0
  187. data/remote/client/src/rb/lib/selenium/webdriver/remote/capabilities.rb +105 -0
  188. data/remote/client/src/rb/lib/selenium/webdriver/remote/commands.rb +53 -0
  189. data/remote/client/src/rb/lib/selenium/webdriver/remote/default_http_client.rb +71 -0
  190. data/remote/client/src/rb/lib/selenium/webdriver/remote/response.rb +49 -0
  191. data/remote/client/src/rb/lib/selenium/webdriver/remote/server_error.rb +32 -0
  192. metadata +303 -0
@@ -0,0 +1,99 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module IE
4
+ module Lib
5
+ extend FFI::Library
6
+
7
+ ffi_lib WebDriver::IE::DLL
8
+
9
+ attach_function :wdAddBooleanScriptArg, [:pointer, :int ], :int
10
+ attach_function :wdAddCookie, [:pointer, :pointer ], :int
11
+ attach_function :wdAddDoubleScriptArg, [:pointer, :double ], :int
12
+ attach_function :wdAddElementScriptArg, [:pointer, :pointer ], :int
13
+ attach_function :wdAddNumberScriptArg, [:pointer, :long ], :int
14
+ attach_function :wdAddStringScriptArg, [:pointer, :pointer ], :int
15
+ attach_function :wdcGetElementAtIndex, [:pointer, :int, :pointer ], :int
16
+ attach_function :wdcGetElementCollectionLength, [:pointer, :pointer ], :int
17
+ attach_function :wdcGetStringAtIndex, [:pointer, :int, :pointer ], :int
18
+ attach_function :wdcGetStringCollectionLength, [:pointer, :pointer ], :int
19
+ attach_function :wdClose, [:pointer ], :int
20
+ attach_function :wdCopyString, [:pointer, :int, :pointer ], :int
21
+ attach_function :wdeClear, [:pointer ], :int
22
+ attach_function :wdeClick, [:pointer ], :int
23
+ attach_function :wdeGetAttribute, [:pointer, :pointer, :pointer ], :int
24
+ attach_function :wdeGetDetailsOnceScrolledOnToScreen, [:pointer, :pointer, :pointer, :pointer, :pointer, :pointer ], :int
25
+ attach_function :wdeGetLocation, [:pointer, :pointer, :pointer ], :int
26
+ attach_function :wdeGetSize, [:pointer, :pointer, :pointer ], :int
27
+ attach_function :wdeGetTagName, [:pointer, :pointer ], :int
28
+ attach_function :wdeGetText, [:pointer, :pointer ], :int
29
+ attach_function :wdeGetValueOfCssProperty, [:pointer, :pointer, :pointer ], :int
30
+ attach_function :wdeIsDisplayed, [:pointer, :pointer ], :int
31
+ attach_function :wdeIsEnabled, [:pointer, :pointer ], :int
32
+ attach_function :wdeIsSelected, [:pointer, :pointer ], :int
33
+ attach_function :wdeMouseDownAt, [:pointer, :long, :long ], :int #hwnd, nativelong
34
+ attach_function :wdeMouseMoveTo, [:pointer, :long, :long, :long, :long, :long ], :int # hwnd, 5x nativelong
35
+ attach_function :wdeMouseUpAt, [:pointer, :long, :long ], :int # hwnd
36
+ attach_function :wdeSendKeys, [:pointer, :pointer ], :int
37
+ attach_function :wdeSetSelected, [:pointer ], :int
38
+ attach_function :wdeSubmit, [:pointer ], :int
39
+ attach_function :wdeToggle, [:pointer, :pointer ], :int
40
+ attach_function :wdExecuteScript, [:pointer, :pointer, :pointer, :pointer ], :int
41
+ attach_function :wdeFreeElement, [:pointer ], :int
42
+ attach_function :wdFindElementByClassName, [:pointer, :pointer, :pointer, :pointer ], :int
43
+ attach_function :wdFindElementById, [:pointer, :pointer, :pointer, :pointer ], :int
44
+ attach_function :wdFindElementByLinkText, [:pointer, :pointer, :pointer, :pointer ], :int
45
+ attach_function :wdFindElementByName, [:pointer, :pointer, :pointer, :pointer ], :int
46
+ attach_function :wdFindElementByPartialLinkText, [:pointer, :pointer, :pointer, :pointer ], :int
47
+ attach_function :wdFindElementByTagName, [:pointer, :pointer, :pointer, :pointer ], :int
48
+ attach_function :wdFindElementByXPath, [:pointer, :pointer, :pointer, :pointer ], :int
49
+ attach_function :wdFindElementsByClassName, [:pointer, :pointer, :pointer, :pointer ], :int
50
+ attach_function :wdFindElementsById, [:pointer, :pointer, :pointer, :pointer ], :int
51
+ attach_function :wdFindElementsByLinkText, [:pointer, :pointer, :pointer, :pointer ], :int
52
+ attach_function :wdFindElementsByName, [:pointer, :pointer, :pointer, :pointer ], :int
53
+ attach_function :wdFindElementsByPartialLinkText, [:pointer, :pointer, :pointer, :pointer ], :int
54
+ attach_function :wdFindElementsByTagName, [:pointer, :pointer, :pointer, :pointer ], :int
55
+ attach_function :wdFindElementsByXPath, [:pointer, :pointer, :pointer, :pointer ], :int
56
+ attach_function :wdFreeDriver, [:pointer ], :int
57
+ attach_function :wdFreeElementCollection, [:pointer, :int ], :int
58
+ attach_function :wdFreeScriptArgs, [:pointer ], :int
59
+ attach_function :wdFreeScriptResult, [:pointer ], :int
60
+ attach_function :wdFreeString, [:pointer ], :int
61
+ attach_function :wdFreeStringCollection, [:pointer ], :int
62
+ attach_function :wdGet, [:pointer, :pointer ], :int
63
+ attach_function :wdGetAllWindowHandles, [:pointer, :pointer ], :int
64
+ attach_function :wdGetBooleanScriptResult, [:pointer, :pointer ], :int
65
+ attach_function :wdGetCookies, [:pointer, :pointer ], :int
66
+ attach_function :wdGetCurrentUrl, [:pointer, :pointer ], :int
67
+ attach_function :wdGetCurrentWindowHandle, [:pointer, :pointer ], :int
68
+ attach_function :wdGetDoubleScriptResult, [:pointer, :pointer ], :int
69
+ attach_function :wdGetElementScriptResult, [:pointer, :pointer, :pointer ], :int
70
+ attach_function :wdGetNumberScriptResult, [:pointer, :pointer ], :int
71
+ attach_function :wdGetPageSource, [:pointer, :pointer ], :int
72
+ attach_function :wdGetScriptResultType, [:pointer, :pointer ], :int
73
+ attach_function :wdGetStringScriptResult, [:pointer, :pointer ], :int
74
+ attach_function :wdGetTitle, [:pointer, :pointer ], :int
75
+ attach_function :wdGetVisible, [:pointer, :pointer ], :int
76
+ attach_function :wdGoBack, [:pointer ], :int
77
+ attach_function :wdGoForward, [:pointer ], :int
78
+ attach_function :wdNewDriverInstance, [:pointer ], :int
79
+ attach_function :wdNewScriptArgs, [:pointer, :int ], :int
80
+ attach_function :wdRefresh, [:pointer, ], :int
81
+ attach_function :wdSetVisible, [:pointer, :int ], :int
82
+ attach_function :wdStringLength, [:pointer, :pointer ], :int
83
+ attach_function :wdSwitchToActiveElement, [:pointer, :pointer ], :int
84
+ attach_function :wdSwitchToFrame, [:pointer, :pointer ], :int
85
+ attach_function :wdSwitchToWindow, [:pointer, :pointer ], :int
86
+ attach_function :wdWaitForLoadToComplete, [:pointer ], :int
87
+ end
88
+
89
+ module Kernel32
90
+ extend FFI::Library
91
+
92
+ ffi_lib "kernel32.dll"
93
+
94
+ attach_function :MultiByteToWideChar, [:int, :long, :pointer, :int, :pointer, :int ], :int
95
+ attach_function :WideCharToMultiByte, [:int, :long, :pointer, :int, :pointer, :int, :pointer, :pointer], :int
96
+ end
97
+ end # IE
98
+ end # WebDriver
99
+ end # Selenium
@@ -0,0 +1,147 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module IE
4
+ module Util
5
+ CP_ACP = 0
6
+ CP_OEMCP = 1
7
+ CP_MACCP = 2
8
+ CP_THREAD_ACP = 3
9
+ CP_SYMBOL = 42
10
+ CP_UTF7 = 65000
11
+ CP_UTF8 = 65001
12
+
13
+ def string_array_from(raw_strings)
14
+ strings_ptr = raw_strings.get_pointer(0)
15
+ length_ptr = FFI::MemoryPointer.new :int
16
+ result = Lib.wdcGetStringCollectionLength(strings_ptr, length_ptr)
17
+
18
+ if result != 0
19
+ raise Error::WebDriverError, "cannot extract strings from collection, error code: #{result.inspect}"
20
+ end
21
+
22
+ arr = []
23
+
24
+ length_ptr.get_int(0).times do |idx|
25
+ str_ptr_ref = FFI::MemoryPointer.new :pointer
26
+ result = Lib.wdcGetStringAtIndex(strings_ptr, idx, str_ptr_ref)
27
+
28
+ if result != 0
29
+ raise Error::WebDriverError, "unable to get string at index: #{idx}, error: #{result}"
30
+ end
31
+
32
+ arr << extract_string_from(str_ptr_ref)
33
+ end
34
+
35
+ arr
36
+ ensure
37
+ Lib.wdFreeStringCollection(strings_ptr)
38
+ raw_strings.free
39
+ end
40
+
41
+ def create_element(&blk)
42
+ element_ptr_ref = FFI::MemoryPointer.new :pointer
43
+ yield element_ptr_ref
44
+ Element.new(self, element_ptr_ref.get_pointer(0))
45
+ ensure
46
+ element_ptr_ref.free
47
+ end
48
+
49
+ def create_element_collection(&blk)
50
+ elements_ptr_ref = FFI::MemoryPointer.new :pointer
51
+ yield elements_ptr_ref
52
+
53
+ extract_elements_from elements_ptr_ref
54
+ end
55
+
56
+ def create_string(&blk)
57
+ wrapper = FFI::MemoryPointer.new :pointer
58
+ yield wrapper
59
+
60
+ extract_string_from wrapper
61
+ end
62
+
63
+ def extract_string_from(string_ptr_ref)
64
+ string_ptr = string_ptr_ref.get_pointer(0)
65
+ return if string_ptr.null? # getElementAttribute()
66
+
67
+ length_ptr = FFI::MemoryPointer.new :int
68
+
69
+ if Lib.wdStringLength(string_ptr, length_ptr) != 0
70
+ raise Error::WebDriverError, "cannot determine length of string"
71
+ end
72
+
73
+ length = length_ptr.get_int(0)
74
+ raw_string = wstring_ptr(" "*length)
75
+
76
+ if Lib.wdCopyString(string_ptr, length, raw_string) != 0
77
+ raise Error::WebDriverError, "cannot copy string from native data to Ruby string"
78
+ end
79
+
80
+ wstring_to_bytestring raw_string
81
+ ensure
82
+ Lib.wdFreeString(string_ptr) unless string_ptr.null?
83
+ string_ptr_ref.free
84
+ end
85
+
86
+ def extract_elements_from(elements_ptr_ref)
87
+ elements_ptr = elements_ptr_ref.get_pointer(0)
88
+ length_ptr = FFI::MemoryPointer.new :int
89
+
90
+ check_error_code Lib.wdcGetElementCollectionLength(elements_ptr, length_ptr),
91
+ "Cannot extract elements from collection"
92
+
93
+ arr = []
94
+
95
+ length_ptr.get_int(0).times do |idx|
96
+ arr << create_element do |ptr|
97
+ result = Lib.wdcGetElementAtIndex(elements_ptr, idx, ptr)
98
+
99
+ if e = WebDriver::Error.for_code(result)
100
+ Lib.wdFreeElementCollection(elements_ptr, 1)
101
+ raise e, "unable to create element from collection at index #{idx} (#{result})"
102
+ end
103
+ end
104
+ end
105
+
106
+ Lib.wdFreeElementCollection(elements_ptr, 0)
107
+
108
+ arr
109
+ ensure
110
+ elements_ptr_ref.free
111
+ length_ptr.free
112
+ end
113
+
114
+
115
+ def wstring_ptr(str)
116
+ str = str.to_s
117
+ size = Kernel32.MultiByteToWideChar(CP_UTF8, 0, str, -1, nil, 0)
118
+
119
+ unless size > 0
120
+ raise Error::WebDriverError, "unable to convert #{str.inspect} to wchar ptr"
121
+ end
122
+
123
+ buf = FFI::MemoryPointer.new :pointer, size
124
+ Kernel32.MultiByteToWideChar(CP_UTF8, 0, str, -1, buf, size)
125
+
126
+ buf
127
+ end
128
+
129
+ def wstring_to_bytestring(wstring)
130
+ size = Kernel32.WideCharToMultiByte(CP_UTF8, 0, wstring, -1, nil, 0, nil, nil)
131
+
132
+ unless size > 0
133
+ raise Error::WebDriverError, "could not convert wstring pointer to bytestring"
134
+ end
135
+
136
+ buf = FFI::MemoryPointer.new :pointer, size
137
+ Kernel32.WideCharToMultiByte(CP_UTF8, 0, wstring, -1, buf, size, nil, nil )
138
+
139
+ buf.get_bytes(0, size - 1)
140
+ ensure
141
+ buf.free if buf
142
+ end
143
+
144
+ end # Util
145
+ end # IE
146
+ end # WebDriver
147
+ end # Selenium
@@ -0,0 +1,16 @@
1
+ require "selenium/webdriver/remote/capabilities"
2
+ require "selenium/webdriver/remote/default_http_client"
3
+ require "selenium/webdriver/remote/bridge"
4
+ require "selenium/webdriver/remote/server_error"
5
+ require "selenium/webdriver/remote/response"
6
+ require "selenium/webdriver/remote/commands"
7
+
8
+ module Selenium
9
+ module WebDriver
10
+ module Remote
11
+
12
+ end
13
+ end
14
+ end
15
+
16
+ require "uri"
@@ -0,0 +1,408 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module Remote
4
+
5
+ COMMANDS = {}
6
+
7
+ #
8
+ # Low level bridge to the remote server, through which the rest of the API works.
9
+ #
10
+ # @api private
11
+ #
12
+
13
+ class Bridge
14
+ include Find
15
+ include BridgeHelper
16
+
17
+ DEFAULT_OPTIONS = {
18
+ :url => "http://localhost:4444/wd/hub",
19
+ :http_client => DefaultHttpClient,
20
+ :desired_capabilities => Capabilities.firefox
21
+ }
22
+
23
+ #
24
+ # Defines a wrapper method for a command, which ultimately calls #execute.
25
+ #
26
+ # @param name [Symbol]
27
+ # name of the resulting method
28
+ # @param url [String]
29
+ # a URL template, which can include some arguments, much like the definitions on the server.
30
+ # the :session_id and :context parameters are implicitly handled, but the remainder will become
31
+ # required method arguments.
32
+ # e.g., "session/:session_id/:context/element/:id/text" will define a method that takes id
33
+ # as it's first argument.
34
+ # @param verb [Symbol]
35
+ # the appropriate http verb, such as :get, :post, or :delete
36
+ #
37
+
38
+ def self.command(name, verb, url)
39
+ COMMANDS[name] = [verb, url.freeze]
40
+ end
41
+
42
+ attr_accessor :context, :http
43
+ attr_reader :capabilities
44
+
45
+ #
46
+ # Initializes the bridge with the given server URL.
47
+ #
48
+ # @param url [String] url for the remote server
49
+ # @param http_client [Class] an HTTP client class that implements the same interface as DefaultHttpClient
50
+ # @param desired_capabilities [Capabilities] an instance of Remote::Capabilities describing the capabilities you want
51
+ #
52
+
53
+ def initialize(opts = {})
54
+ opts = DEFAULT_OPTIONS.merge(opts)
55
+ http_client_class = opts.delete(:http_client)
56
+ desired_capabilities = opts.delete(:desired_capabilities)
57
+ url = opts.delete(:url)
58
+
59
+ unless opts.empty?
60
+ raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
61
+ end
62
+
63
+ if desired_capabilities.kind_of?(Symbol)
64
+ unless Capabilities.respond_to?(desired_capabilities)
65
+ raise Error::WebDriverError, "invalid desired capability: #{desired_capabilities.inspect}"
66
+ end
67
+
68
+ desired_capabilities = Capabilities.send(desired_capabilities)
69
+ end
70
+
71
+ uri = URI.parse(url)
72
+ uri.path += "/" unless uri.path =~ /\/$/
73
+
74
+ @context = "context"
75
+ @http = http_client_class.new uri
76
+ @capabilities = create_session(desired_capabilities)
77
+ end
78
+
79
+ def browser
80
+ @browser ||= @capabilities.browser_name.gsub(" ", "_").to_sym
81
+ end
82
+
83
+ def driver_extensions
84
+ []
85
+ end
86
+
87
+ #
88
+ # Returns the current session ID.
89
+ #
90
+
91
+ def session_id
92
+ @session_id || raise(Error::WebDriverError, "no current session exists")
93
+ end
94
+
95
+
96
+ def create_session(desired_capabilities)
97
+ resp = raw_execute :newSession, {}, desired_capabilities
98
+ @session_id = resp['sessionId'] || raise(Error::WebDriverError, 'no sessionId in returned payload')
99
+ @context = resp['context']
100
+
101
+ Capabilities.json_create resp['value']
102
+ end
103
+
104
+ def get(url)
105
+ execute :get, {}, url
106
+ end
107
+
108
+ def goBack
109
+ execute :goBack
110
+ end
111
+
112
+ def goForward
113
+ execute :goForward
114
+ end
115
+
116
+ def getCurrentUrl
117
+ execute :getCurrentUrl
118
+ end
119
+
120
+ def getTitle
121
+ execute :getTitle
122
+ end
123
+
124
+ def getPageSource
125
+ execute :getPageSource
126
+ end
127
+
128
+ def getVisible
129
+ execute :getVisible
130
+ end
131
+
132
+ def setVisible(bool)
133
+ execute :setVisible, {}, bool
134
+ end
135
+
136
+ def switchToWindow(name)
137
+ execute :switchToWindow, :name => name
138
+ end
139
+
140
+ def switchToFrame(id)
141
+ execute :switchToFrame, :id => id
142
+ end
143
+
144
+ def switchToDefaultContent
145
+ execute :switchToFrame, :id => nil
146
+ end
147
+
148
+ def quit
149
+ execute :quit
150
+ end
151
+
152
+ def close
153
+ execute :close
154
+ end
155
+
156
+ def refresh
157
+ execute :refresh
158
+ end
159
+
160
+ def getWindowHandles
161
+ execute :getWindowHandles
162
+ end
163
+
164
+ def getCurrentWindowHandle
165
+ execute :getCurrentWindowHandle
166
+ end
167
+
168
+ def setSpeed(value)
169
+ execute :setSpeed, {}, value
170
+ end
171
+
172
+ def getSpeed
173
+ execute :getSpeed
174
+ end
175
+
176
+ def executeScript(script, *args)
177
+ unless capabilities.javascript?
178
+ raise Error::UnsupportedOperationError, "underlying webdriver instance does not support javascript"
179
+ end
180
+
181
+ typed_args = args.map { |arg| wrap_script_argument(arg) }
182
+ response = raw_execute :executeScript, {}, script, typed_args
183
+
184
+ unwrap_script_argument response['value']
185
+ end
186
+
187
+ def addCookie(cookie)
188
+ execute :addCookie, {}, cookie
189
+ end
190
+
191
+ def deleteCookie(name)
192
+ execute :deleteCookie, :name => name
193
+ end
194
+
195
+ def getAllCookies
196
+ execute :getAllCookies
197
+ end
198
+
199
+ def deleteAllCookies
200
+ execute :deleteAllCookies
201
+ end
202
+
203
+ def findElementByClassName(parent, class_name)
204
+ find_element_by 'class name', class_name, parent
205
+ end
206
+
207
+ def findElementsByClassName(parent, class_name)
208
+ find_elements_by 'class name', class_name, parent
209
+ end
210
+
211
+ def findElementById(parent, id)
212
+ find_element_by 'id', id, parent
213
+ end
214
+
215
+ def findElementsById(parent, id)
216
+ find_elements_by 'id', id, parent
217
+ end
218
+
219
+ def findElementByLinkText(parent, link_text)
220
+ find_element_by 'link text', link_text, parent
221
+ end
222
+
223
+ def findElementsByLinkText(parent, link_text)
224
+ find_elements_by 'link text', link_text, parent
225
+ end
226
+
227
+ def findElementByPartialLinkText(parent, link_text)
228
+ find_element_by 'partial link text', link_text, parent
229
+ end
230
+
231
+ def findElementsByPartialLinkText(parent, link_text)
232
+ find_elements_by 'partial link text', link_text, parent
233
+ end
234
+
235
+ def findElementByName(parent, name)
236
+ find_element_by 'name', name, parent
237
+ end
238
+
239
+ def findElementsByName(parent, name)
240
+ find_elements_by 'name', name, parent
241
+ end
242
+
243
+ def findElementByTagName(parent, tag_name)
244
+ find_element_by 'tag name', tag_name, parent
245
+ end
246
+
247
+ def findElementsByTagName(parent, tag_name)
248
+ find_elements_by 'tag name', tag_name, parent
249
+ end
250
+
251
+ def findElementByXpath(parent, xpath)
252
+ find_element_by 'xpath', xpath, parent
253
+ end
254
+
255
+ def findElementsByXpath(parent, xpath)
256
+ find_elements_by 'xpath', xpath, parent
257
+ end
258
+
259
+
260
+ #
261
+ # Element functions
262
+ #
263
+
264
+ def clickElement(element)
265
+ execute :clickElement, :id => element
266
+ end
267
+
268
+ def getElementTagName(element)
269
+ execute :getElementTagName, :id => element
270
+ end
271
+
272
+ def getElementAttribute(element, name)
273
+ execute :getElementAttribute, :id => element, :name => name
274
+ end
275
+
276
+ def getElementValue(element)
277
+ execute :getElementValue, :id => element
278
+ end
279
+
280
+ def getElementText(element)
281
+ execute :getElementText, :id => element
282
+ end
283
+
284
+ def getElementLocation(element)
285
+ data = execute :getElementLocation, :id => element
286
+
287
+ Point.new data['x'], data['y']
288
+ end
289
+
290
+ def getElementSize(element)
291
+ data = execute :getElementSize, :id => element
292
+
293
+ Dimension.new data['width'], data['height']
294
+ end
295
+
296
+ def sendKeysToElement(element, string)
297
+ execute :sendKeysToElement, {:id => element}, {:value => string.split(//u)}
298
+ end
299
+
300
+ def clearElement(element)
301
+ execute :clearElement, :id => element
302
+ end
303
+
304
+ def isElementEnabled(element)
305
+ execute :isElementEnabled, :id => element
306
+ end
307
+
308
+ def isElementSelected(element)
309
+ execute :isElementSelected, :id => element
310
+ end
311
+
312
+ def isElementDisplayed(element)
313
+ execute :isElementDisplayed, :id => element
314
+ end
315
+
316
+ def submitElement(element)
317
+ execute :submitElement, :id => element
318
+ end
319
+
320
+ def toggleElement(element)
321
+ execute :toggleElement, :id => element
322
+ end
323
+
324
+ def setElementSelected(element)
325
+ execute :setElementSelected, :id => element
326
+ end
327
+
328
+ def getElementValueOfCssProperty(element, prop)
329
+ execute :getElementValueOfCssProperty, :id => element, :property_name => prop
330
+ end
331
+
332
+ def getActiveElement
333
+ Element.new self, element_id_from(execute(:getActiveElement))
334
+ end
335
+ alias_method :switchToActiveElement, :getActiveElement
336
+
337
+ def hoverOverElement(element)
338
+ execute :hoverOverElement, :id => element
339
+ end
340
+
341
+ def dragElement(element, rigth_by, down_by)
342
+ # TODO: why is element sent twice in the payload?
343
+ execute :dragElement, {:id => element}, element, rigth_by, down_by
344
+ end
345
+
346
+ private
347
+
348
+ def find_element_by(how, what, parent = nil)
349
+ if parent
350
+ # TODO: why is how sent twice in the payload?
351
+ id = execute :findChildElement, {:id => parent, :using => how}, {:using => how, :value => what}
352
+ else
353
+ id = execute :findElement, {}, how, what
354
+ end
355
+
356
+ Element.new self, element_id_from(id)
357
+ end
358
+
359
+ def find_elements_by(how, what, parent = nil)
360
+ if parent
361
+ # TODO: why is how sent twice in the payload?
362
+ ids = execute :findChildElements, {:id => parent, :using => how}, {:using => how, :value => what}
363
+ else
364
+ ids = execute :findElements, {}, how, what
365
+ end
366
+
367
+ ids.map { |id| Element.new self, element_id_from(id) }
368
+ end
369
+
370
+
371
+ #
372
+ # executes a command on the remote server via the REST / JSON API.
373
+ #
374
+ #
375
+ # Returns the 'value' of the returned payload
376
+ #
377
+
378
+ def execute(*args)
379
+ raw_execute(*args)['value']
380
+ end
381
+
382
+ #
383
+ # executes a command on the remote server via the REST / JSON API.
384
+ #
385
+ # Returns a WebDriver::Remote::Response instance
386
+ #
387
+
388
+ def raw_execute(command, opts = {}, *args)
389
+ verb, path = COMMANDS[command] || raise("unknown command #{command.inspect}")
390
+ path = path.dup
391
+
392
+ path[':session_id'] = @session_id if path.include?(":session_id")
393
+ path[':context'] = @context if path.include?(":context")
394
+
395
+ begin
396
+ opts.each { |key, value| path[key.inspect] = URI.escape(value.to_s) }
397
+ rescue IndexError
398
+ raise ArgumentError, "#{opts.inspect} invalid for #{command.inspect}"
399
+ end
400
+
401
+ puts "-> #{verb.to_s.upcase} #{path}" if $DEBUG
402
+ http.call verb, path, *args
403
+ end
404
+
405
+ end # Bridge
406
+ end # Remote
407
+ end # WebDriver
408
+ end # Selenium