browserstack-webdriver 0.0.1

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 (202) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES +791 -0
  3. data/README.md +31 -0
  4. data/build.desc +334 -0
  5. data/lib/selenium-client.rb +2 -0
  6. data/lib/selenium-webdriver.rb +1 -0
  7. data/lib/selenium/client.rb +37 -0
  8. data/lib/selenium/client/base.rb +132 -0
  9. data/lib/selenium/client/driver.rb +10 -0
  10. data/lib/selenium/client/errors.rb +9 -0
  11. data/lib/selenium/client/extensions.rb +118 -0
  12. data/lib/selenium/client/idiomatic.rb +488 -0
  13. data/lib/selenium/client/javascript_expression_builder.rb +116 -0
  14. data/lib/selenium/client/javascript_frameworks/jquery.rb +13 -0
  15. data/lib/selenium/client/javascript_frameworks/prototype.rb +13 -0
  16. data/lib/selenium/client/legacy_driver.rb +1720 -0
  17. data/lib/selenium/client/protocol.rb +104 -0
  18. data/lib/selenium/client/selenium_helper.rb +34 -0
  19. data/lib/selenium/rake/server_task.rb +157 -0
  20. data/lib/selenium/server.rb +248 -0
  21. data/lib/selenium/webdriver.rb +71 -0
  22. data/lib/selenium/webdriver/android.rb +9 -0
  23. data/lib/selenium/webdriver/android/bridge.rb +47 -0
  24. data/lib/selenium/webdriver/chrome.rb +26 -0
  25. data/lib/selenium/webdriver/chrome/bridge.rb +120 -0
  26. data/lib/selenium/webdriver/chrome/profile.rb +90 -0
  27. data/lib/selenium/webdriver/chrome/service.rb +75 -0
  28. data/lib/selenium/webdriver/common.rb +44 -0
  29. data/lib/selenium/webdriver/common/action_builder.rb +352 -0
  30. data/lib/selenium/webdriver/common/alert.rb +30 -0
  31. data/lib/selenium/webdriver/common/bridge_helper.rb +67 -0
  32. data/lib/selenium/webdriver/common/core_ext/base64.rb +9 -0
  33. data/lib/selenium/webdriver/common/core_ext/dir.rb +42 -0
  34. data/lib/selenium/webdriver/common/core_ext/string.rb +5 -0
  35. data/lib/selenium/webdriver/common/driver.rb +301 -0
  36. data/lib/selenium/webdriver/common/driver_extensions/has_browser_connection.rb +17 -0
  37. data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +39 -0
  38. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +25 -0
  39. data/lib/selenium/webdriver/common/driver_extensions/has_remote_status.rb +13 -0
  40. data/lib/selenium/webdriver/common/driver_extensions/has_session_id.rb +22 -0
  41. data/lib/selenium/webdriver/common/driver_extensions/has_touch_screen.rb +19 -0
  42. data/lib/selenium/webdriver/common/driver_extensions/has_web_storage.rb +22 -0
  43. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +45 -0
  44. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +43 -0
  45. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +46 -0
  46. data/lib/selenium/webdriver/common/element.rb +293 -0
  47. data/lib/selenium/webdriver/common/error.rb +207 -0
  48. data/lib/selenium/webdriver/common/file_reaper.rb +47 -0
  49. data/lib/selenium/webdriver/common/html5/local_storage.rb +42 -0
  50. data/lib/selenium/webdriver/common/html5/location.rb +0 -0
  51. data/lib/selenium/webdriver/common/html5/session_storage.rb +44 -0
  52. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +42 -0
  53. data/lib/selenium/webdriver/common/json_helper.rb +34 -0
  54. data/lib/selenium/webdriver/common/keyboard.rb +55 -0
  55. data/lib/selenium/webdriver/common/keys.rb +109 -0
  56. data/lib/selenium/webdriver/common/log_entry.rb +29 -0
  57. data/lib/selenium/webdriver/common/logs.rb +23 -0
  58. data/lib/selenium/webdriver/common/mouse.rb +72 -0
  59. data/lib/selenium/webdriver/common/navigation.rb +43 -0
  60. data/lib/selenium/webdriver/common/options.rb +136 -0
  61. data/lib/selenium/webdriver/common/platform.rb +218 -0
  62. data/lib/selenium/webdriver/common/port_prober.rb +42 -0
  63. data/lib/selenium/webdriver/common/profile_helper.rb +67 -0
  64. data/lib/selenium/webdriver/common/proxy.rb +149 -0
  65. data/lib/selenium/webdriver/common/search_context.rb +92 -0
  66. data/lib/selenium/webdriver/common/socket_poller.rb +105 -0
  67. data/lib/selenium/webdriver/common/target_locator.rb +81 -0
  68. data/lib/selenium/webdriver/common/timeouts.rb +38 -0
  69. data/lib/selenium/webdriver/common/touch_action_builder.rb +64 -0
  70. data/lib/selenium/webdriver/common/touch_screen.rb +105 -0
  71. data/lib/selenium/webdriver/common/wait.rb +63 -0
  72. data/lib/selenium/webdriver/common/window.rb +104 -0
  73. data/lib/selenium/webdriver/common/zipper.rb +82 -0
  74. data/lib/selenium/webdriver/firefox.rb +37 -0
  75. data/lib/selenium/webdriver/firefox/binary.rb +158 -0
  76. data/lib/selenium/webdriver/firefox/bridge.rb +70 -0
  77. data/lib/selenium/webdriver/firefox/extension.rb +52 -0
  78. data/lib/selenium/webdriver/firefox/launcher.rb +106 -0
  79. data/lib/selenium/webdriver/firefox/profile.rb +263 -0
  80. data/lib/selenium/webdriver/firefox/profiles_ini.rb +62 -0
  81. data/lib/selenium/webdriver/firefox/socket_lock.rb +61 -0
  82. data/lib/selenium/webdriver/firefox/util.rb +29 -0
  83. data/lib/selenium/webdriver/ie.rb +19 -0
  84. data/lib/selenium/webdriver/ie/bridge.rb +68 -0
  85. data/lib/selenium/webdriver/ie/server.rb +86 -0
  86. data/lib/selenium/webdriver/iphone.rb +9 -0
  87. data/lib/selenium/webdriver/iphone/bridge.rb +45 -0
  88. data/lib/selenium/webdriver/opera.rb +24 -0
  89. data/lib/selenium/webdriver/opera/bridge.rb +112 -0
  90. data/lib/selenium/webdriver/opera/service.rb +49 -0
  91. data/lib/selenium/webdriver/phantomjs.rb +22 -0
  92. data/lib/selenium/webdriver/phantomjs/bridge.rb +59 -0
  93. data/lib/selenium/webdriver/phantomjs/service.rb +90 -0
  94. data/lib/selenium/webdriver/remote.rb +22 -0
  95. data/lib/selenium/webdriver/remote/bridge.rb +644 -0
  96. data/lib/selenium/webdriver/remote/capabilities.rb +267 -0
  97. data/lib/selenium/webdriver/remote/commands.rb +193 -0
  98. data/lib/selenium/webdriver/remote/http/common.rb +74 -0
  99. data/lib/selenium/webdriver/remote/http/curb.rb +79 -0
  100. data/lib/selenium/webdriver/remote/http/default.rb +139 -0
  101. data/lib/selenium/webdriver/remote/http/persistent.rb +38 -0
  102. data/lib/selenium/webdriver/remote/response.rb +97 -0
  103. data/lib/selenium/webdriver/remote/server_error.rb +17 -0
  104. data/lib/selenium/webdriver/safari.rb +46 -0
  105. data/lib/selenium/webdriver/safari/bridge.rb +110 -0
  106. data/lib/selenium/webdriver/safari/browser.rb +20 -0
  107. data/lib/selenium/webdriver/safari/extension.rb +120 -0
  108. data/lib/selenium/webdriver/safari/server.rb +145 -0
  109. data/lib/selenium/webdriver/support.rb +5 -0
  110. data/lib/selenium/webdriver/support/abstract_event_listener.rb +28 -0
  111. data/lib/selenium/webdriver/support/block_event_listener.rb +17 -0
  112. data/lib/selenium/webdriver/support/color.rb +110 -0
  113. data/lib/selenium/webdriver/support/event_firing_bridge.rb +112 -0
  114. data/lib/selenium/webdriver/support/select.rb +293 -0
  115. data/ruby.iml +13 -0
  116. data/spec/integration/selenium/client/api/backward_compatible_api_spec.rb +22 -0
  117. data/spec/integration/selenium/client/api/browser_xpath_library_spec.rb +17 -0
  118. data/spec/integration/selenium/client/api/click_spec.rb +39 -0
  119. data/spec/integration/selenium/client/api/cookie_spec.rb +39 -0
  120. data/spec/integration/selenium/client/api/element_spec.rb +14 -0
  121. data/spec/integration/selenium/client/api/highlight_located_element_spec.rb +19 -0
  122. data/spec/integration/selenium/client/api/retrieve_last_remote_control_logs_spec.rb +33 -0
  123. data/spec/integration/selenium/client/api/screenshot_spec.rb +31 -0
  124. data/spec/integration/selenium/client/api/select_window_spec.rb +46 -0
  125. data/spec/integration/selenium/client/api/start_stop_spec.rb +9 -0
  126. data/spec/integration/selenium/client/api/wait_for_ajax_spec.rb +27 -0
  127. data/spec/integration/selenium/client/api/wait_for_element_spec.rb +56 -0
  128. data/spec/integration/selenium/client/api/wait_for_field_value_spec.rb +52 -0
  129. data/spec/integration/selenium/client/api/wait_for_text_spec.rb +98 -0
  130. data/spec/integration/selenium/client/api/webdriver_backed_spec.rb +21 -0
  131. data/spec/integration/selenium/client/sample-app/public/jquery-1.3.2.js +4376 -0
  132. data/spec/integration/selenium/client/sample-app/public/jquery.html +55 -0
  133. data/spec/integration/selenium/client/sample-app/public/prototype-1.6.0.3.js +4320 -0
  134. data/spec/integration/selenium/client/sample-app/public/prototype.html +59 -0
  135. data/spec/integration/selenium/client/sample-app/sample_app.rb +32 -0
  136. data/spec/integration/selenium/client/spec_helper.rb +139 -0
  137. data/spec/integration/selenium/webdriver/app_cache_spec.rb +47 -0
  138. data/spec/integration/selenium/webdriver/browser_connection_spec.rb +20 -0
  139. data/spec/integration/selenium/webdriver/chrome/driver_spec.rb +28 -0
  140. data/spec/integration/selenium/webdriver/chrome/profile_spec.rb +63 -0
  141. data/spec/integration/selenium/webdriver/driver_spec.rb +266 -0
  142. data/spec/integration/selenium/webdriver/element_spec.rb +191 -0
  143. data/spec/integration/selenium/webdriver/error_spec.rb +30 -0
  144. data/spec/integration/selenium/webdriver/firefox/driver_spec.rb +21 -0
  145. data/spec/integration/selenium/webdriver/firefox/profile_spec.rb +141 -0
  146. data/spec/integration/selenium/webdriver/keyboard_spec.rb +57 -0
  147. data/spec/integration/selenium/webdriver/location_spec.rb +29 -0
  148. data/spec/integration/selenium/webdriver/mouse_spec.rb +57 -0
  149. data/spec/integration/selenium/webdriver/navigation_spec.rb +46 -0
  150. data/spec/integration/selenium/webdriver/opera/driver_spec.rb +47 -0
  151. data/spec/integration/selenium/webdriver/options_spec.rb +77 -0
  152. data/spec/integration/selenium/webdriver/remote/driver_spec.rb +19 -0
  153. data/spec/integration/selenium/webdriver/remote/element_spec.rb +26 -0
  154. data/spec/integration/selenium/webdriver/spec_helper.rb +36 -0
  155. data/spec/integration/selenium/webdriver/spec_support.rb +12 -0
  156. data/spec/integration/selenium/webdriver/spec_support/guards.rb +110 -0
  157. data/spec/integration/selenium/webdriver/spec_support/helpers.rb +51 -0
  158. data/spec/integration/selenium/webdriver/spec_support/rack_server.rb +123 -0
  159. data/spec/integration/selenium/webdriver/spec_support/test_environment.rb +239 -0
  160. data/spec/integration/selenium/webdriver/sql_database_spec.rb +59 -0
  161. data/spec/integration/selenium/webdriver/storage_spec.rb +96 -0
  162. data/spec/integration/selenium/webdriver/target_locator_spec.rb +186 -0
  163. data/spec/integration/selenium/webdriver/timeout_spec.rb +69 -0
  164. data/spec/integration/selenium/webdriver/touch_spec.rb +176 -0
  165. data/spec/integration/selenium/webdriver/window_spec.rb +70 -0
  166. data/spec/integration/selenium/webdriver/zipper_spec.rb +66 -0
  167. data/spec/unit/selenium/client/base_spec.rb +239 -0
  168. data/spec/unit/selenium/client/extensions_spec.rb +174 -0
  169. data/spec/unit/selenium/client/idiomatic_spec.rb +500 -0
  170. data/spec/unit/selenium/client/javascript_expression_builder_spec.rb +79 -0
  171. data/spec/unit/selenium/client/javascript_frameworks/jquery_spec.rb +10 -0
  172. data/spec/unit/selenium/client/javascript_frameworks/prototype_spec.rb +10 -0
  173. data/spec/unit/selenium/client/protocol_spec.rb +124 -0
  174. data/spec/unit/selenium/client/selenium_helper_spec.rb +56 -0
  175. data/spec/unit/selenium/client/spec_helper.rb +24 -0
  176. data/spec/unit/selenium/rake/task_spec.rb +79 -0
  177. data/spec/unit/selenium/server_spec.rb +150 -0
  178. data/spec/unit/selenium/webdriver/action_builder_spec.rb +97 -0
  179. data/spec/unit/selenium/webdriver/android/bridge_spec.rb +43 -0
  180. data/spec/unit/selenium/webdriver/chrome/bridge_spec.rb +137 -0
  181. data/spec/unit/selenium/webdriver/chrome/profile_spec.rb +57 -0
  182. data/spec/unit/selenium/webdriver/chrome/service_spec.rb +44 -0
  183. data/spec/unit/selenium/webdriver/error_spec.rb +41 -0
  184. data/spec/unit/selenium/webdriver/firefox/bridge_spec.rb +47 -0
  185. data/spec/unit/selenium/webdriver/ie/bridge_spec.rb +91 -0
  186. data/spec/unit/selenium/webdriver/iphone/bridge_spec.rb +42 -0
  187. data/spec/unit/selenium/webdriver/log_entry_spec.rb +11 -0
  188. data/spec/unit/selenium/webdriver/opera/bridge_spec.rb +44 -0
  189. data/spec/unit/selenium/webdriver/phantomjs/bridge_spec.rb +55 -0
  190. data/spec/unit/selenium/webdriver/proxy_spec.rb +106 -0
  191. data/spec/unit/selenium/webdriver/remote/bridge_spec.rb +16 -0
  192. data/spec/unit/selenium/webdriver/remote/capabilities_spec.rb +115 -0
  193. data/spec/unit/selenium/webdriver/remote/http/common_spec.rb +24 -0
  194. data/spec/unit/selenium/webdriver/remote/http/default_spec.rb +124 -0
  195. data/spec/unit/selenium/webdriver/search_context_spec.rb +61 -0
  196. data/spec/unit/selenium/webdriver/socket_poller_spec.rb +68 -0
  197. data/spec/unit/selenium/webdriver/spec_helper.rb +27 -0
  198. data/spec/unit/selenium/webdriver/support/color_spec.rb +119 -0
  199. data/spec/unit/selenium/webdriver/support/event_firing_spec.rb +111 -0
  200. data/spec/unit/selenium/webdriver/support/select_spec.rb +290 -0
  201. data/spec/unit/selenium/webdriver/wait_spec.rb +49 -0
  202. metadata +370 -0
