selenium-client 1.2 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
data/lib/selenium.rb
CHANGED
@@ -27,8 +27,9 @@ require File.expand_path(File.dirname(__FILE__) + '/tcp_socket_extension')
|
|
27
27
|
require File.expand_path(File.dirname(__FILE__) + '/nautilus/shell')
|
28
28
|
require File.expand_path(File.dirname(__FILE__) + '/selenium/command_error')
|
29
29
|
require File.expand_path(File.dirname(__FILE__) + '/selenium/protocol_error')
|
30
|
-
require File.expand_path(File.dirname(__FILE__) + '/selenium/client/
|
30
|
+
require File.expand_path(File.dirname(__FILE__) + '/selenium/client/protocol')
|
31
31
|
require File.expand_path(File.dirname(__FILE__) + '/selenium/client/generated_driver')
|
32
|
+
require File.expand_path(File.dirname(__FILE__) + '/selenium/client/extensions')
|
32
33
|
require File.expand_path(File.dirname(__FILE__) + '/selenium/client/idiomatic')
|
33
34
|
require File.expand_path(File.dirname(__FILE__) + '/selenium/client/base')
|
34
35
|
require File.expand_path(File.dirname(__FILE__) + '/selenium/client/driver')
|
data/lib/selenium/client/base.rb
CHANGED
@@ -1,27 +1,14 @@
|
|
1
|
-
# Copyright 2006 ThoughtWorks, Inc
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# Original code by Aslak Hellesoy and Darren Hobbs
|
18
|
-
#
|
19
1
|
module Selenium
|
20
2
|
module Client
|
21
3
|
|
4
|
+
# Driver constructor and session management commands
|
5
|
+
#
|
6
|
+
# Original code by Aslak Hellesoy and Darren Hobbs
|
22
7
|
module Base
|
23
|
-
include Selenium::Client::
|
8
|
+
include Selenium::Client::Protocol
|
24
9
|
include Selenium::Client::GeneratedDriver
|
10
|
+
include Selenium::Client::Extensions
|
11
|
+
include Selenium::Client::Idiomatic
|
25
12
|
|
26
13
|
def initialize(server_host, server_port, browser_string, browser_url, timeout_in_seconds=300)
|
27
14
|
@server_host = server_host
|
@@ -33,39 +20,42 @@ module Selenium
|
|
33
20
|
@session_id = nil
|
34
21
|
end
|
35
22
|
|
36
|
-
def
|
37
|
-
@
|
38
|
-
end
|
39
|
-
|
40
|
-
def start()
|
41
|
-
result = get_string("getNewBrowserSession", [@browser_string, @browser_url, @extension_js])
|
42
|
-
@session_id = result
|
43
|
-
end
|
44
|
-
|
45
|
-
def stop()
|
46
|
-
do_command("testComplete", [])
|
47
|
-
@session_id = nil
|
23
|
+
def session_started?
|
24
|
+
not @session_id.nil?
|
48
25
|
end
|
49
26
|
|
50
27
|
def start_new_browser_session
|
51
|
-
|
28
|
+
result = string_command "getNewBrowserSession", [@browser_string, @browser_url, @extension_js]
|
29
|
+
@session_id = result
|
30
|
+
# Consistent timeout on the remote control and driver side.
|
31
|
+
# Intuitive and this is what you want 90% of the time
|
32
|
+
self.remote_control_timeout_in_seconds = @timeout
|
52
33
|
end
|
53
34
|
|
54
35
|
def close_current_browser_session
|
55
|
-
|
36
|
+
remote_control_command "testComplete"
|
37
|
+
@session_id = nil
|
56
38
|
end
|
57
39
|
|
58
|
-
def
|
59
|
-
|
40
|
+
def start
|
41
|
+
start_new_browser_session
|
60
42
|
end
|
61
43
|
|
62
|
-
def
|
63
|
-
|
44
|
+
def stop
|
45
|
+
close_current_browser_session
|
64
46
|
end
|
65
|
-
|
47
|
+
|
66
48
|
def chrome_backend?
|
67
49
|
["*chrome", "*firefox", "*firefox2", "*firefox3"].include?(@browser_string)
|
68
50
|
end
|
51
|
+
|
52
|
+
def javascript_extension=(new_javascript_extension)
|
53
|
+
@extension_js = new_javascript_extension
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_extension_js(new_javascript_extension)
|
57
|
+
javascript_extension = new_javascript_extension
|
58
|
+
end
|
69
59
|
|
70
60
|
end
|
71
61
|
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Selenium
|
2
|
+
module Client
|
3
|
+
|
4
|
+
# Convenience methods not explicitely part of the protocol
|
5
|
+
module Extensions
|
6
|
+
|
7
|
+
# These for all Ajax request to finish (Only works if you are using prototype)
|
8
|
+
#
|
9
|
+
# See http://davidvollbracht.com/2008/6/4/30-days-of-tech-day-3-waitforajax for
|
10
|
+
# more background.
|
11
|
+
def wait_for_ajax(timeout=nil)
|
12
|
+
selenium.wait_for_condition "selenium.browserbot.getCurrentWindow().Ajax.activeRequestCount == 0",
|
13
|
+
timeout || default_timeout_in_seconds
|
14
|
+
end
|
15
|
+
|
16
|
+
# Wait for all Prototype effects to be processed
|
17
|
+
#
|
18
|
+
# Credits to http://github.com/brynary/webrat/tree/master
|
19
|
+
def wait_for_effects(timeout=nil)
|
20
|
+
selenium.wait_for_condition "window.Effect.Queue.size() == 0", timeout || default_timeout_in_seconds
|
21
|
+
end
|
22
|
+
|
23
|
+
def wait_for_element(field_name, time=60000)
|
24
|
+
script = <<-EOS
|
25
|
+
var element;
|
26
|
+
try {
|
27
|
+
element = selenium.browserbot.findElement('#{field_name}');
|
28
|
+
} catch(e) {
|
29
|
+
element = null;
|
30
|
+
}
|
31
|
+
element != null
|
32
|
+
EOS
|
33
|
+
|
34
|
+
wait_for_condition script, time
|
35
|
+
end
|
36
|
+
|
37
|
+
def wait_for_text(field_name, text, time=60000)
|
38
|
+
script = "var element;
|
39
|
+
try {
|
40
|
+
element = selenium.browserbot.findElement('#{field_name}');
|
41
|
+
} catch(e) {
|
42
|
+
element = null;
|
43
|
+
}
|
44
|
+
element != null && element.innerHTML == '#{text}'"
|
45
|
+
|
46
|
+
wait_for_condition script, time
|
47
|
+
end
|
48
|
+
|
49
|
+
def wait_for_text_change(field_name, original_text, time=60000)
|
50
|
+
script = "var element;
|
51
|
+
try {
|
52
|
+
element = selenium.browserbot.findElement('#{field_name}');
|
53
|
+
} catch(e) {
|
54
|
+
element = null;
|
55
|
+
}
|
56
|
+
element != null && element.innerHTML != '#{original_text}'"
|
57
|
+
|
58
|
+
wait_for_condition script, time
|
59
|
+
end
|
60
|
+
|
61
|
+
def wait_for_field_value(field_name, value, time=60000)
|
62
|
+
script = "var element;
|
63
|
+
try {
|
64
|
+
element = selenium.browserbot.findElement('#{field_name}');
|
65
|
+
} catch(e) {
|
66
|
+
element = null;
|
67
|
+
}
|
68
|
+
element != null && element.value == '#{value}'"
|
69
|
+
|
70
|
+
wait_for_condition script, time
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -1,11 +1,9 @@
|
|
1
|
-
#
|
2
|
-
# Provide a more idiomatic API than the generated Ruby driver.
|
3
|
-
#
|
4
|
-
# Work on progress...
|
5
|
-
#
|
6
1
|
module Selenium
|
7
2
|
module Client
|
8
3
|
|
4
|
+
# Provide a more idiomatic API than the generated Ruby driver.
|
5
|
+
#
|
6
|
+
# Work in progress...
|
9
7
|
module Idiomatic
|
10
8
|
|
11
9
|
# Return the text content of an HTML element (rendered text shown to
|
@@ -18,17 +16,17 @@ module Selenium
|
|
18
16
|
#
|
19
17
|
# 'locator' is an Selenium element locator
|
20
18
|
def text_content(locator)
|
21
|
-
|
19
|
+
string_command"getText", [locator,]
|
22
20
|
end
|
23
21
|
|
24
22
|
# Return the title of the current HTML page.
|
25
23
|
def title
|
26
|
-
|
24
|
+
string_command"getTitle"
|
27
25
|
end
|
28
26
|
|
29
27
|
# Returns the absolute URL of the current page.
|
30
28
|
def location
|
31
|
-
|
29
|
+
string_command"getLocation"
|
32
30
|
end
|
33
31
|
|
34
32
|
# Waits for a new page to load.
|
@@ -43,12 +41,12 @@ module Selenium
|
|
43
41
|
# command will return with an error
|
44
42
|
def wait_for_page(timeout_in_seconds=nil)
|
45
43
|
actual_timeout = timeout_in_seconds || default_timeout_in_seconds
|
46
|
-
|
44
|
+
remote_control_command "waitForPageToLoad", [actual_timeout * 1000,]
|
47
45
|
end
|
48
46
|
|
49
47
|
# Gets the entire text of the page.
|
50
48
|
def body_text
|
51
|
-
|
49
|
+
string_command"getBodyText"
|
52
50
|
end
|
53
51
|
|
54
52
|
# Clicks on a link, button, checkbox or radio button. If the click action
|
@@ -57,9 +55,13 @@ module Selenium
|
|
57
55
|
#
|
58
56
|
# 'locator' is an element locator
|
59
57
|
def click(locator, options={})
|
60
|
-
|
58
|
+
remote_control_command("click", [locator,])
|
61
59
|
if options[:wait_for] == :page
|
62
60
|
wait_for_page options[:timeout_in_seconds]
|
61
|
+
elsif options[:wait_for] == :ajax
|
62
|
+
wait_for_ajax options[:timeout_in_seconds]
|
63
|
+
elsif options[:wait_for] == :effects
|
64
|
+
wait_for_effects options[:timeout_in_seconds]
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
@@ -67,14 +69,14 @@ module Selenium
|
|
67
69
|
#
|
68
70
|
# 'pattern' is a pattern to match with the text of the page
|
69
71
|
def text_present?(pattern)
|
70
|
-
|
72
|
+
boolean_command "isTextPresent", [pattern,]
|
71
73
|
end
|
72
74
|
|
73
75
|
# Verifies that the specified element is somewhere on the page.
|
74
76
|
#
|
75
77
|
# 'locator' is an element locator
|
76
78
|
def element_present?(locator)
|
77
|
-
|
79
|
+
boolean_command "isElementPresent", [locator,]
|
78
80
|
end
|
79
81
|
|
80
82
|
# Gets the (whitespace-trimmed) value of an input field
|
@@ -83,13 +85,26 @@ module Selenium
|
|
83
85
|
# depending on whether the element is checked or not.
|
84
86
|
#
|
85
87
|
# 'locator' is an element locator
|
88
|
+
def field(locator)
|
89
|
+
string_command "getValue", [locator,]
|
90
|
+
end
|
91
|
+
|
92
|
+
# Alias for +field+
|
86
93
|
def value(locator)
|
87
|
-
|
94
|
+
field locator
|
95
|
+
end
|
96
|
+
|
97
|
+
# Returns whether a toggle-button (checkbox/radio) is checked.
|
98
|
+
# Fails if the specified element doesn't exist or isn't a toggle-button.
|
99
|
+
#
|
100
|
+
# 'locator' is an element locator pointing to a checkbox or radio button
|
101
|
+
def checked?(locator)
|
102
|
+
boolean_command "isChecked", [locator,]
|
88
103
|
end
|
89
104
|
|
90
105
|
# Whether an alert occurred
|
91
106
|
def alert?
|
92
|
-
|
107
|
+
boolean_command "isAlertPresent"
|
93
108
|
end
|
94
109
|
|
95
110
|
# Retrieves the message of a JavaScript alert generated during the previous action,
|
@@ -105,12 +120,12 @@ module Selenium
|
|
105
120
|
# generated and Selenium will hang until someone manually clicks OK.
|
106
121
|
#
|
107
122
|
def alert
|
108
|
-
|
123
|
+
string_command"getAlert"
|
109
124
|
end
|
110
125
|
|
111
126
|
# Whether a confirmation has been auto-acknoledged (i.e. confirm() been called)
|
112
127
|
def confirmation?
|
113
|
-
|
128
|
+
boolean_command "isConfirmationPresent"
|
114
129
|
end
|
115
130
|
|
116
131
|
# Retrieves the message of a JavaScript confirmation dialog generated during
|
@@ -131,12 +146,12 @@ module Selenium
|
|
131
146
|
# dialog WILL be generated and Selenium will hang until you manually click
|
132
147
|
# OK.
|
133
148
|
def confirmation
|
134
|
-
|
149
|
+
string_command"getConfirmation"
|
135
150
|
end
|
136
151
|
|
137
152
|
# Whether a prompt occurred
|
138
153
|
def prompt?
|
139
|
-
|
154
|
+
boolean_command "isPromptPresent"
|
140
155
|
end
|
141
156
|
|
142
157
|
# Retrieves the message of a JavaScript question prompt dialog generated during
|
@@ -153,7 +168,7 @@ module Selenium
|
|
153
168
|
# page's onload() event handler. In this case a visible dialog WILL be
|
154
169
|
# generated and Selenium will hang until someone manually clicks OK.
|
155
170
|
def prompt
|
156
|
-
|
171
|
+
string_command"getPrompt"
|
157
172
|
end
|
158
173
|
|
159
174
|
# Returns the result of evaluating the specified JavaScript snippet whithin the browser.
|
@@ -168,9 +183,27 @@ module Selenium
|
|
168
183
|
#
|
169
184
|
# 'script' is the JavaScript snippet to run
|
170
185
|
def js_eval(script)
|
171
|
-
|
186
|
+
string_command"getEval", [script,]
|
172
187
|
end
|
173
188
|
|
189
|
+
# Set the Remote Control timeout (as opposed to the client side driver timeout).
|
190
|
+
# This timout specifies the amount of time that Selenium Core will wait for actions to complete.
|
191
|
+
#
|
192
|
+
# The default timeout is 30 seconds.
|
193
|
+
# 'timeout' is a timeout in seconds, after which the action will return with an error
|
194
|
+
#
|
195
|
+
# Actions that require waiting include "open" and the "waitFor*" actions.
|
196
|
+
def remote_control_timeout_in_seconds=(timeout_in_seconds)
|
197
|
+
remote_control_command "setTimeout", [timeout_in_seconds * 1000,]
|
198
|
+
end
|
199
|
+
|
200
|
+
# Returns the text from a cell of a table. The cellAddress syntax
|
201
|
+
# tableLocator.row.column, where row and column start at 0.
|
202
|
+
#
|
203
|
+
# 'tableCellAddress' is a cell address, e.g. "foo.1.4"
|
204
|
+
def table_cell_text(tableCellAddress)
|
205
|
+
string_command "getTable", [tableCellAddress,]
|
206
|
+
end
|
174
207
|
|
175
208
|
# set speed
|
176
209
|
end
|
@@ -3,10 +3,11 @@ module Selenium
|
|
3
3
|
|
4
4
|
HTTP_HEADERS = { 'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8' }
|
5
5
|
|
6
|
-
|
6
|
+
# Module in charge of handling Selenium over-the-wire HTTP protocol
|
7
|
+
module Protocol
|
7
8
|
attr_reader :session_id
|
8
9
|
|
9
|
-
def
|
10
|
+
def remote_control_command(verb, args=[])
|
10
11
|
timeout(default_timeout_in_seconds) do
|
11
12
|
status, response = http_post(http_request_for(verb, args))
|
12
13
|
raise SeleniumCommandError, response unless status == "OK"
|
@@ -14,12 +15,12 @@ module Selenium
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
-
|
18
|
+
def string_command(verb, args=[])
|
19
|
+
remote_control_command(verb, args)
|
19
20
|
end
|
20
21
|
|
21
|
-
def
|
22
|
-
csv =
|
22
|
+
def string_array_command(verb, args)
|
23
|
+
csv = string_command(verb, args)
|
23
24
|
token = ""
|
24
25
|
tokens = []
|
25
26
|
escape = false
|
@@ -43,24 +44,26 @@ module Selenium
|
|
43
44
|
return tokens
|
44
45
|
end
|
45
46
|
|
46
|
-
def
|
47
|
-
|
48
|
-
return get_string(verb, args)
|
47
|
+
def number_command(verb, args)
|
48
|
+
string_command verb, args
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
52
|
-
|
53
|
-
return get_string_array(verb, args)
|
51
|
+
def number_array_command(verb, args)
|
52
|
+
string_array_command verb, args
|
54
53
|
end
|
55
54
|
|
56
|
-
def
|
57
|
-
parse_boolean_value
|
55
|
+
def boolean_command(verb, args=[])
|
56
|
+
parse_boolean_value string_command(verb, args)
|
58
57
|
end
|
59
58
|
|
60
|
-
def
|
61
|
-
|
59
|
+
def boolean_array_command(verb, args)
|
60
|
+
string_array_command(verb, args).collect {|value| parse_boolean_value(value)}
|
62
61
|
end
|
63
|
-
|
62
|
+
|
63
|
+
def default_timeout_in_seconds
|
64
|
+
@timeout
|
65
|
+
end
|
66
|
+
|
64
67
|
protected
|
65
68
|
|
66
69
|
def parse_boolean_value(value)
|
@@ -88,7 +91,7 @@ module Selenium
|
|
88
91
|
# puts "RESULT: #{response.inspect}\n"
|
89
92
|
[ response.body[0..1], response.body[3..-1] ]
|
90
93
|
end
|
91
|
-
|
94
|
+
|
92
95
|
end
|
93
96
|
|
94
97
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: selenium-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OpenQA
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-09-
|
12
|
+
date: 2008-09-29 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -25,8 +25,9 @@ files:
|
|
25
25
|
- lib/nautilus/shell.rb
|
26
26
|
- lib/selenium/client/base.rb
|
27
27
|
- lib/selenium/client/driver.rb
|
28
|
+
- lib/selenium/client/extensions.rb
|
28
29
|
- lib/selenium/client/idiomatic.rb
|
29
|
-
- lib/selenium/client/
|
30
|
+
- lib/selenium/client/protocol.rb
|
30
31
|
- lib/selenium/client/selenium_helper.rb
|
31
32
|
- lib/selenium/command_error.rb
|
32
33
|
- lib/selenium/protocol_error.rb
|