selenium-webdriver 2.53.4 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/CHANGES +24 -18
  2. data/README.md +2 -3
  3. data/lib/selenium/server.rb +64 -68
  4. data/lib/selenium/webdriver.rb +5 -9
  5. data/lib/selenium/webdriver/chrome.rb +18 -3
  6. data/lib/selenium/webdriver/chrome/bridge.rb +13 -16
  7. data/lib/selenium/webdriver/chrome/profile.rb +7 -9
  8. data/lib/selenium/webdriver/chrome/service.rb +8 -84
  9. data/lib/selenium/webdriver/common.rb +1 -2
  10. data/lib/selenium/webdriver/common/action_builder.rb +28 -38
  11. data/lib/selenium/webdriver/common/alert.rb +7 -10
  12. data/lib/selenium/webdriver/common/bridge_helper.rb +10 -15
  13. data/lib/selenium/webdriver/common/driver.rb +19 -28
  14. data/lib/selenium/webdriver/common/driver_extensions/has_input_devices.rb +0 -3
  15. data/lib/selenium/webdriver/common/driver_extensions/has_location.rb +4 -6
  16. data/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb +4 -5
  17. data/lib/selenium/webdriver/common/driver_extensions/has_remote_status.rb +0 -2
  18. data/lib/selenium/webdriver/common/driver_extensions/has_session_id.rb +0 -2
  19. data/lib/selenium/webdriver/common/driver_extensions/has_touch_screen.rb +0 -2
  20. data/lib/selenium/webdriver/common/driver_extensions/has_web_storage.rb +0 -3
  21. data/lib/selenium/webdriver/common/driver_extensions/rotatable.rb +3 -6
  22. data/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb +2 -5
  23. data/lib/selenium/webdriver/common/driver_extensions/uploads_files.rb +2 -5
  24. data/lib/selenium/webdriver/common/element.rb +27 -29
  25. data/lib/selenium/webdriver/common/error.rb +17 -20
  26. data/lib/selenium/webdriver/common/file_reaper.rb +3 -9
  27. data/lib/selenium/webdriver/common/html5/local_storage.rb +6 -8
  28. data/lib/selenium/webdriver/common/html5/session_storage.rb +6 -8
  29. data/lib/selenium/webdriver/common/html5/shared_web_storage.rb +6 -15
  30. data/lib/selenium/webdriver/common/keyboard.rb +7 -12
  31. data/lib/selenium/webdriver/common/keys.rb +67 -69
  32. data/lib/selenium/webdriver/common/log_entry.rb +3 -4
  33. data/lib/selenium/webdriver/common/logs.rb +2 -4
  34. data/lib/selenium/webdriver/common/mouse.rb +9 -12
  35. data/lib/selenium/webdriver/common/navigation.rb +2 -4
  36. data/lib/selenium/webdriver/common/options.rb +16 -19
  37. data/lib/selenium/webdriver/common/platform.rb +61 -90
  38. data/lib/selenium/webdriver/common/port_prober.rb +1 -2
  39. data/lib/selenium/webdriver/common/profile_helper.rb +5 -8
  40. data/lib/selenium/webdriver/common/proxy.rb +58 -70
  41. data/lib/selenium/webdriver/common/search_context.rb +15 -19
  42. data/lib/selenium/webdriver/common/service.rb +127 -0
  43. data/lib/selenium/webdriver/common/socket_lock.rb +5 -11
  44. data/lib/selenium/webdriver/common/socket_poller.rb +4 -9
  45. data/lib/selenium/webdriver/common/target_locator.rb +11 -13
  46. data/lib/selenium/webdriver/common/timeouts.rb +4 -6
  47. data/lib/selenium/webdriver/common/touch_action_builder.rb +2 -4
  48. data/lib/selenium/webdriver/common/touch_screen.rb +15 -18
  49. data/lib/selenium/webdriver/common/w3c_error.rb +3 -6
  50. data/lib/selenium/webdriver/common/wait.rb +6 -11
  51. data/lib/selenium/webdriver/common/window.rb +12 -15
  52. data/lib/selenium/webdriver/common/zipper.rb +6 -8
  53. data/lib/selenium/webdriver/edge.rb +18 -3
  54. data/lib/selenium/webdriver/edge/bridge.rb +11 -16
  55. data/lib/selenium/webdriver/edge/legacy_support.rb +38 -39
  56. data/lib/selenium/webdriver/edge/service.rb +8 -82
  57. data/lib/selenium/webdriver/firefox.rb +25 -6
  58. data/lib/selenium/webdriver/firefox/binary.rb +37 -53
  59. data/lib/selenium/webdriver/firefox/bridge.rb +3 -6
  60. data/lib/selenium/webdriver/firefox/extension.rb +4 -6
  61. data/lib/selenium/webdriver/firefox/extension/prefs.json +1 -10
  62. data/lib/selenium/webdriver/firefox/extension/webdriver.xpi +0 -0
  63. data/lib/selenium/webdriver/firefox/launcher.rb +8 -11
  64. data/lib/selenium/webdriver/firefox/profile.rb +40 -42
  65. data/lib/selenium/webdriver/firefox/profiles_ini.rb +8 -15
  66. data/lib/selenium/webdriver/firefox/service.rb +23 -79
  67. data/lib/selenium/webdriver/firefox/util.rb +0 -2
  68. data/lib/selenium/webdriver/firefox/w3c_bridge.rb +2 -4
  69. data/lib/selenium/webdriver/ie.rb +16 -7
  70. data/lib/selenium/webdriver/ie/bridge.rb +16 -23
  71. data/lib/selenium/webdriver/{iphone.rb → ie/service.rb} +26 -4
  72. data/lib/selenium/webdriver/phantomjs.rb +8 -3
  73. data/lib/selenium/webdriver/phantomjs/bridge.rb +9 -11
  74. data/lib/selenium/webdriver/phantomjs/service.rb +17 -81
  75. data/lib/selenium/webdriver/remote.rb +0 -2
  76. data/lib/selenium/webdriver/remote/bridge.rb +193 -191
  77. data/lib/selenium/webdriver/remote/capabilities.rb +60 -90
  78. data/lib/selenium/webdriver/remote/commands.rb +197 -192
  79. data/lib/selenium/webdriver/remote/http/common.rb +15 -13
  80. data/lib/selenium/webdriver/remote/http/curb.rb +5 -9
  81. data/lib/selenium/webdriver/remote/http/default.rb +32 -37
  82. data/lib/selenium/webdriver/remote/http/persistent.rb +4 -6
  83. data/lib/selenium/webdriver/remote/response.rb +13 -21
  84. data/lib/selenium/webdriver/remote/server_error.rb +1 -3
  85. data/lib/selenium/webdriver/remote/w3c_bridge.rb +200 -195
  86. data/lib/selenium/webdriver/remote/w3c_capabilities.rb +38 -46
  87. data/lib/selenium/webdriver/remote/w3c_commands.rb +116 -113
  88. data/lib/selenium/webdriver/safari.rb +23 -7
  89. data/lib/selenium/{client/javascript_frameworks/jquery.rb → webdriver/safari/apple_bridge.rb} +28 -9
  90. data/lib/selenium/webdriver/safari/browser.rb +0 -2
  91. data/lib/selenium/webdriver/safari/{bridge.rb → legacy_bridge.rb} +12 -9
  92. data/lib/selenium/webdriver/safari/options.rb +3 -4
  93. data/lib/selenium/webdriver/safari/resources/client.js +56 -7255
  94. data/lib/selenium/webdriver/safari/server.rb +18 -24
  95. data/lib/selenium/{client/javascript_frameworks/prototype.rb → webdriver/safari/service.rb} +27 -9
  96. data/lib/selenium/webdriver/support.rb +1 -0
  97. data/lib/selenium/webdriver/support/abstract_event_listener.rb +17 -2
  98. data/lib/selenium/webdriver/support/block_event_listener.rb +1 -3
  99. data/lib/selenium/webdriver/support/color.rb +55 -38
  100. data/lib/selenium/webdriver/{android.rb → support/escaper.rb} +19 -4
  101. data/lib/selenium/webdriver/support/event_firing_bridge.rb +36 -38
  102. data/lib/selenium/webdriver/support/select.rb +33 -84
  103. data/selenium-webdriver.gemspec +23 -23
  104. metadata +19 -30
  105. data/lib/selenium-client.rb +0 -21
  106. data/lib/selenium/client.rb +0 -57
  107. data/lib/selenium/client/base.rb +0 -151
  108. data/lib/selenium/client/driver.rb +0 -29
  109. data/lib/selenium/client/errors.rb +0 -28
  110. data/lib/selenium/client/extensions.rb +0 -132
  111. data/lib/selenium/client/idiomatic.rb +0 -507
  112. data/lib/selenium/client/javascript_expression_builder.rb +0 -135
  113. data/lib/selenium/client/legacy_driver.rb +0 -1722
  114. data/lib/selenium/client/protocol.rb +0 -123
  115. data/lib/selenium/client/selenium_helper.rb +0 -49
  116. data/lib/selenium/rake/server_task.rb +0 -176
  117. data/lib/selenium/webdriver/android/bridge.rb +0 -68
  118. data/lib/selenium/webdriver/common/core_ext/base64.rb +0 -28
  119. data/lib/selenium/webdriver/common/core_ext/dir.rb +0 -61
  120. data/lib/selenium/webdriver/common/html5/location.rb +0 -19
  121. data/lib/selenium/webdriver/ie/server.rb +0 -133
  122. data/lib/selenium/webdriver/iphone/bridge.rb +0 -64
