browserstack-webdriver 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,81 @@
1
+ module Selenium
2
+ module WebDriver
3
+ class TargetLocator
4
+
5
+ #
6
+ # @api private
7
+ #
8
+
9
+ def initialize(bridge)
10
+ @bridge = bridge
11
+ end
12
+
13
+ #
14
+ # switch to the frame with the given id
15
+ #
16
+
17
+ def frame(id)
18
+ @bridge.switchToFrame id
19
+ end
20
+
21
+ #
22
+ # switch to the given window handle
23
+ #
24
+ # If given a block, this method will switch back to the original window after
25
+ # block execution.
26
+ #
27
+ # @param id
28
+ # A window handle, obtained through Driver#window_handles
29
+ #
30
+
31
+ def window(id)
32
+ if block_given?
33
+ original = @bridge.getCurrentWindowHandle
34
+ @bridge.switchToWindow id
35
+
36
+ begin
37
+ returned = yield
38
+ ensure
39
+ current_handles = @bridge.getWindowHandles
40
+
41
+ if current_handles.size == 1
42
+ original = current_handles.shift
43
+ end
44
+
45
+ @bridge.switchToWindow original
46
+ returned
47
+ end
48
+ else
49
+ @bridge.switchToWindow id
50
+ end
51
+ end
52
+
53
+ #
54
+ # get the active element
55
+ #
56
+ # @return [WebDriver::Element]
57
+ #
58
+
59
+ def active_element
60
+ @bridge.switchToActiveElement
61
+ end
62
+
63
+ #
64
+ # selects either the first frame on the page, or the main document when a page contains iframes.
65
+ #
66
+
67
+ def default_content
68
+ @bridge.switchToDefaultContent
69
+ end
70
+
71
+ #
72
+ # switches to the currently active modal dialog for this particular driver instance
73
+ #
74
+
75
+ def alert
76
+ Alert.new(@bridge)
77
+ end
78
+
79
+ end # TargetLocator
80
+ end # WebDriver
81
+ end # Selenium
@@ -0,0 +1,38 @@
1
+ module Selenium
2
+ module WebDriver
3
+ class Timeouts
4
+
5
+ def initialize(bridge)
6
+ @bridge = bridge
7
+ end
8
+
9
+ #
10
+ # Set the amount of time the driver should wait when searching for elements.
11
+ #
12
+
13
+ def implicit_wait=(seconds)
14
+ @bridge.setImplicitWaitTimeout Integer(seconds * 1000)
15
+ end
16
+
17
+ #
18
+ # Sets the amount of time to wait for an asynchronous script to finish
19
+ # execution before throwing an error. If the timeout is negative, then the
20
+ # script will be allowed to run indefinitely.
21
+ #
22
+
23
+ def script_timeout=(seconds)
24
+ @bridge.setScriptTimeout Integer(seconds * 1000)
25
+ end
26
+
27
+ #
28
+ # Sets the amount of time to wait for a page load to complete before throwing an error.
29
+ # If the timeout is negative, page loads can be indefinite.
30
+ #
31
+
32
+ def page_load=(seconds)
33
+ @bridge.setTimeout 'page load', Integer(seconds * 1000)
34
+ end
35
+
36
+ end # Timeouts
37
+ end # WebDriver
38
+ end # Selenium
@@ -0,0 +1,64 @@
1
+ module Selenium
2
+ module WebDriver
3
+ class TouchActionBuilder < ActionBuilder
4
+
5
+ #
6
+ # @api private
7
+ #
8
+
9
+ def initialize(mouse, keyboard, touch_screen)
10
+ super(mouse, keyboard)
11
+ @devices[:touch_screen] = touch_screen
12
+ end
13
+
14
+ def scroll(*args)
15
+ unless [2,3].include? args.size
16
+ raise ArgumentError, "wrong number of arguments, expected 2..3, got #{args.size}"
17
+ end
18
+
19
+ @actions << [:touch_screen, :scroll, args]
20
+ self
21
+ end
22
+
23
+ def flick(*args)
24
+ unless [2,4].include? args.size
25
+ raise ArgumentError, "wrong number of arguments, expected 2 or 4, got #{args.size}"
26
+ end
27
+
28
+ @actions << [:touch_screen, :flick, args]
29
+ self
30
+ end
31
+
32
+ def single_tap(element)
33
+ @actions << [:touch_screen, :single_tap, [element]]
34
+ self
35
+ end
36
+
37
+ def double_tap(element)
38
+ @actions << [:touch_screen, :double_tap, [element]]
39
+ self
40
+ end
41
+
42
+ def long_press(element)
43
+ @actions << [:touch_screen, :long_press, [element]]
44
+ self
45
+ end
46
+
47
+ def down(x, y = nil)
48
+ @actions << [:touch_screen, :down, [x, y]]
49
+ self
50
+ end
51
+
52
+ def up(x, y = nil)
53
+ @actions << [:touch_screen, :up, [x, y]]
54
+ self
55
+ end
56
+
57
+ def move(x, y = nil)
58
+ @actions << [:touch_screen, :move, [x, y]]
59
+ self
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,105 @@
1
+ module Selenium
2
+ module WebDriver
3
+ class TouchScreen
4
+ FLICK_SPEED = { :normal => 0, :fast => 1}
5
+
6
+
7
+ #
8
+ # @api private
9
+ #
10
+
11
+ def initialize(bridge)
12
+ @bridge = bridge
13
+ end
14
+
15
+ def single_tap(element)
16
+ assert_element element
17
+ @bridge.touchSingleTap element.ref
18
+ end
19
+
20
+ def double_tap(element)
21
+ assert_element element
22
+ @bridge.touchDoubleTap element.ref
23
+ end
24
+
25
+ def long_press(element)
26
+ assert_element element
27
+ @bridge.touchLongPress element.ref
28
+ end
29
+
30
+ def down(x, y = nil)
31
+ x, y = coords_from x, y
32
+ @bridge.touchDown x, y
33
+ end
34
+
35
+ def up(x, y = nil)
36
+ x, y = coords_from x, y
37
+ @bridge.touchUp x, y
38
+ end
39
+
40
+ def move(x, y = nil)
41
+ x, y = coords_from x, y
42
+ @bridge.touchMove x, y
43
+ end
44
+
45
+ def scroll(*args)
46
+ case args.size
47
+ when 2
48
+ x_offset, y_offset = args
49
+ @bridge.touchScroll nil, Integer(x_offset), Integer(y_offset)
50
+ when 3
51
+ element, x_offset, y_offset = args
52
+ assert_element element
53
+ @bridge.touchScroll element.ref, Integer(x_offset), Integer(y_offset)
54
+ else
55
+ raise ArgumentError, "wrong number of arguments, expected 2..3, got #{args.size}"
56
+ end
57
+ end
58
+
59
+ def flick(*args)
60
+ case args.size
61
+ when 2
62
+ x_speed, y_speed = args
63
+ @bridge.touchFlick Integer(x_speed), Integer(y_speed)
64
+ when 4
65
+ element, xoffset, yoffset, speed = args
66
+
67
+ assert_element element
68
+ flick_speed = FLICK_SPEED[speed.to_sym]
69
+
70
+ unless flick_speed
71
+ raise ArgumentError, "expected one of #{FLICK_SPEED.keys.inspect}, got #{speed.inspect}"
72
+ end
73
+
74
+ @bridge.touchElementFlick element.ref, Integer(xoffset), Integer(yoffset), flick_speed
75
+ else
76
+ raise ArgumentError, "wrong number of arguments, expected 2 or 4, got #{args.size}"
77
+ end
78
+
79
+ end
80
+
81
+ private
82
+
83
+ def coords_from(x, y)
84
+ if y.nil?
85
+ point = x
86
+
87
+ unless point.respond_to?(:x) && point.respond_to?(:y)
88
+ raise ArgumentError, "expected #{point.inspect} to respond to :x and :y"
89
+ end
90
+
91
+ x, y = point.x, point.y
92
+ end
93
+
94
+ [Integer(x), Integer(y)]
95
+ end
96
+
97
+ def assert_element(element)
98
+ unless element.kind_of? Element
99
+ raise TypeError, "expected #{Element}, got #{element.inspect}:#{element.class}"
100
+ end
101
+ end
102
+
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,63 @@
1
+ module Selenium
2
+ module WebDriver
3
+ class Wait
4
+
5
+ DEFAULT_TIMEOUT = 5
6
+ DEFAULT_INTERVAL = 0.2
7
+
8
+ #
9
+ # Create a new Wait instance
10
+ #
11
+ # @param [Hash] opts Options for this instance
12
+ # @option opts [Numeric] :timeout (5) Seconds to wait before timing out.
13
+ # @option opts [Numeric] :interval (0.2) Seconds to sleep between polls.
14
+ # @option opts [String] :message Exception mesage if timed out.
15
+ # @option opts [Array, Exception] :ignore Exceptions to ignore while polling (default: Error::NoSuchElementError)
16
+ #
17
+
18
+ def initialize(opts = {})
19
+ @timeout = opts.fetch(:timeout, DEFAULT_TIMEOUT)
20
+ @interval = opts.fetch(:interval, DEFAULT_INTERVAL)
21
+ @message = opts[:message]
22
+ @ignored = Array(opts[:ignore] || Error::NoSuchElementError)
23
+ end
24
+
25
+
26
+ #
27
+ # Wait until the given block returns a true value.
28
+ #
29
+ # @raise [Error::TimeOutError]
30
+ # @return [Object] the result of the block
31
+ #
32
+
33
+ def until(&blk)
34
+ end_time = Time.now + @timeout
35
+ last_error = nil
36
+
37
+ until Time.now > end_time
38
+ begin
39
+ result = yield
40
+ return result if result
41
+ rescue *@ignored => last_error
42
+ # swallowed
43
+ end
44
+
45
+ sleep @interval
46
+ end
47
+
48
+
49
+ if @message
50
+ msg = @message.dup
51
+ else
52
+ msg = "timed out after #{@timeout} seconds"
53
+ end
54
+
55
+ msg << " (#{last_error.message})" if last_error
56
+
57
+ raise Error::TimeOutError, msg
58
+ end
59
+
60
+ end # Wait
61
+ end # WebDriver
62
+ end # Selenium
63
+
@@ -0,0 +1,104 @@
1
+ module Selenium
2
+ module WebDriver
3
+
4
+ #
5
+ # @api beta This API may be changed or removed in a future release.
6
+ #
7
+
8
+ class Window
9
+
10
+ #
11
+ # @api private
12
+ #
13
+
14
+ def initialize(bridge)
15
+ @bridge = bridge
16
+ end
17
+
18
+ #
19
+ # Resize the current window to the given dimension.
20
+ #
21
+ # @param [Selenium::WebDriver::Dimension, #width and #height] dimension The new size.
22
+ #
23
+
24
+ def size=(dimension)
25
+ unless dimension.respond_to?(:width) && dimension.respond_to?(:height)
26
+ raise ArgumentError, "expected #{dimension.inspect}:#{dimension.class}" +
27
+ " to respond to #width and #height"
28
+ end
29
+
30
+ @bridge.setWindowSize dimension.width, dimension.height
31
+ end
32
+
33
+ #
34
+ # Get the size of the current window.
35
+ #
36
+ # @return [Selenium::WebDriver::Dimension] The size.
37
+ #
38
+
39
+ def size
40
+ @bridge.getWindowSize
41
+ end
42
+
43
+ #
44
+ # Move the current window to the given position.
45
+ #
46
+ # @param [Selenium::WebDriver::Point, #x and #y] point The new position.
47
+ #
48
+
49
+ def position=(point)
50
+ unless point.respond_to?(:x) && point.respond_to?(:y)
51
+ raise ArgumentError, "expected #{point.inspect}:#{point.class}" +
52
+ " to respond to #x and #y"
53
+ end
54
+
55
+ @bridge.setWindowPosition point.x, point.y
56
+ end
57
+
58
+ #
59
+ # Get the position of the current window.
60
+ #
61
+ # @return [Selenium::WebDriver::Point] The position.
62
+ #
63
+
64
+ def position
65
+ @bridge.getWindowPosition
66
+ end
67
+
68
+ #
69
+ # Equivalent to #size=, but accepts width and height arguments.
70
+ #
71
+ # @example Maximize the window.
72
+ #
73
+ # max_width, max_height = driver.execute_script("return [window.screen.availWidth, window.screen.availHeight];")
74
+ # driver.manage.window.resize_to(max_width, max_height)
75
+ #
76
+
77
+ def resize_to(width, height)
78
+ @bridge.setWindowSize Integer(width), Integer(height)
79
+ end
80
+
81
+ #
82
+ # Equivalent to #position=, but accepts x and y arguments.
83
+ #
84
+ # @example
85
+ #
86
+ # driver.manage.window.move_to(300, 400)
87
+ #
88
+
89
+ def move_to(x, y)
90
+ @bridge.setWindowPosition Integer(x), Integer(y)
91
+ end
92
+
93
+ #
94
+ # Maximize the current window
95
+ #
96
+
97
+ def maximize
98
+ @bridge.maximizeWindow
99
+ end
100
+
101
+
102
+ end
103
+ end
104
+ end