bbc-selenium-webdriver 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +473 -0
- data/README +31 -0
- data/lib/selenium-client.rb +2 -0
- data/lib/selenium-webdriver.rb +1 -0
- data/lib/selenium/client.rb +37 -0
- data/lib/selenium/client/base.rb +118 -0
- data/lib/selenium/client/driver.rb +10 -0
- data/lib/selenium/client/errors.rb +9 -0
- data/lib/selenium/client/extensions.rb +118 -0
- data/lib/selenium/client/idiomatic.rb +488 -0
- data/lib/selenium/client/javascript_expression_builder.rb +116 -0
- data/lib/selenium/client/javascript_frameworks/jquery.rb +13 -0
- data/lib/selenium/client/javascript_frameworks/prototype.rb +13 -0
- data/lib/selenium/client/legacy_driver.rb +1720 -0
- data/lib/selenium/client/protocol.rb +104 -0
- data/lib/selenium/client/selenium_helper.rb +34 -0
- data/lib/selenium/rake/server_task.rb +157 -0
- data/lib/selenium/server.rb +223 -0
- data/lib/selenium/webdriver.rb +64 -0
- data/lib/selenium/webdriver/android.rb +9 -0
- data/lib/selenium/webdriver/android/bridge.rb +51 -0
- data/lib/selenium/webdriver/chrome.rb +26 -0
- data/lib/selenium/webdriver/chrome/bridge.rb +106 -0
- data/lib/selenium/webdriver/chrome/profile.rb +83 -0
- data/lib/selenium/webdriver/chrome/service.rb +74 -0
- data/lib/selenium/webdriver/common.rb +30 -0
- data/lib/selenium/webdriver/common/action_builder.rb +352 -0
- data/lib/selenium/webdriver/common/alert.rb +26 -0
- data/lib/selenium/webdriver/common/bridge_helper.rb +67 -0
- data/lib/selenium/webdriver/common/core_ext/base64.rb +9 -0
- data/lib/selenium/webdriver/common/core_ext/dir.rb +42 -0
- data/lib/selenium/webdriver/common/core_ext/string.rb +5 -0
- data/lib/selenium/webdriver/common/driver.rb +301 -0
- data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +39 -0
- data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +44 -0
- data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +43 -0
- data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +46 -0
- data/lib/selenium/webdriver/common/element.rb +262 -0
- data/lib/selenium/webdriver/common/error.rb +212 -0
- data/lib/selenium/webdriver/common/file_reaper.rb +47 -0
- data/lib/selenium/webdriver/common/keyboard.rb +52 -0
- data/lib/selenium/webdriver/common/keys.rb +109 -0
- data/lib/selenium/webdriver/common/mouse.rb +65 -0
- data/lib/selenium/webdriver/common/navigation.rb +43 -0
- data/lib/selenium/webdriver/common/options.rb +128 -0
- data/lib/selenium/webdriver/common/platform.rb +166 -0
- data/lib/selenium/webdriver/common/port_prober.rb +25 -0
- data/lib/selenium/webdriver/common/profile_helper.rb +67 -0
- data/lib/selenium/webdriver/common/proxy.rb +120 -0
- data/lib/selenium/webdriver/common/search_context.rb +92 -0
- data/lib/selenium/webdriver/common/socket_poller.rb +100 -0
- data/lib/selenium/webdriver/common/target_locator.rb +81 -0
- data/lib/selenium/webdriver/common/timeouts.rb +29 -0
- data/lib/selenium/webdriver/common/wait.rb +60 -0
- data/lib/selenium/webdriver/common/window.rb +96 -0
- data/lib/selenium/webdriver/common/zipper.rb +82 -0
- data/lib/selenium/webdriver/firefox.rb +37 -0
- data/lib/selenium/webdriver/firefox/binary.rb +161 -0
- data/lib/selenium/webdriver/firefox/bridge.rb +58 -0
- data/lib/selenium/webdriver/firefox/extension.rb +52 -0
- data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
- data/lib/selenium/webdriver/firefox/launcher.rb +104 -0
- data/lib/selenium/webdriver/firefox/native/linux/amd64/x_ignore_nofocus.so +0 -0
- data/lib/selenium/webdriver/firefox/native/linux/x86/x_ignore_nofocus.so +0 -0
- data/lib/selenium/webdriver/firefox/profile.rb +315 -0
- data/lib/selenium/webdriver/firefox/profiles_ini.rb +62 -0
- data/lib/selenium/webdriver/firefox/socket_lock.rb +61 -0
- data/lib/selenium/webdriver/firefox/util.rb +29 -0
- data/lib/selenium/webdriver/ie.rb +19 -0
- data/lib/selenium/webdriver/ie/bridge.rb +60 -0
- data/lib/selenium/webdriver/ie/native/win32/IEDriver.dll +0 -0
- data/lib/selenium/webdriver/ie/native/x64/IEDriver.dll +0 -0
- data/lib/selenium/webdriver/ie/server.rb +64 -0
- data/lib/selenium/webdriver/iphone.rb +9 -0
- data/lib/selenium/webdriver/iphone/bridge.rb +50 -0
- data/lib/selenium/webdriver/opera.rb +24 -0
- data/lib/selenium/webdriver/opera/bridge.rb +113 -0
- data/lib/selenium/webdriver/opera/service.rb +49 -0
- data/lib/selenium/webdriver/remote.rb +21 -0
- data/lib/selenium/webdriver/remote/bridge.rb +473 -0
- data/lib/selenium/webdriver/remote/capabilities.rb +241 -0
- data/lib/selenium/webdriver/remote/commands.rb +181 -0
- data/lib/selenium/webdriver/remote/http/common.rb +74 -0
- data/lib/selenium/webdriver/remote/http/curb.rb +79 -0
- data/lib/selenium/webdriver/remote/http/default.rb +102 -0
- data/lib/selenium/webdriver/remote/http/persistent.rb +38 -0
- data/lib/selenium/webdriver/remote/response.rb +99 -0
- data/lib/selenium/webdriver/remote/server_error.rb +17 -0
- data/lib/selenium/webdriver/support.rb +4 -0
- data/lib/selenium/webdriver/support/abstract_event_listener.rb +28 -0
- data/lib/selenium/webdriver/support/block_event_listener.rb +17 -0
- data/lib/selenium/webdriver/support/event_firing_bridge.rb +112 -0
- data/lib/selenium/webdriver/support/select.rb +293 -0
- data/spec/integration/selenium/client/api/backward_compatible_api_spec.rb +22 -0
- data/spec/integration/selenium/client/api/browser_xpath_library_spec.rb +17 -0
- data/spec/integration/selenium/client/api/click_spec.rb +39 -0
- data/spec/integration/selenium/client/api/cookie_spec.rb +39 -0
- data/spec/integration/selenium/client/api/element_spec.rb +14 -0
- data/spec/integration/selenium/client/api/highlight_located_element_spec.rb +19 -0
- data/spec/integration/selenium/client/api/retrieve_last_remote_control_logs_spec.rb +33 -0
- data/spec/integration/selenium/client/api/screenshot_spec.rb +29 -0
- data/spec/integration/selenium/client/api/select_window_spec.rb +46 -0
- data/spec/integration/selenium/client/api/start_stop_spec.rb +9 -0
- data/spec/integration/selenium/client/api/wait_for_ajax_spec.rb +27 -0
- data/spec/integration/selenium/client/api/wait_for_element_spec.rb +56 -0
- data/spec/integration/selenium/client/api/wait_for_field_value_spec.rb +52 -0
- data/spec/integration/selenium/client/api/wait_for_text_spec.rb +98 -0
- data/spec/integration/selenium/client/sample-app/public/jquery-1.3.2.js +4376 -0
- data/spec/integration/selenium/client/sample-app/public/jquery.html +55 -0
- data/spec/integration/selenium/client/sample-app/public/prototype-1.6.0.3.js +4320 -0
- data/spec/integration/selenium/client/sample-app/public/prototype.html +59 -0
- data/spec/integration/selenium/client/sample-app/sample_app.rb +32 -0
- data/spec/integration/selenium/client/spec_helper.rb +125 -0
- data/spec/integration/selenium/webdriver/chrome/driver_spec.rb +28 -0
- data/spec/integration/selenium/webdriver/chrome/profile_spec.rb +42 -0
- data/spec/integration/selenium/webdriver/driver_spec.rb +253 -0
- data/spec/integration/selenium/webdriver/element_spec.rb +185 -0
- data/spec/integration/selenium/webdriver/error_spec.rb +30 -0
- data/spec/integration/selenium/webdriver/firefox/driver_spec.rb +21 -0
- data/spec/integration/selenium/webdriver/firefox/profile_spec.rb +141 -0
- data/spec/integration/selenium/webdriver/keyboard_spec.rb +57 -0
- data/spec/integration/selenium/webdriver/mouse_spec.rb +55 -0
- data/spec/integration/selenium/webdriver/navigation_spec.rb +44 -0
- data/spec/integration/selenium/webdriver/opera/driver_spec.rb +47 -0
- data/spec/integration/selenium/webdriver/options_spec.rb +49 -0
- data/spec/integration/selenium/webdriver/remote/element_spec.rb +24 -0
- data/spec/integration/selenium/webdriver/spec_helper.rb +44 -0
- data/spec/integration/selenium/webdriver/spec_support.rb +13 -0
- data/spec/integration/selenium/webdriver/spec_support/guards.rb +86 -0
- data/spec/integration/selenium/webdriver/spec_support/helpers.rb +46 -0
- data/spec/integration/selenium/webdriver/spec_support/jruby_test_environment.rb +29 -0
- data/spec/integration/selenium/webdriver/spec_support/rack_server.rb +123 -0
- data/spec/integration/selenium/webdriver/spec_support/test_environment.rb +199 -0
- data/spec/integration/selenium/webdriver/target_locator_spec.rb +170 -0
- data/spec/integration/selenium/webdriver/timeout_spec.rb +56 -0
- data/spec/integration/selenium/webdriver/window_spec.rb +56 -0
- data/spec/integration/selenium/webdriver/zipper_spec.rb +66 -0
- data/spec/unit/selenium/client/base_spec.rb +239 -0
- data/spec/unit/selenium/client/extensions_spec.rb +174 -0
- data/spec/unit/selenium/client/idiomatic_spec.rb +500 -0
- data/spec/unit/selenium/client/javascript_expression_builder_spec.rb +79 -0
- data/spec/unit/selenium/client/javascript_frameworks/jquery_spec.rb +10 -0
- data/spec/unit/selenium/client/javascript_frameworks/prototype_spec.rb +10 -0
- data/spec/unit/selenium/client/protocol_spec.rb +124 -0
- data/spec/unit/selenium/client/selenium_helper_spec.rb +56 -0
- data/spec/unit/selenium/client/spec_helper.rb +24 -0
- data/spec/unit/selenium/rake/task_spec.rb +79 -0
- data/spec/unit/selenium/server_spec.rb +131 -0
- data/spec/unit/selenium/webdriver/action_builder_spec.rb +90 -0
- data/spec/unit/selenium/webdriver/android/bridge_spec.rb +31 -0
- data/spec/unit/selenium/webdriver/chrome/bridge_spec.rb +94 -0
- data/spec/unit/selenium/webdriver/chrome/profile_spec.rb +57 -0
- data/spec/unit/selenium/webdriver/chrome/service_spec.rb +44 -0
- data/spec/unit/selenium/webdriver/error_spec.rb +41 -0
- data/spec/unit/selenium/webdriver/firefox/bridge_spec.rb +17 -0
- data/spec/unit/selenium/webdriver/iphone/bridge_spec.rb +30 -0
- data/spec/unit/selenium/webdriver/proxy_spec.rb +87 -0
- data/spec/unit/selenium/webdriver/remote/bridge_spec.rb +16 -0
- data/spec/unit/selenium/webdriver/remote/capabilities_spec.rb +111 -0
- data/spec/unit/selenium/webdriver/remote/http/common_spec.rb +24 -0
- data/spec/unit/selenium/webdriver/remote/http/default_spec.rb +46 -0
- data/spec/unit/selenium/webdriver/search_context_spec.rb +61 -0
- data/spec/unit/selenium/webdriver/socket_poller_spec.rb +68 -0
- data/spec/unit/selenium/webdriver/spec_helper.rb +6 -0
- data/spec/unit/selenium/webdriver/support/event_firing_spec.rb +111 -0
- data/spec/unit/selenium/webdriver/support/select_spec.rb +290 -0
- data/spec/unit/selenium/webdriver/wait_spec.rb +40 -0
- metadata +215 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
module Selenium
|
2
|
+
module WebDriver
|
3
|
+
|
4
|
+
#
|
5
|
+
# @api private
|
6
|
+
#
|
7
|
+
|
8
|
+
module FileReaper
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def reap=(bool)
|
12
|
+
@reap = bool
|
13
|
+
end
|
14
|
+
|
15
|
+
def reap?
|
16
|
+
@reap = true unless defined?(@reap)
|
17
|
+
!!@reap
|
18
|
+
end
|
19
|
+
|
20
|
+
def tmp_files
|
21
|
+
@tmp_files ||= []
|
22
|
+
end
|
23
|
+
|
24
|
+
def <<(file)
|
25
|
+
tmp_files << file
|
26
|
+
end
|
27
|
+
|
28
|
+
def reap(file)
|
29
|
+
return unless reap?
|
30
|
+
|
31
|
+
unless tmp_files.include?(file)
|
32
|
+
raise Error::WebDriverError, "file not added for reaping: #{file.inspect}"
|
33
|
+
end
|
34
|
+
|
35
|
+
FileUtils.rm_rf tmp_files.delete(file)
|
36
|
+
end
|
37
|
+
|
38
|
+
def reap!
|
39
|
+
tmp_files.each { |file| FileUtils.rm_rf(file) } if reap?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
Platform.exit_hook { reap! }
|
44
|
+
|
45
|
+
end # FileReaper
|
46
|
+
end # WebDriver
|
47
|
+
end # Selenium
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Selenium
|
2
|
+
module WebDriver
|
3
|
+
|
4
|
+
# @api private
|
5
|
+
class Keyboard
|
6
|
+
|
7
|
+
def initialize(bridge)
|
8
|
+
@bridge = bridge
|
9
|
+
end
|
10
|
+
|
11
|
+
def send_keys(*keys)
|
12
|
+
@bridge.sendKeysToActiveElement Keys.encode(keys)
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Press a modifier key
|
17
|
+
#
|
18
|
+
# @see Selenium::WebDriver::Keys
|
19
|
+
#
|
20
|
+
|
21
|
+
def press(key)
|
22
|
+
assert_modifier key
|
23
|
+
|
24
|
+
@bridge.sendKeysToActiveElement Keys.encode([key])
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# Release a modifier key
|
29
|
+
#
|
30
|
+
# @see Selenium::WebDriver::Keys
|
31
|
+
#
|
32
|
+
|
33
|
+
def release(key)
|
34
|
+
assert_modifier key
|
35
|
+
|
36
|
+
@bridge.sendKeysToActiveElement Keys.encode([key])
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
MODIFIERS = [:control, :shift, :alt, :command, :meta]
|
42
|
+
|
43
|
+
def assert_modifier(key)
|
44
|
+
unless MODIFIERS.include? key
|
45
|
+
raise ArgumentError,
|
46
|
+
"#{key.inspect} is not a modifier key, expected one of #{MODIFIERS.inspect}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end # Keyboard
|
51
|
+
end # WebDriver
|
52
|
+
end # Selenium
|
@@ -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,65 @@
|
|
1
|
+
module Selenium
|
2
|
+
module WebDriver
|
3
|
+
|
4
|
+
# @api private
|
5
|
+
class Mouse
|
6
|
+
|
7
|
+
def initialize(bridge)
|
8
|
+
@bridge = bridge
|
9
|
+
end
|
10
|
+
|
11
|
+
def click(element = nil)
|
12
|
+
move_if_needed element
|
13
|
+
@bridge.click
|
14
|
+
end
|
15
|
+
|
16
|
+
def double_click(element = nil)
|
17
|
+
move_if_needed element
|
18
|
+
@bridge.doubleClick
|
19
|
+
end
|
20
|
+
|
21
|
+
def context_click(element = nil)
|
22
|
+
move_if_needed element
|
23
|
+
@bridge.contextClick
|
24
|
+
end
|
25
|
+
|
26
|
+
def down(element = nil)
|
27
|
+
move_if_needed element
|
28
|
+
@bridge.mouseDown
|
29
|
+
end
|
30
|
+
|
31
|
+
def up(element = nil)
|
32
|
+
move_if_needed element
|
33
|
+
@bridge.mouseUp
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Move the mouse.
|
38
|
+
#
|
39
|
+
# Examples:
|
40
|
+
#
|
41
|
+
# driver.mouse.move_to(element)
|
42
|
+
# driver.mouse.move_to(element, 5, 5)
|
43
|
+
#
|
44
|
+
|
45
|
+
def move_to(element, right_by = nil, down_by = nil)
|
46
|
+
unless element.kind_of? Element
|
47
|
+
raise TypeError, "expected #{Element}, got #{element.inspect}:#{element.class}"
|
48
|
+
end
|
49
|
+
|
50
|
+
@bridge.mouseMoveTo element.ref, right_by, down_by
|
51
|
+
end
|
52
|
+
|
53
|
+
def move_by(right_by, down_by)
|
54
|
+
@bridge.mouseMoveTo nil, right_by, down_by
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def move_if_needed(element)
|
60
|
+
move_to element if element
|
61
|
+
end
|
62
|
+
|
63
|
+
end # Mouse
|
64
|
+
end # WebDriver
|
65
|
+
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,128 @@
|
|
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 window
|
98
|
+
@window ||= Window.new(@bridge)
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
SECONDS_PER_DAY = 86_400.0
|
104
|
+
|
105
|
+
def datetime_at(int)
|
106
|
+
DateTime.civil(1970) + (int / SECONDS_PER_DAY)
|
107
|
+
end
|
108
|
+
|
109
|
+
def seconds_from(obj)
|
110
|
+
case obj
|
111
|
+
when Time
|
112
|
+
obj.to_f
|
113
|
+
when DateTime
|
114
|
+
(obj - DateTime.civil(1970)) * SECONDS_PER_DAY
|
115
|
+
when Numeric
|
116
|
+
obj
|
117
|
+
else
|
118
|
+
raise ArgumentError, "invalid value for expiration date: #{obj.inspect}"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def strip_port(str)
|
123
|
+
str.split(":", 2).first
|
124
|
+
end
|
125
|
+
|
126
|
+
end # Options
|
127
|
+
end # WebDriver
|
128
|
+
end # Selenium
|