@@ -1,151 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Licensed to the Software Freedom Conservancy (SFC) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The SFC licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
-
20
- module Selenium
21
- module Client
22
-
23
- # Driver constructor and session management commands
24
- module Base
25
- include Selenium::Client::Protocol
26
- include Selenium::Client::GeneratedDriver
27
- include Selenium::Client::Extensions
28
- include Selenium::Client::Idiomatic
29
-
30
- attr_reader :host, :port, :browser_string, :browser_url,
31
- :default_timeout_in_seconds,
32
- :default_javascript_framework,
33
- :highlight_located_element_by_default
34
-
35
- #
36
- # Create a new client driver
37
- #
38
- # Example:
39
- #
40
- # Selenium::Client::Driver.new \
41
- # :host => "localhost",
42
- # :port => 4444,
43
- # :browser => "*firefox",
44
- # :timeout_in_seconds => 10,
45
- # :url => "http://localhost:3000",
46
- #
47
- # You can also set the default javascript framework used for :wait_for
48
- # AJAX and effects semantics (:prototype is the default value):
49
- #
50
- # Selenium::Client::Driver.new \
51
- # :host => "localhost",
52
- # :port => 4444,
53
- # :browser => "*firefox",
54
- # :timeout_in_seconds => 10,
55
- # :url => "http://localhost:3000",
56
- # :javascript_framework => :jquery
57
- #
58
- # You can also enables automatic highlighting of located elements
59
- # by passing the highlight_located_element option, e.g.
60
- #
61
- # Selenium::Client::Driver.new \
62
- # :host => "localhost",
63
- # :port => 4444,
64
- # :browser => "*firefox",
65
- # :highlight_located_element => true
66
- #
67
- def initialize(*args)
68
- if args[0].kind_of?(Hash)
69
- options = args[0]
70
- @host = options[:host]
71
- @port = options[:port].to_i
72
- @browser_string = options[:browser]
73
- @browser_url = options[:url]
74
- @default_timeout_in_seconds = (options[:timeout_in_seconds] || 300).to_i
75
- @default_javascript_framework = options[:javascript_framework] || :prototype
76
- @highlight_located_element_by_default = options[:highlight_located_element] || false
77
- else
78
- @host = args[0]
79
- @port = args[1].to_i
80
- @browser_string = args[2]
81
- @browser_url = args[3]
82
- @default_timeout_in_seconds = (args[4] || 300).to_i
83
- @default_javascript_framework = :prototype
84
- @highlight_located_element_by_default = false
85
- end
86
-
87
- @extension_js = ""
88
- @session_id = nil
89
- end
90
-
91
- def session_started?
92
- not @session_id.nil?
93
- end
94
-
95
- # Starts a new browser session (launching a new browser matching
96
- # configuration provided at driver creation time).
97
- #
98
- # Browser session specific option can also be provided. e.g.
99
- #
100
- # driver.start_new_browser_session(:captureNetworkTraffic => true)
101
- #
102
- def start_new_browser_session(options={})
103
- start_args = [@browser_string, @browser_url, @extension_js]
104
-
105
- if driver = options.delete(:driver)
106
- expected_browser_string = "*webdriver"
107
- unless @browser_string == expected_browser_string
108
- raise ArgumentError, "can't use :driver unless the browser string is #{expected_browser_string.inspect} (got #{@browser_string.inspect})"
109
- end
110
-
111
- sid = driver.capabilities['webdriver.remote.sessionid']
112
- sid or raise ArgumentError, "This driver can not be wrapped in the RC API."
113
-
114
- start_args << "webdriver.remote.sessionid=#{sid}"
115
- end
116
-
117
- start_args << options.collect {|key,value| "#{key.to_s}=#{value.to_s}"}.sort.join(";")
118
-
119
- @session_id = string_command "getNewBrowserSession", start_args
120
- # Consistent timeout on the remote control and driver side.
121
- # Intuitive and this is what you want 90% of the time
122
- self.remote_control_timeout_in_seconds = @default_timeout_in_seconds
123
- self.highlight_located_element = true if highlight_located_element_by_default
124
- end
125
-
126
- def close_current_browser_session
127
- remote_control_command "testComplete" if @session_id
128
- @session_id = nil
129
- end
130
-
131
- def start(opts = {})
132
- start_new_browser_session opts
133
- end
134
-
135
- def stop
136
- close_current_browser_session
137
- end
138
-
139
- def chrome_backend?
140
- ["*chrome", "*firefox", "*firefox2", "*firefox3"].include?(@browser_string)
141
- end
142
-
143
- def javascript_extension=(new_javascript_extension)
144
- @extension_js = new_javascript_extension
145
- end
146
- alias :set_extension_js :javascript_extension=
147
-
148
- end
149
-
150
- end
151
- end
@@ -1,29 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Licensed to the Software Freedom Conservancy (SFC) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The SFC licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
-
20
- module Selenium
21
- module Client
22
-
23
- # Client driver providing the complete API to drive a Selenium Remote Control
24
- class Driver
25
- include Selenium::Client::Base
26
- end
27
-
28
- end
29
- end
@@ -1,28 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Licensed to the Software Freedom Conservancy (SFC) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The SFC licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
-
20
- module Selenium
21
- module Client
22
- class CommandError < RuntimeError
23
- end
24
-
25
- class ProtocolError < RuntimeError
26
- end
27
- end
28
- end
@@ -1,132 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Licensed to the Software Freedom Conservancy (SFC) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The SFC licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
-
20
- module Selenium
21
- module Client
22
-
23
- # Convenience methods not explicitly part of the protocol
24
- module Extensions
25
-
26
- # These for all Ajax request to finish (Only works if you are using prototype, the wait happens in the browser)
27
- def wait_for_ajax(options={})
28
- builder = JavascriptExpressionBuilder.new active_javascript_framework(options)
29
- wait_for_condition builder.no_pending_ajax_requests.script, options[:timeout_in_seconds]
30
- end
31
-
32
- # Wait for all Prototype effects to be processed (the wait happens in the browser).
33
- #
34
- # Credits to http://github.com/brynary/webrat/tree/master
35
- def wait_for_effects(options={})
36
- builder = JavascriptExpressionBuilder.new active_javascript_framework(options)
37
- wait_for_condition builder.no_pending_effects.script, options[:timeout_in_seconds]
38
- end
39
-
40
- # Wait for an element to be present (the wait happens in the browser).
41
- def wait_for_element(locator, options={})
42
- builder = JavascriptExpressionBuilder.new
43
- builder.find_element(locator).append("element != null;")
44
- wait_for_condition builder.script, options[:timeout_in_seconds]
45
- end
46
-
47
- # Wait for an element to NOT be present (the wait happens in the browser).
48
- def wait_for_no_element(locator, options={})
49
- builder = JavascriptExpressionBuilder.new
50
- builder.find_element(locator).append("element == null;")
51
- wait_for_condition builder.script, options[:timeout_in_seconds]
52
- end
53
-
54
- # Wait for some text to be present (the wait is happening browser side).
55
- #
56
- # wait_for_text will search for the given argument within the innerHTML
57
- # of the current DOM. Note that this method treats a single string
58
- # as a special case.
59
- #
60
- # ==== Parameters
61
- # wait_for_text accepts an optional hash of parameters:
62
- # * <tt>:element</tt> - a selenium locator for an element limiting
63
- # the search scope.
64
- # * <tt>:timeout_in_seconds</tt> - duration in seconds after which we
65
- # time out if text cannot be found.
66
- #
67
- # ==== Regular Expressions
68
- # In addition to plain strings, wait_for_text accepts regular expressions
69
- # as the pattern specification.
70
- #
71
- # ==== Examples
72
- # The following are equivalent, and will match "some text" anywhere
73
- # within the document:
74
- # wait_for_text "some text"
75
- # wait_for_text /some text/
76
- #
77
- # This will match "some text" anywhere within the specified element:
78
- # wait_for_text /some text/, :element => "container"
79
- #
80
- # This will match "some text" only if it exactly matches the complete
81
- # innerHTML of the specified element:
82
- # wait_for_text "some text", :element => "container"
83
- #
84
- def wait_for_text(pattern, options={})
85
- builder = JavascriptExpressionBuilder.new
86
- builder.find_text(pattern, options).append("text_match == true;")
87
- wait_for_condition builder.script, options[:timeout_in_seconds]
88
- end
89
-
90
- # Wait for some text to NOT be present (the wait happens in the browser).
91
- #
92
- # See wait_for_text for usage details.
93
- def wait_for_no_text(pattern, options={})
94
- builder = JavascriptExpressionBuilder.new
95
- builder.find_text(pattern, options).append("text_match == false;")
96
- wait_for_condition builder.script, options[:timeout_in_seconds]
97
- end
98
-
99
- # Wait for a field to get a specific value (the wait happens in the browser).
100
- def wait_for_field_value(locator, expected_value, options={})
101
- builder = JavascriptExpressionBuilder.new
102
- builder.find_element(locator).element_value_is(expected_value)
103
- wait_for_condition builder.script, options[:timeout_in_seconds]
104
- end
105
-
106
- # Wait for a field to not have a specific value (the wait happens in the browser).
107
- def wait_for_no_field_value(locator, expected_value, options={})
108
- builder = JavascriptExpressionBuilder.new
109
- builder.find_element(locator).element_value_is_not(expected_value)
110
- wait_for_condition builder.script, options[:timeout_in_seconds]
111
- end
112
-
113
- # Wait for something to be visible (the wait happens in the browser).
114
- def wait_for_visible(locator, options={})
115
- builder = JavascriptExpressionBuilder.new
116
- wait_for_condition builder.visible(locator).script, options[:timeout_in_seconds]
117
- end
118
-
119
- # Wait for something to not be visible (the wait happens in the browser).
120
- def wait_for_not_visible(locator, options={})
121
- builder = JavascriptExpressionBuilder.new
122
- wait_for_condition builder.not_visible(locator).script, options[:timeout_in_seconds]
123
- end
124
-
125
- def active_javascript_framework(options)
126
- options[:javascript_framework] || default_javascript_framework
127
- end
128
-
129
- end
130
-
131
- end
132
- end
@@ -1,507 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Licensed to the Software Freedom Conservancy (SFC) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The SFC licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
-
20
- module Selenium
21
- module Client
22
-
23
- # Provide a more idiomatic API than the generated Ruby driver.
24
- #
25
- # Work in progress...
26
- module Idiomatic
27
-
28
- # Return the text content of an HTML element (rendered text shown to
29
- # the user). Works for any HTML element that contains text.
30
- #
31
- #
32
- # This command uses either the textContent (Mozilla-like browsers)
33
- # or the innerText (IE-like browsers) of the element, which is the
34
- # rendered text shown to the user.
35
- #
36
- # * 'locator' is an Selenium element locator
37
- #
38
- def text(locator)
39
- string_command "getText", [locator,]
40
- end
41
- alias :text_content :text
42
-
43
- # Return the title of the current HTML page.
44
- def title
45
- string_command "getTitle"
46
- end
47
-
48
- # Returns the absolute URL of the current page.
49
- def location
50
- string_command "getLocation"
51
- end
52
-
53
- # Waits for a new page to load.
54
- #
55
- # Selenium constantly keeps track of new pages loading, and sets a
56
- # "newPageLoaded" flag when it first notices a page load. Running
57
- # any other Selenium command after turns the flag to false. Hence,
58
- # if you want to wait for a page to load, you must wait immediately
59
- # after a Selenium command that caused a page-load.
60
- #
61
- # * 'timeout_in_seconds' is a timeout in seconds, after which this
62
- # command will return with an error
63
- def wait_for_page(timeout_in_seconds=nil)
64
- remote_control_command "waitForPageToLoad",
65
- [actual_timeout_in_milliseconds(timeout_in_seconds),]
66
- end
67
- alias_method :wait_for_page_to_load, :wait_for_page
68
-
69
- # Waits for a popup window to appear and load up.
70
- #
71
- # window_id is the JavaScript window "name" of the window that will appear (not the text of the title bar)
72
- # timeout_in_seconds is a timeout in seconds, after which the action will return with an error
73
- def wait_for_popup(window_id, timeout_in_seconds=nil)
74
- remote_control_command "waitForPopUp",
75
- [window_id, actual_timeout_in_milliseconds(timeout_in_seconds) ,]
76
- end
77
-
78
- # Flexible wait semantics. ait is happening browser side. Useful for testing AJAX application.
79
- #
80
- # * wait :wait_for => :page # will wait for a new page to load
81
- # * wait :wait_for => :popup, :window => 'a window id' # will wait for a new popup window to appear. Also selects the popup window for you provide `:select => true`
82
- # * wait :wait_for => :ajax # will wait for all ajax requests to be completed using semantics of default javascript framework
83
- # * wait :wait_for => :ajax, :javascript_framework => :jquery # will wait for all ajax requests to be completed overriding default javascript framework
84
- # * wait :wait_for => :effects # will wait for all javascript effects to be rendered using semantics of default javascript framework
85
- # * wait :wait_for => :effects, :javascript_framework => :prototype # will wait for all javascript effects to be rendered overriding default javascript framework
86
- # * wait :wait_for => :element, :element => 'new_element_id' # will wait for an element to be present/appear
87
- # * wait :wait_for => :no_element, :element => 'new_element_id' # will wait for an element to be not be present/disappear
88
- # * wait :wait_for => :text, :text => 'some text' # will wait for some text to be present/appear
89
- # * wait :wait_for => :text, :text => /A Regexp/ # will wait for some text to be present/appear
90
- # * wait :wait_for => :text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to be 'some text'
91
- # * wait :wait_for => :no_text, :text => 'some text' # will wait for the text to be not be present/disappear
92
- # * wait :wait_for => :no_text, :text => /A Regexp/ # will wait for the text to be not be present/disappear
93
- # * wait :wait_for => :no_text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to not be 'some text'
94
- # * wait :wait_for => :value, :element => 'a_locator', :value => 'some value' # will wait for the field value of 'a_locator' to be 'some value'
95
- # * wait :wait_for => :no_value, :element => 'a_locator', :value => 'some value' # will wait for the field value of 'a_locator' to not be 'some value'
96
- # * wait :wait_for => :visible, :element => 'a_locator' # will wait for element to be visible
97
- # * wait :wait_for => :not_visible, :element => 'a_locator' # will wait for element to not be visible
98
- # * wait :wait_for => :condition, :javascript => 'some expression' # will wait for the javascript expression to be true
99
- #
100
- # Using options you can also define an explicit timeout (:timeout_in_seconds key). Otherwise the default driver timeout
101
- # is used.
102
- def wait_for(options)
103
- if options[:wait_for] == :page
104
- wait_for_page options[:timeout_in_seconds]
105
- elsif options[:wait_for] == :ajax
106
- wait_for_ajax options
107
- elsif options[:wait_for] == :element
108
- wait_for_element options[:element], options
109
- elsif options[:wait_for] == :no_element
110
- wait_for_no_element options[:element], options
111
- elsif options[:wait_for] == :text
112
- wait_for_text options[:text], options
113
- elsif options[:wait_for] == :no_text
114
- wait_for_no_text options[:text], options
115
- elsif options[:wait_for] == :effects
116
- wait_for_effects options
117
- elsif options[:wait_for] == :popup
118
- wait_for_popup options[:window], options[:timeout_in_seconds]
119
- select_window options[:window] if options[:select]
120
- elsif options[:wait_for] == :value
121
- wait_for_field_value options[:element], options[:value], options
122
- elsif options[:wait_for] == :no_value
123
- wait_for_no_field_value options[:element], options[:value], options
124
- elsif options[:wait_for] == :visible
125
- wait_for_visible options[:element], options
126
- elsif options[:wait_for] == :not_visible
127
- wait_for_not_visible options[:element], options
128
- elsif options[:wait_for] == :condition
129
- wait_for_condition options[:javascript], options[:timeout_in_seconds]
130
- end
131
- end
132
-
133
- # Gets the entire text of the page.
134
- def body_text
135
- string_command "getBodyText"
136
- end
137
-
138
- # Clicks on a link, button, checkbox or radio button.
139
- #
140
- # 'locator' is an element locator
141
- #
142
- # Using 'options' you can automatically wait for an event to happen after the
143
- # click. e.g.
144
- #
145
- # * click "a_locator", :wait_for => :page # will wait for a new page to load
146
- # * click "a_locator", :wait_for => :popup, :window => 'a window id' # will wait for a new popup window to appear. Also selects the popup window for you provide `:select => true`
147
- # * click "a_locator", :wait_for => :ajax # will wait for all ajax requests to be completed using semantics of default javascript framework
148
- # * click "a_locator", :wait_for => :ajax, :javascript_framework => :jquery # will wait for all ajax requests to be completed overriding default javascript framework
149
- # * click "a_locator", :wait_for => :effects # will wait for all javascript effects to be rendered using semantics of default javascript framework
150
- # * click "a_locator", :wait_for => :effects, :javascript_framework => :prototype # will wait for all javascript effects to be rendered overriding default javascript framework
151
- # * click "a_locator", :wait_for => :element, :element => 'new_element_id' # will wait for an element to be present/appear
152
- # * click "a_locator", :wait_for => :no_element, :element => 'new_element_id' # will wait for an element to be not be present/disappear
153
- # * click "a_locator", :wait_for => :text, :text => 'some text' # will wait for some text to be present/appear
154
- # * click "a_locator", :wait_for => :text, :text => /A Regexp/ # will wait for some text to be present/appear
155
- # * click "a_locator", :wait_for => :text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to be 'some text'
156
- # * click "a_locator", :wait_for => :no_text, :text => 'some text' # will wait for the text to be not be present/disappear
157
- # * click "a_locator", :wait_for => :no_text, :text => /A Regexp/ # will wait for the text to be not be present/disappear
158
- # * click "a_locator", :wait_for => :no_text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to not be 'some text'
159
- # * click "a_locator", :wait_for => :value, :element => 'a_locator', :value => 'some value' # will wait for the field value of 'a_locator' to be 'some value'
160
- # * click "a_locator", :wait_for => :no_value, :element => 'a_locator', :value => 'some value' # will wait for the field value of 'a_locator' to not be 'some value'
161
- # * click "a_locator", :wait_for => :visible, :element => 'a_locator' # will wait for element to be visible
162
- # * click "a_locator", :wait_for => :not_visible, :element => 'a_locator' # will wait for element to not be visible
163
- # * click "a_locator", :wait_for => :condition, :javascript => 'some expression' # will wait for the javascript expression to be true
164
- #
165
- # Using options you can also define an explicit timeout (:timeout_in_seconds key). Otherwise the default driver timeout
166
- # is used.
167
- def click(locator, options={})
168
- remote_control_command "click", [locator,]
169
- wait_for options
170
- end
171
-
172
- # Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
173
- #
174
- # * 'pattern' is a pattern to match with the text of the page
175
- def text?(pattern)
176
- boolean_command "isTextPresent", [pattern,]
177
- end
178
-
179
- # Verifies that the specified element is somewhere on the page.
180
- #
181
- # * 'locator' is an element locator
182
- def element?(locator)
183
- boolean_command "isElementPresent", [locator,]
184
- end
185
-
186
- # Determines if the specified element is visible. An
187
- # element can be rendered invisible by setting the CSS "visibility"
188
- # property to "hidden", or the "display" property to "none", either for the
189
- # element itself or one if its ancestors. This method will fail if
190
- # the element is not present.
191
- #
192
- # 'locator' is an element locator
193
- def visible?(locator)
194
- boolean_command "isVisible", [locator,]
195
- end
196
-
197
- # Gets the (whitespace-trimmed) value of an input field
198
- # (or anything else with a value parameter).
199
- # For checkbox/radio elements, the value will be "on" or "off"
200
- # depending on whether the element is checked or not.
201
- #
202
- # * 'locator' is an element locator
203
- def field(locator)
204
- string_command "getValue", [locator,]
205
- end
206
-
207
- # Alias for +field+
208
- def value(locator)
209
- field locator
210
- end
211
-
212
- # Returns whether a toggle-button (checkbox/radio) is checked.
213
- # Fails if the specified element doesn't exist or isn't a toggle-button.
214
- #
215
- # * 'locator' is an element locator pointing to a checkbox or radio button
216
- def checked?(locator)
217
- boolean_command "isChecked", [locator,]
218
- end
219
-
220
- # Whether an alert occurred
221
- def alert?
222
- boolean_command "isAlertPresent"
223
- end
224
-
225
- # Retrieves the message of a JavaScript alert generated during the previous action,
226
- # or fail if there were no alerts.
227
- #
228
- # Getting an alert has the same effect as manually clicking OK. If an
229
- # alert is generated but you do not consume it with getAlert, the next Selenium action
230
- # will fail.
231
- #
232
- # Under Selenium, JavaScript alerts will NOT pop up a visible alert
233
- # dialog.
234
- #
235
- # Selenium does NOT support JavaScript alerts that are generated in a
236
- # page's onload() event handler. In this case a visible dialog WILL be
237
- # generated and Selenium will hang until someone manually clicks OK.
238
- #
239
- def alert
240
- string_command "getAlert"
241
- end
242
-
243
- # Whether a confirmation has been auto-acknoledged (i.e. confirm() been called)
244
- def confirmation?
245
- boolean_command "isConfirmationPresent"
246
- end
247
-
248
- # Retrieves the message of a JavaScript confirmation dialog generated during
249
- # the previous action.
250
- #
251
- # By default, the confirm function will return true, having the same effect
252
- # as manually clicking OK. This can be changed by prior execution of the
253
- # chooseCancelOnNextConfirmation command.
254
- #
255
- # If an confirmation is generated but you do not consume it with getConfirmation,
256
- # the next Selenium action will fail.
257
- #
258
- # NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible
259
- # dialog.
260
- #
261
- # NOTE: Selenium does NOT support JavaScript confirmations that are
262
- # generated in a page's onload() event handler. In this case a visible
263
- # dialog WILL be generated and Selenium will hang until you manually click
264
- # OK.
265
- def confirmation
266
- string_command "getConfirmation"
267
- end
268
-
269
- # Whether a prompt occurred
270
- def prompt?
271
- boolean_command "isPromptPresent"
272
- end
273
-
274
- # Retrieves the message of a JavaScript question prompt dialog generated during
275
- # the previous action.
276
- #
277
- # Successful handling of the prompt requires prior execution of the
278
- # answerOnNextPrompt command. If a prompt is generated but you
279
- # do not get/verify it, the next Selenium action will fail.
280
- #
281
- # NOTE: under Selenium, JavaScript prompts will NOT pop up a visible
282
- # dialog.
283
- #
284
- # NOTE: Selenium does NOT support JavaScript prompts that are generated in a
285
- # page's onload() event handler. In this case a visible dialog WILL be
286
- # generated and Selenium will hang until someone manually clicks OK.
287
- def prompt
288
- string_command "getPrompt"
289
- end
290
-
291
- # Returns the result of evaluating the specified JavaScript snippet whithin the browser.
292
- # The snippet may have multiple lines, but only the result of the last line will be returned.
293
- #
294
- # Note that, by default, the snippet will run in the context of the "selenium"
295
- # object itself, so <tt>this</tt> will refer to the Selenium object. Use <tt>window</tt> to
296
- # refer to the window of your application, e.g. <tt>window.document.getElementById('foo')</tt>
297
- # If you need to use
298
- # a locator to refer to a single element in your application page, you can
299
- # use <tt>this.browserbot.findElement("id=foo")</tt> where "id=foo" is your locator.
300
- #
301
- # * 'script' is the JavaScript snippet to run
302
- def js_eval(script)
303
- string_command "getEval", [script,]
304
- end
305
-
306
- # Set the Remote Control timeout (as opposed to the client side driver timeout).
307
- # This timout specifies the amount of time that Selenium Core will wait for actions to complete.
308
- #
309
- # The default timeout is 30 seconds.
310
- # 'timeout' is a timeout in seconds, after which the action will return with an error
311
- #
312
- # Actions that require waiting include "open" and the "waitFor*" actions.
313
- def remote_control_timeout_in_seconds=(timeout_in_seconds)
314
- remote_control_command "setTimeout", [actual_timeout_in_milliseconds(timeout_in_seconds),]
315
- end
316
-
317
- # Returns the text from a cell of a table. The cellAddress syntax
318
- # tableLocator.row.column, where row and column start at 0.
319
- #
320
- # * 'tableCellAddress' is a cell address, e.g. "foo.1.4"
321
- def table_cell_text(tableCellAddress)
322
- string_command "getTable", [tableCellAddress,]
323
- end
324
-
325
- # Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
326
- # The snippet may have multiple lines, but only the result of the last line
327
- # will be considered.
328
- #
329
- # Note that, by default, the snippet will be run in the runner's test window, not in the window
330
- # of your application. To get the window of your application, you can use
331
- # the JavaScript snippet <tt>selenium.browserbot.getCurrentWindow()</tt>, and then
332
- # run your JavaScript in there
333
- #
334
- #
335
- # * 'script' is the JavaScript snippet to run
336
- # * 'timeout_in_seconds' is a timeout in seconds, after which this command will return with an error
337
- def wait_for_condition(script, timeout_in_seconds = nil)
338
- remote_control_command "waitForCondition",
339
- [script, actual_timeout_in_milliseconds(timeout_in_seconds),]
340
- end
341
-
342
- # Simulates the user clicking the "back" button on their browser.
343
- # Using 'options' you can automatically wait for an event to happen after the
344
- # click. e.g.
345
- #
346
- # * go_back :wait_for => :page # will wait for a new page to load
347
- # * go_back :wait_for => :popup, :window => 'a window id' # will wait for a new popup window to appear. Also selects the popup window for you provide `:select => true`
348
- # * go_back :wait_for => :ajax # will wait for all ajax requests to be completed using semantics of default javascript framework
349
- # * go_back :wait_for => :ajax, :javascript_framework => :jquery # will wait for all ajax requests to be completed overriding default javascript framework
350
- # * go_back :wait_for => :effects # will wait for all javascript effects to be rendered using semantics of default javascript framework
351
- # * go_back :wait_for => :effects, :javascript_framework => :prototype # will wait for all javascript effects to be rendered overriding default javascript framework
352
- # * go_back :wait_for => :element, :element => 'new_element_id' # will wait for an element to be present/appear
353
- # * go_back :wait_for => :no_element, :element => 'new_element_id' # will wait for an element to be not be present/disappear
354
- # * go_back :wait_for => :text, :text => 'some text' # will wait for some text to be present/appear
355
- # * go_back "a_locator", :wait_for => :text, :text => /A Regexp/ # will wait for some text to be present/appear
356
- # * go_back :wait_for => :text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to be 'some text'
357
- # * go_back :wait_for => :no_text, :text => 'some text' # will wait for the text to be not be present/disappear
358
- # * go_back "a_locator", :wait_for => :no_text, :text => /A Regexp/ # will wait for the text to be not be present/disappear
359
- # * go_back :wait_for => :no_text, :element => 'a_locator', :text => 'some text' # will wait for the content of 'a_locator' to not be 'some text'
360
- # * go_back :wait_for => :condition, :javascript => 'some expression' # will wait for the javascript expression to be true
361
- # * go_back :wait_for => :value, :element => 'a_locator', :value => 'some value' # will wait for the field value of 'a_locator' to be 'some value'
362
- # * go_back :wait_for => :visible, :element => 'a_locator' # will wait for element to be visible
363
- # * go_back :wait_for => :not_visible, :element => 'a_locator' # will wait for element to not be visible
364
- # * go_back :wait_for => :no_value, :element => 'a_locator', :value => 'some value' # will wait for the field value of 'a_locator' to not be 'some value'
365
- #
366
- # Using options you can also define an explicit timeout (:timeout_in_seconds key). Otherwise the default driver timeout
367
- # is used.
368
- def go_back(options={})
369
- remote_control_command "goBack"
370
- wait_for options
371
- end
372
-
373
- # Return all cookies for the current page under test.
374
- def cookies
375
- string_command "getCookie"
376
- end
377
-
378
- # Returns the value of the cookie with the specified name, or throws an error if the cookie is not present.
379
- #
380
- # 'name' is the name of the cookie
381
- def cookie(name)
382
- string_command "getCookieByName", [name,]
383
- end
384
-
385
- # Returns true if a cookie with the specified name is present, or false otherwise.
386
- #
387
- # 'name' is the name of the cookie
388
- def cookie?(name)
389
- boolean_command "isCookiePresent", [name,]
390
- end
391
-
392
- # Create a new cookie whose path and domain are same with those of current page
393
- # under test, unless you specified a path for this cookie explicitly.
394
- #
395
- # 'nameValuePair' is name and value of the cookie in a format "name=value"
396
- # 'optionsString' is options for the cookie. Currently supported options include 'path', 'max_age' and 'domain'.
397
- # the optionsString's format is "path=/path/, max_age=60, domain=.foo.com". The order of options are irrelevant, the unit of the value of 'max_age' is second. Note that specifying a domain that isn't a subset of the current domain will usually fail.
398
- def create_cookie(name_value_pair, options="")
399
- if options.kind_of? Hash
400
- options = options.keys.collect {|key| "#{key}=#{options[key]}" }.sort.join(", ")
401
- end
402
- remote_control_command "createCookie", [name_value_pair,options,]
403
- end
404
-
405
- # Delete a named cookie with specified path and domain. Be careful; to delete a cookie, you
406
- # need to delete it using the exact same path and domain that were used to create the cookie.
407
- # If the path is wrong, or the domain is wrong, the cookie simply won't be deleted. Also
408
- # note that specifying a domain that isn't a subset of the current domain will usually fail.
409
- #
410
- # Since there's no way to discover at runtime the original path and domain of a given cookie,
411
- # we've added an option called 'recurse' to try all sub-domains of the current domain with
412
- # all paths that are a subset of the current path. Beware; this option can be slow. In
413
- # big-O notation, it operates in O(n*m) time, where n is the number of dots in the domain
414
- # name and m is the number of slashes in the path.
415
- #
416
- # 'name' is the name of the cookie to be deleted
417
- # 'optionsString' is options for the cookie. Currently supported options include 'path', 'domain' and 'recurse.' The optionsString's format is "path=/path/, domain=.foo.com, recurse=true". The order of options are irrelevant. Note that specifying a domain that isn't a subset of the current domain will usually fail.
418
- def delete_cookie(name, options="")
419
- if options.kind_of? Hash
420
- ordered_keys = options.keys.sort {|a,b| a.to_s <=> b.to_s }
421
- options = ordered_keys.collect {|key| "#{key}=#{options[key]}" }.join(", ")
422
- end
423
- remote_control_command "deleteCookie", [name,options,]
424
- end
425
-
426
- # Returns the IDs of all windows that the browser knows about.
427
- def all_window_ids
428
- string_array_command "getAllWindowIds"
429
- end
430
-
431
-
432
- # Returns the names of all windows that the browser knows about.
433
- def all_window_names
434
- string_array_command "getAllWindowNames"
435
- end
436
-
437
-
438
- # Returns the titles of all windows that the browser knows about.
439
- def all_window_titles
440
- string_array_command "getAllWindowTitles"
441
- end
442
-
443
- # Returns a string representation of the network traffic seen by the
444
- # browser, including headers, AJAX requests, status codes, and timings.
445
- # When this function is called, the traffic log is cleared, so the
446
- # returned content is only the traffic seen since the last call.
447
- #
448
- # The network traffic is returned in the format it was requested. Valid
449
- # values are: :json, :xml, or :plain.
450
- #
451
- # Warning: For browser_network_traffic to work you need to start your
452
- # browser session with the option "captureNetworkTraffic=true", which
453
- # will force ALL traffic to go to the Remote Control proxy even for
454
- # more efficient browser modes like `*firefox` and `*safari`.
455
- def browser_network_traffic(format = :plain)
456
- raise "format must be :plain, :json, or :xml" \
457
- unless [:plain, :json, :xml].include?(format)
458
-
459
- remote_control_command "captureNetworkTraffic", [format.to_s]
460
- end
461
-
462
- # Allows choice of a specific XPath libraries for Xpath evualuation
463
- # in the browser (e.g. to resolve XPath locators).
464
- #
465
- # `library_name' can be:
466
- # * :ajaxslt : Google's library
467
- # * :javascript-xpath : Cybozu Labs' faster library
468
- # * :default : Selenium default library.
469
- def browser_xpath_library=(library_name)
470
- raise "library name must be :ajaxslt, :javascript-xpath, or :default" \
471
- unless [:ajaxslt, :'javascript-xpath', :default].include?(library_name)
472
- remote_control_command "useXpathLibrary", [library_name.to_s]
473
- end
474
-
475
- #
476
- # Turn on/off the automatic hightlighting of the element driven or
477
- # inspected by Selenium core. Useful when recording videos
478
- #
479
- def highlight_located_element=(enabled)
480
- boolean = (true == enabled)
481
- js_eval "selenium.browserbot.shouldHighlightLocatedElement = #{boolean}"
482
- end
483
-
484
- # Get execution delay in milliseconds, i.e. a pause delay following
485
- # each selenium operation. By default, there is no such delay
486
- # (value is 0).
487
- def execution_delay
488
- string_command "getSpeed"
489
- end
490
-
491
- # Set the execution delay in milliseconds, i.e. a pause delay following
492
- # each selenium operation. By default, there is no such delay.
493
- #
494
- # Setting an execution can be useful to troubleshoot or capture videos
495
- def execution_delay=(delay_in_milliseconds)
496
- remote_control_command "setSpeed", [delay_in_milliseconds]
497
- end
498
-
499
- def actual_timeout_in_milliseconds(timeout_in_seconds)
500
- actual_timeout = (timeout_in_seconds ||
501
- default_timeout_in_seconds).to_i
502
- actual_timeout * 1000
503
- end
504
- end
505
-
506
- end
507
- end