@@ -0,0 +1,109 @@
1
+ # encoding: utf-8
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ module Keys
6
+
7
+ #
8
+ # @see Element#send_keys
9
+ # @see http://www.google.com.au/search?&q=unicode+pua&btnG=Search
10
+ #
11
+
12
+ KEYS = {
13
+ # \x works on both 1.8.6/1.9
14
+ :null => "\xEE\x80\x80",
15
+ :cancel => "\xEE\x80\x81",
16
+ :help => "\xEE\x80\x82",
17
+ :backspace => "\xEE\x80\x83",
18
+ :tab => "\xEE\x80\x84",
19
+ :clear => "\xEE\x80\x85",
20
+ :return => "\xEE\x80\x86",
21
+ :enter => "\xEE\x80\x87",
22
+ :shift => "\xEE\x80\x88",
23
+ :left_shift => "\xEE\x80\x88",
24
+ :control => "\xEE\x80\x89",
25
+ :left_control => "\xEE\x80\x89",
26
+ :alt => "\xEE\x80\x8A",
27
+ :left_alt => "\xEE\x80\x8A",
28
+ :pause => "\xEE\x80\x8B",
29
+ :escape => "\xEE\x80\x8C",
30
+ :space => "\xEE\x80\x8D",
31
+ :page_up => "\xEE\x80\x8E",
32
+ :page_down => "\xEE\x80\x8F",
33
+ :end => "\xEE\x80\x90",
34
+ :home => "\xEE\x80\x91",
35
+ :left => "\xEE\x80\x92",
36
+ :arrow_left => "\xEE\x80\x92",
37
+ :up => "\xEE\x80\x93",
38
+ :arrow_up => "\xEE\x80\x93",
39
+ :right => "\xEE\x80\x94",
40
+ :arrow_right => "\xEE\x80\x94",
41
+ :down => "\xEE\x80\x95",
42
+ :arrow_down => "\xEE\x80\x95",
43
+ :insert => "\xEE\x80\x96",
44
+ :delete => "\xEE\x80\x97",
45
+ :semicolon => "\xEE\x80\x98",
46
+ :equals => "\xEE\x80\x99",
47
+ :numpad0 => "\xEE\x80\x9A",
48
+ :numpad1 => "\xEE\x80\x9B",
49
+ :numpad2 => "\xEE\x80\x9C",
50
+ :numpad3 => "\xEE\x80\x9D",
51
+ :numpad4 => "\xEE\x80\x9E",
52
+ :numpad5 => "\xEE\x80\x9F",
53
+ :numpad6 => "\xEE\x80\xA0",
54
+ :numpad7 => "\xEE\x80\xA1",
55
+ :numpad8 => "\xEE\x80\xA2",
56
+ :numpad9 => "\xEE\x80\xA3",
57
+ :multiply => "\xEE\x80\xA4",
58
+ :add => "\xEE\x80\xA5",
59
+ :separator => "\xEE\x80\xA6",
60
+ :subtract => "\xEE\x80\xA7",
61
+ :decimal => "\xEE\x80\xA8",
62
+ :divide => "\xEE\x80\xA9",
63
+ :f1 => "\xEE\x80\xB1",
64
+ :f2 => "\xEE\x80\xB2",
65
+ :f3 => "\xEE\x80\xB3",
66
+ :f4 => "\xEE\x80\xB4",
67
+ :f5 => "\xEE\x80\xB5",
68
+ :f6 => "\xEE\x80\xB6",
69
+ :f7 => "\xEE\x80\xB7",
70
+ :f8 => "\xEE\x80\xB8",
71
+ :f9 => "\xEE\x80\xB9",
72
+ :f10 => "\xEE\x80\xBA",
73
+ :f11 => "\xEE\x80\xBB",
74
+ :f12 => "\xEE\x80\xBC",
75
+ :meta => "\xEE\x80\xBD",
76
+ :command => "\xEE\x80\xBD" # alias
77
+ }
78
+
79
+ #
80
+ # @api private
81
+ #
82
+
83
+ def self.[](key)
84
+ KEYS[key] or raise Error::UnsupportedOperationError, "no such key #{key.inspect}"
85
+ end
86
+
87
+ #
88
+ # @api private
89
+ #
90
+
91
+ def self.encode(keys)
92
+ keys.map do |arg|
93
+ case arg
94
+ when Symbol
95
+ Keys[arg]
96
+ when Array
97
+ arg = arg.map { |e| e.kind_of?(Symbol) ? Keys[e] : e }.join
98
+ arg << Keys[:null]
99
+
100
+ arg
101
+ else
102
+ arg.to_s
103
+ end
104
+ end
105
+ end
106
+
107
+ end # Keys
108
+ end # WebDriver
109
+ end # Selenium
@@ -0,0 +1,29 @@
1
+ module Selenium
2
+ module WebDriver
3
+ class LogEntry
4
+ attr_reader :level, :timestamp, :message
5
+
6
+ def initialize(level, timestamp, message)
7
+ @level = level
8
+ @timestamp = timestamp
9
+ @message = message
10
+ end
11
+
12
+ def as_json(opts = nil)
13
+ {
14
+ 'level' => level,
15
+ 'timestamp' => timestamp,
16
+ 'message' => message
17
+ }
18
+ end
19
+
20
+ def to_s
21
+ "#{level} #{time}: #{message}"
22
+ end
23
+
24
+ def time
25
+ Time.at timestamp / 1000
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ module Selenium
2
+ module WebDriver
3
+ class Logs
4
+
5
+ #
6
+ # @api private
7
+ #
8
+
9
+ def initialize(bridge)
10
+ @bridge = bridge
11
+ end
12
+
13
+ def get(type)
14
+ @bridge.getLog type
15
+ end
16
+
17
+ def available_types
18
+ @bridge.getAvailableLogTypes
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,72 @@
1
+ module Selenium
2
+ module WebDriver
3
+
4
+ #
5
+ # @api private
6
+ # @see ActionBuilder
7
+ #
8
+
9
+ class Mouse
10
+
11
+ def initialize(bridge)
12
+ @bridge = bridge
13
+ end
14
+
15
+ def click(element = nil)
16
+ move_if_needed element
17
+ @bridge.click
18
+ end
19
+
20
+ def double_click(element = nil)
21
+ move_if_needed element
22
+ @bridge.doubleClick
23
+ end
24
+
25
+ def context_click(element = nil)
26
+ move_if_needed element
27
+ @bridge.contextClick
28
+ end
29
+
30
+ def down(element = nil)
31
+ move_if_needed element
32
+ @bridge.mouseDown
33
+ end
34
+
35
+ def up(element = nil)
36
+ move_if_needed element
37
+ @bridge.mouseUp
38
+ end
39
+
40
+ #
41
+ # Move the mouse.
42
+ #
43
+ # Examples:
44
+ #
45
+ # driver.mouse.move_to(element)
46
+ # driver.mouse.move_to(element, 5, 5)
47
+ #
48
+
49
+ def move_to(element, right_by = nil, down_by = nil)
50
+ assert_element element
51
+
52
+ @bridge.mouseMoveTo element.ref, right_by, down_by
53
+ end
54
+
55
+ def move_by(right_by, down_by)
56
+ @bridge.mouseMoveTo nil, Integer(right_by), Integer(down_by)
57
+ end
58
+
59
+ private
60
+
61
+ def move_if_needed(element)
62
+ move_to element if element
63
+ end
64
+
65
+ def assert_element(element)
66
+ unless element.kind_of? Element
67
+ raise TypeError, "expected #{Element}, got #{element.inspect}:#{element.class}"
68
+ end
69
+ end
70
+ end # Mouse
71
+ end # WebDriver
72
+ end # Selenium
@@ -0,0 +1,43 @@
1
+ module Selenium
2
+ module WebDriver
3
+ class Navigation
4
+
5
+ def initialize(bridge)
6
+ @bridge = bridge
7
+ end
8
+
9
+ #
10
+ # Navigate to the given URL
11
+ #
12
+
13
+ def to(url)
14
+ @bridge.get url
15
+ end
16
+
17
+ #
18
+ # Move back a single entry in the browser's history.
19
+ #
20
+
21
+ def back
22
+ @bridge.goBack
23
+ end
24
+
25
+ #
26
+ # Move forward a single entry in the browser's history.
27
+ #
28
+
29
+ def forward
30
+ @bridge.goForward
31
+ end
32
+
33
+ #
34
+ # Refresh the current page.
35
+ #
36
+
37
+ def refresh
38
+ @bridge.refresh
39
+ end
40
+
41
+ end # Navigation
42
+ end # WebDriver
43
+ end # Selenium
@@ -0,0 +1,136 @@
1
+ module Selenium
2
+ module WebDriver
3
+ class Options
4
+
5
+ #
6
+ # @api private
7
+ #
8
+
9
+ def initialize(bridge)
10
+ @bridge = bridge
11
+ end
12
+
13
+ #
14
+ # Add a cookie to the browser
15
+ #
16
+ # @param [Hash] opts the options to create a cookie with.
17
+ # @option opts [String] :name A name
18
+ # @option opts [String] :value A value
19
+ # @option opts [String] :path ('/') A path
20
+ # @option opts [String] :secure (false) A boolean
21
+ # @option opts [Time,DateTime,Numeric,nil] :expires (nil) Expiry date, either as a Time, DateTime, or seconds since epoch.
22
+ #
23
+ # @raise [ArgumentError] if :name or :value is not specified
24
+ #
25
+
26
+ def add_cookie(opts = {})
27
+ raise ArgumentError, "name is required" unless opts[:name]
28
+ raise ArgumentError, "value is required" unless opts[:value]
29
+
30
+ opts[:path] ||= "/"
31
+ opts[:secure] ||= false
32
+
33
+ if obj = opts.delete(:expires)
34
+ opts[:expiry] = seconds_from(obj)
35
+ end
36
+
37
+
38
+ @bridge.addCookie opts
39
+ end
40
+
41
+ #
42
+ # Get the cookie with the given name
43
+ #
44
+ # @param [String] name the name of the cookie
45
+ # @return [Hash, nil] the cookie, or nil if it wasn't found.
46
+ #
47
+
48
+ def cookie_named(name)
49
+ all_cookies.find { |c| c[:name] == name }
50
+ end
51
+
52
+ #
53
+ # Delete the cookie with the given name
54
+ #
55
+ # @param [String] name the name of the cookie to delete
56
+ #
57
+
58
+ def delete_cookie(name)
59
+ @bridge.deleteCookie name
60
+ end
61
+
62
+ #
63
+ # Delete all cookies
64
+ #
65
+
66
+ def delete_all_cookies
67
+ @bridge.deleteAllCookies
68
+ end
69
+
70
+ #
71
+ # Get all cookies
72
+ #
73
+ # @return [Array<Hash>] list of cookies
74
+ #
75
+
76
+ def all_cookies
77
+ @bridge.getAllCookies.map do |cookie|
78
+ {
79
+ :name => cookie["name"],
80
+ :value => cookie["value"],
81
+ :path => cookie["path"],
82
+ :domain => cookie["domain"] && strip_port(cookie["domain"]),
83
+ :expires => cookie["expiry"] && datetime_at(cookie['expiry']),
84
+ :secure => cookie["secure"]
85
+ }
86
+ end
87
+ end
88
+
89
+ def timeouts
90
+ @timeouts ||= Timeouts.new(@bridge)
91
+ end
92
+
93
+ #
94
+ # @api beta This API may be changed or removed in a future release.
95
+ #
96
+
97
+ def logs
98
+ @logs ||= Logs.new(@bridge)
99
+ end
100
+
101
+ #
102
+ # @api beta This API may be changed or removed in a future release.
103
+ #
104
+
105
+ def window
106
+ @window ||= Window.new(@bridge)
107
+ end
108
+
109
+ private
110
+
111
+ SECONDS_PER_DAY = 86_400.0
112
+
113
+ def datetime_at(int)
114
+ DateTime.civil(1970) + (int / SECONDS_PER_DAY)
115
+ end
116
+
117
+ def seconds_from(obj)
118
+ case obj
119
+ when Time
120
+ obj.to_f
121
+ when DateTime
122
+ (obj - DateTime.civil(1970)) * SECONDS_PER_DAY
123
+ when Numeric
124
+ obj
125
+ else
126
+ raise ArgumentError, "invalid value for expiration date: #{obj.inspect}"
127
+ end
128
+ end
129
+
130
+ def strip_port(str)
131
+ str.split(":", 2).first
132
+ end
133
+
134
+ end # Options
135
+ end # WebDriver
136
+ end # Selenium
@@ -0,0 +1,218 @@
1
+ require 'rbconfig'
2
+ require 'socket'
3
+
4
+ module Selenium
5
+ module WebDriver
6
+
7
+ # @api private
8
+ module Platform
9
+
10
+ module_function
11
+
12
+ def home
13
+ # jruby has an issue with ENV['HOME'] on Windows
14
+ @home ||= jruby? ? ENV_JAVA['user.home'] : ENV['HOME']
15
+ end
16
+
17
+ def engine
18
+ @engine ||= (
19
+ if defined? RUBY_ENGINE
20
+ RUBY_ENGINE.to_sym
21
+ else
22
+ :ruby
23
+ end
24
+ )
25
+ end
26
+
27
+ def os
28
+ @os ||= (
29
+ host_os = RbConfig::CONFIG['host_os']
30
+ case host_os
31
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
32
+ :windows
33
+ when /darwin|mac os/
34
+ :macosx
35
+ when /linux/
36
+ :linux
37
+ when /solaris|bsd/
38
+ :unix
39
+ else
40
+ raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
41
+ end
42
+ )
43
+ end
44
+
45
+ def bitsize
46
+ @bitsize ||= (
47
+ if defined?(FFI::Platform::ADDRESS_SIZE)
48
+ FFI::Platform::ADDRESS_SIZE
49
+ elsif defined?(FFI)
50
+ FFI.type_size(:pointer) == 4 ? 32 : 64
51
+ elsif jruby?
52
+ Integer(ENV_JAVA['sun.arch.data.model'])
53
+ else
54
+ 1.size == 4 ? 32 : 64
55
+ end
56
+ )
57
+ end
58
+
59
+ def jruby?
60
+ engine == :jruby
61
+ end
62
+
63
+ def ironruby?
64
+ engine == :ironruby
65
+ end
66
+
67
+ def ruby187?
68
+ !!(RUBY_VERSION =~ /^1\.8\.7/)
69
+ end
70
+
71
+ def ruby19?
72
+ !!(RUBY_VERSION =~ /^1\.9/)
73
+ end
74
+
75
+ def windows?
76
+ os == :windows
77
+ end
78
+
79
+ def mac?
80
+ os == :macosx
81
+ end
82
+
83
+ def linux?
84
+ os == :linux
85
+ end
86
+
87
+ def cygwin?
88
+ !!(RUBY_PLATFORM =~ /cygwin/)
89
+ end
90
+
91
+ def null_device
92
+ @null_device ||= (
93
+ if defined?(File::NULL)
94
+ File::NULL
95
+ else
96
+ Platform.windows? ? 'NUL' : '/dev/null'
97
+ end
98
+ )
99
+ end
100
+
101
+ def wrap_in_quotes_if_necessary(str)
102
+ windows? && !cygwin? ? %{"#{str}"} : str
103
+ end
104
+
105
+ def cygwin_path(path, opts = {})
106
+ flags = []
107
+ opts.each { |k,v| flags << "--#{k}" if v }
108
+
109
+ `cygpath #{flags.join ' '} "#{path}"`.strip
110
+ end
111
+
112
+ def make_writable(file)
113
+ File.chmod 0766, file
114
+ end
115
+
116
+ def assert_file(path)
117
+ unless File.file? path
118
+ raise Error::WebDriverError, "not a file: #{path.inspect}"
119
+ end
120
+ end
121
+
122
+ def assert_executable(path)
123
+ assert_file(path)
124
+
125
+ unless File.executable? path
126
+ raise Error::WebDriverError, "not executable: #{path.inspect}"
127
+ end
128
+ end
129
+
130
+ def exit_hook(&blk)
131
+ pid = Process.pid
132
+
133
+ at_exit do
134
+ yield if Process.pid == pid
135
+ end
136
+ end
137
+
138
+ def find_binary(*binary_names)
139
+ paths = ENV['PATH'].split(File::PATH_SEPARATOR)
140
+ binary_names.map! { |n| "#{n}.exe" } if windows?
141
+
142
+ binary_names.each do |binary_name|
143
+ paths.each do |path|
144
+ exe = File.join(path, binary_name)
145
+ return exe if File.executable?(exe)
146
+ end
147
+ end
148
+
149
+ nil
150
+ end
151
+
152
+ def find_in_program_files(*binary_names)
153
+ paths = [
154
+ ENV['PROGRAMFILES'] || "\\Program Files",
155
+ ENV['ProgramFiles(x86)'] || "\\Program Files (x86)"
156
+ ]
157
+
158
+ paths.each do |root|
159
+ binary_names.each do |name|
160
+ exe = File.join(root, name)
161
+ return exe if File.executable?(exe)
162
+ end
163
+ end
164
+
165
+ nil
166
+ end
167
+
168
+ def localhost
169
+ info = Socket.getaddrinfo "localhost", 80, Socket::AF_INET, Socket::SOCK_STREAM
170
+
171
+ if info.empty?
172
+ raise Error::WebDriverError, "unable to translate 'localhost' for TCP + IPv4"
173
+ end
174
+
175
+ info[0][3]
176
+ end
177
+
178
+ def ip
179
+ orig = Socket.do_not_reverse_lookup
180
+ Socket.do_not_reverse_lookup = true
181
+
182
+ begin
183
+ UDPSocket.open do |s|
184
+ s.connect '8.8.8.8', 53
185
+ return s.addr.last
186
+ end
187
+ ensure
188
+ Socket.do_not_reverse_lookup = orig
189
+ end
190
+ rescue Errno::ENETUNREACH, Errno::EHOSTUNREACH
191
+ # no external ip
192
+ end
193
+
194
+ def interfaces
195
+ interfaces = Socket.getaddrinfo("localhost", 8080).map { |e| e[3] }
196
+ interfaces += ["0.0.0.0", Platform.ip]
197
+
198
+ interfaces.compact.uniq
199
+ end
200
+
201
+ end # Platform
202
+ end # WebDriver
203
+ end # Selenium
204
+
205
+ if __FILE__ == $0
206
+ p :engine => Selenium::WebDriver::Platform.engine,
207
+ :os => Selenium::WebDriver::Platform.os,
208
+ :ruby187? => Selenium::WebDriver::Platform.ruby187?,
209
+ :ruby19? => Selenium::WebDriver::Platform.ruby19?,
210
+ :jruby? => Selenium::WebDriver::Platform.jruby?,
211
+ :windows? => Selenium::WebDriver::Platform.windows?,
212
+ :home => Selenium::WebDriver::Platform.home,
213
+ :bitsize => Selenium::WebDriver::Platform.bitsize,
214
+ :localhost => Selenium::WebDriver::Platform.localhost,
215
+ :ip => Selenium::WebDriver::Platform.ip,
216
+ :interfaces => Selenium::WebDriver::Platform.interfaces,
217
+ :null_device => Selenium::WebDriver::Platform.null_device
218
+ end