jacobdam-selenium 1.1.16
Sign up to get free protection for your applications and to get access to all the features.
- data/README +17 -0
- data/lib/selenium.rb +17 -0
- data/lib/selenium/alert.rb +15 -0
- data/lib/selenium/auto_it.rb +6 -0
- data/lib/selenium/auto_it_driver.rb +45 -0
- data/lib/selenium/auto_it_window.rb +86 -0
- data/lib/selenium/autoit/AutoItX3.dll +0 -0
- data/lib/selenium/button.rb +7 -0
- data/lib/selenium/file_upload.rb +16 -0
- data/lib/selenium/html_element.rb +42 -0
- data/lib/selenium/key.rb +16 -0
- data/lib/selenium/link.rb +31 -0
- data/lib/selenium/openqa/selenium-server.jar.txt +0 -0
- data/lib/selenium/openqa/selenium.rb +1689 -0
- data/lib/selenium/openqa/sslSupport/cybervillainsCA.cer +0 -0
- data/lib/selenium/selenium_server.rb +86 -0
- data/lib/selenium/server.rb +124 -0
- data/lib/selenium/server_manager.rb +10 -0
- data/lib/selenium/text_area.rb +15 -0
- data/lib/selenium/text_field.rb +16 -0
- data/lib/selenium/web_page.rb +214 -0
- data/spec/selenium/examples/selenium_ruby.rb +9 -0
- data/spec/selenium/examples/selenium_ruby/directory_listing_page.rb +9 -0
- data/spec/selenium/examples/selenium_ruby/download_page.rb +11 -0
- data/spec/selenium/examples/selenium_ruby/home_page.rb +13 -0
- data/spec/selenium/examples/selenium_ruby/license_page.rb +11 -0
- data/spec/selenium/examples/selenium_ruby/menu.rb +29 -0
- data/spec/selenium/examples/selenium_ruby/selenium_ruby_page.rb +18 -0
- data/spec/selenium/manual_tc_file_upload.rb +53 -0
- data/spec/selenium/manual_tc_timout.rb +37 -0
- data/spec/selenium/selenium.rb +8 -0
- data/spec/selenium/tc_auto_it.rb +18 -0
- data/spec/selenium/tc_auto_it_window.rb +19 -0
- data/spec/selenium/tc_basic_operation.rb +37 -0
- data/spec/selenium/tc_domain_example.rb +58 -0
- data/spec/selenium/tc_html_element.rb +32 -0
- data/spec/selenium/tc_interaction_example.rb +30 -0
- data/spec/selenium/tc_server.rb +24 -0
- data/spec/selenium/tc_web_page.rb +113 -0
- data/spec/ts_selenium.rb +6 -0
- metadata +94 -0
Binary file
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module Selenium
|
4
|
+
|
5
|
+
# Selenium server driver that provides API to start/stop server and check if
|
6
|
+
# server is running.
|
7
|
+
# NOTE: The start does not return until the server shuts down.
|
8
|
+
class SeleniumServer
|
9
|
+
|
10
|
+
def SeleniumServer::run(argv, vmparameter='')
|
11
|
+
jar_file = SeleniumServer.jar_file
|
12
|
+
if (argv[0] == '-stop')
|
13
|
+
server = SeleniumServer.new(argv[1])
|
14
|
+
puts "stopping server on port #{server.port_number}"
|
15
|
+
server.stop
|
16
|
+
elsif argv[0] == '-check'
|
17
|
+
server = SeleniumServer.new(argv[1])
|
18
|
+
if (server.running?)
|
19
|
+
puts "server running on #{server.port_number}"
|
20
|
+
else
|
21
|
+
puts "server not running on #{server.port_number}"
|
22
|
+
end
|
23
|
+
else
|
24
|
+
command = "java #{vmparameter} -jar #{jar_file} #{argv.join(' ')}"
|
25
|
+
puts command
|
26
|
+
system(command)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def SeleniumServer::jar_file
|
32
|
+
File.join(File.dirname(__FILE__), 'openqa', 'selenium-server.jar.txt')
|
33
|
+
end
|
34
|
+
|
35
|
+
public
|
36
|
+
attr_reader :port_number, :request_timeout
|
37
|
+
# Turn off INFO level server logs, only WARN and above message will be printed
|
38
|
+
attr_accessor :print_log
|
39
|
+
|
40
|
+
# Initialize the server driver with an opitonal port number (default to 4444)
|
41
|
+
# and request timeout (default to 30)
|
42
|
+
def initialize(port_number_to_use = 4444, request_timeout=30)
|
43
|
+
port_number_to_use = 4444 unless port_number_to_use
|
44
|
+
@port_number = port_number_to_use
|
45
|
+
@request_timeout = request_timeout
|
46
|
+
@print_log = false
|
47
|
+
end
|
48
|
+
|
49
|
+
def port_number
|
50
|
+
@port_number
|
51
|
+
end
|
52
|
+
|
53
|
+
# Starts the Selenium server. This does not return until the server is shutdown.
|
54
|
+
def start(*argv)
|
55
|
+
logging_option = ''
|
56
|
+
logging_option = '-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog -Dorg.apache.commons.logging.simplelog.defaultlog=warn' unless @print_log
|
57
|
+
SeleniumServer.run(['-port', port_number.to_s, '-timeout', request_timeout.to_s] + argv, logging_option)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Stops the Selenium server
|
61
|
+
def stop
|
62
|
+
Net::HTTP.get('localhost', '/selenium-server/driver/?cmd=shutDownSeleniumServer', @port_number)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Check if the Selenium is running by sending a test_complete command with invalid session ID
|
66
|
+
def running?
|
67
|
+
begin
|
68
|
+
ping
|
69
|
+
rescue Errno::EBADF, Errno::ECONNREFUSED => e
|
70
|
+
return false
|
71
|
+
end
|
72
|
+
return true
|
73
|
+
end
|
74
|
+
|
75
|
+
# ping the server to see if it is running, raises error if not
|
76
|
+
# returns the ping status
|
77
|
+
def ping
|
78
|
+
url = URI.parse("http://localhost:#{@port_number}/selenium-server/driver/?cmd=testComplete&sessionId=smoketest")
|
79
|
+
request = Net::HTTP::Get.new(url.path)
|
80
|
+
Net::HTTP.start(url.host, url.port) {|http|
|
81
|
+
http.read_timeout=5
|
82
|
+
http.request(request)
|
83
|
+
}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Selenium
|
4
|
+
# The class that can manages the server driver classes.
|
5
|
+
# This class is originally copied from the BuildMaster project.
|
6
|
+
# You can setup your build task to start the server before
|
7
|
+
# the tests and shutdown when it is finished
|
8
|
+
# server = Selenium::Server.new()
|
9
|
+
# begin
|
10
|
+
# server.start
|
11
|
+
# tests.run # run your tests here
|
12
|
+
# ensure
|
13
|
+
# server.stop
|
14
|
+
# end
|
15
|
+
class Server
|
16
|
+
# The status of the server. Values are
|
17
|
+
# * stopped
|
18
|
+
# * starting
|
19
|
+
# * started
|
20
|
+
# * stopping
|
21
|
+
# * error
|
22
|
+
attr_reader :status
|
23
|
+
|
24
|
+
# The timeout setting for selenium in seconds
|
25
|
+
attr_reader :timeout
|
26
|
+
|
27
|
+
def Server::on_port(port)
|
28
|
+
Server.new(SeleniumServer.new(port))
|
29
|
+
end
|
30
|
+
|
31
|
+
# Create a selenium server that can be controlled directly
|
32
|
+
def initialize(port_number, timeout=60)
|
33
|
+
if port_number.is_a? SeleniumServer
|
34
|
+
# backward compatibility, to be removed in 2.0
|
35
|
+
@server = port_number
|
36
|
+
else
|
37
|
+
@server = SeleniumServer.new(port_number, timeout)
|
38
|
+
end
|
39
|
+
@status = 'stopped'
|
40
|
+
end
|
41
|
+
|
42
|
+
def print_log=(value)
|
43
|
+
@server.print_log = value
|
44
|
+
end
|
45
|
+
|
46
|
+
# Starts the server, returns when the server is up and running
|
47
|
+
def start(*argv)
|
48
|
+
puts "starting selenium server..."
|
49
|
+
starting_server(*argv)
|
50
|
+
wait_for_condition {@server.running?}
|
51
|
+
puts "started selenium server"
|
52
|
+
@status = 'started'
|
53
|
+
end
|
54
|
+
|
55
|
+
def driver(browser_start_command, browser_url)
|
56
|
+
SeleniumDriver.new('localhost', @server.port_number, browser_start_command, browser_url, @server.request_timeout * 1000)
|
57
|
+
end
|
58
|
+
|
59
|
+
def open(browser_start_command, browser_url)
|
60
|
+
url = URI.parse(browser_url)
|
61
|
+
browser = driver(browser_start_command, URI::Generic::new(url.scheme, url.userinfo, url.host, url.port, nil, nil, nil, nil, nil))
|
62
|
+
browser.start
|
63
|
+
browser.open(url.request_uri)
|
64
|
+
page = WebPage.new(browser)
|
65
|
+
page.wait_for_load
|
66
|
+
page
|
67
|
+
end
|
68
|
+
|
69
|
+
# Starts the server, does not return until the server shuts down
|
70
|
+
def run(*argv)
|
71
|
+
@server.start(*argv)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Stops the server, returns when the server is no longer running
|
75
|
+
def stop
|
76
|
+
puts "stopping selenium server..."
|
77
|
+
stopping_server
|
78
|
+
wait_for_condition {not @server.running?}
|
79
|
+
puts "stopped selenium server."
|
80
|
+
@status = 'stopped'
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
def starting_server(*argv)
|
85
|
+
@status = 'starting'
|
86
|
+
['INT', 'TERM'].each { |signal|
|
87
|
+
trap(signal){ @server.stop}
|
88
|
+
}
|
89
|
+
start_thread {run(*argv)}
|
90
|
+
end
|
91
|
+
|
92
|
+
def stopping_server
|
93
|
+
@status = 'stopping'
|
94
|
+
start_thread {@server.stop}
|
95
|
+
end
|
96
|
+
|
97
|
+
def start_thread
|
98
|
+
Thread.new do
|
99
|
+
begin
|
100
|
+
yield
|
101
|
+
rescue Exception => exception
|
102
|
+
@exception = exception
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def wait_for_condition
|
108
|
+
count = 0
|
109
|
+
sleep 1
|
110
|
+
while not (result = yield)
|
111
|
+
if (@exception)
|
112
|
+
error = @exception
|
113
|
+
@exception = nil
|
114
|
+
@status = 'error'
|
115
|
+
raise error
|
116
|
+
end
|
117
|
+
count = count + 1
|
118
|
+
raise 'wait timed out' unless count < 10
|
119
|
+
sleep 1
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
module Selenium
|
6
|
+
# Error that is thrown when a key is not supported
|
7
|
+
class NoKeyError < NameError
|
8
|
+
def initialize(key)
|
9
|
+
super(key)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Class that models a web page with a title
|
14
|
+
class WebPage
|
15
|
+
attr_reader :browser
|
16
|
+
attr_accessor :timeout, :interval_millis
|
17
|
+
|
18
|
+
def initialize(browser, expected_title = nil)
|
19
|
+
@browser = browser
|
20
|
+
@expected_title = expected_title
|
21
|
+
@timeout = 60
|
22
|
+
@interval_millis = 100
|
23
|
+
end
|
24
|
+
|
25
|
+
def title
|
26
|
+
raise 'nil as browser' unless @browser
|
27
|
+
@browser.get_title
|
28
|
+
end
|
29
|
+
|
30
|
+
def present?
|
31
|
+
title == @expected_title
|
32
|
+
end
|
33
|
+
|
34
|
+
def ensure_present
|
35
|
+
title.should == @expected_title
|
36
|
+
end
|
37
|
+
|
38
|
+
def html
|
39
|
+
@browser.get_html_source
|
40
|
+
end
|
41
|
+
|
42
|
+
def speed=(value)
|
43
|
+
@browser.set_speed(value)
|
44
|
+
end
|
45
|
+
|
46
|
+
def speed
|
47
|
+
@browser.get_speed.to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
def wait_for_load
|
51
|
+
@browser.wait_for_page_to_load
|
52
|
+
end
|
53
|
+
|
54
|
+
def wait_until(message, &block)
|
55
|
+
Timeout::timeout(timeout, "Timeout waiting for : #{message}") do
|
56
|
+
while(not yield message)
|
57
|
+
sleep interval_millis / 1000.0
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def alert
|
63
|
+
Alert.new(self)
|
64
|
+
end
|
65
|
+
|
66
|
+
def link(how, what=nil)
|
67
|
+
if (how == :text)
|
68
|
+
locator = "link=#{what}"
|
69
|
+
elsif (how == :href)
|
70
|
+
locator = "xpath=//a[@href='#{what}']"
|
71
|
+
else
|
72
|
+
locator = element_locator(how, what)
|
73
|
+
end
|
74
|
+
Link.new(self, locator)
|
75
|
+
end
|
76
|
+
|
77
|
+
def text_field(how, what=nil)
|
78
|
+
TextField.new(self, element_locator(how, what))
|
79
|
+
end
|
80
|
+
|
81
|
+
def text_area(how, what=nil)
|
82
|
+
TextArea.new(self, element_locator(how, what))
|
83
|
+
end
|
84
|
+
|
85
|
+
def element(how, what=nil)
|
86
|
+
HtmlElement.new(self, element_locator(how,what))
|
87
|
+
end
|
88
|
+
|
89
|
+
def element_locator(how, what=nil)
|
90
|
+
locator = how
|
91
|
+
if (not what.nil?)
|
92
|
+
if (how == :xpath or how == :name or how == :id)
|
93
|
+
locator = "#{how}=#{what}"
|
94
|
+
else
|
95
|
+
raise "couldn't understand how to build locator using #{how} with #{what}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
locator
|
99
|
+
end
|
100
|
+
|
101
|
+
def file_upload(how, what)
|
102
|
+
FileUpload.new(self, element_locator(how, what))
|
103
|
+
end
|
104
|
+
|
105
|
+
def open_page(url)
|
106
|
+
@browser.open(url)
|
107
|
+
wait_for_load
|
108
|
+
end
|
109
|
+
|
110
|
+
def close
|
111
|
+
@browser.stop
|
112
|
+
end
|
113
|
+
|
114
|
+
def click(locator)
|
115
|
+
@browser.click(locator)
|
116
|
+
end
|
117
|
+
|
118
|
+
def text(locator)
|
119
|
+
@browser.get_text(locator)
|
120
|
+
end
|
121
|
+
|
122
|
+
def button(how, what=nil)
|
123
|
+
Button.new(self, element_locator(how, what))
|
124
|
+
end
|
125
|
+
|
126
|
+
def key(key)
|
127
|
+
Key.new(self, key)
|
128
|
+
end
|
129
|
+
|
130
|
+
def element_present?(locator)
|
131
|
+
@browser.is_element_present(locator)
|
132
|
+
end
|
133
|
+
|
134
|
+
def alert_present?
|
135
|
+
@browser.is_alert_present
|
136
|
+
end
|
137
|
+
|
138
|
+
def text_present?(text)
|
139
|
+
@browser.is_text_present(text)
|
140
|
+
end
|
141
|
+
|
142
|
+
def double_click(locator)
|
143
|
+
@browser.double_click(locator)
|
144
|
+
end
|
145
|
+
|
146
|
+
def click_wait(locator)
|
147
|
+
click(locator)
|
148
|
+
wait_for_load
|
149
|
+
end
|
150
|
+
|
151
|
+
# enter the text to the element found by locator
|
152
|
+
def enter(locator, text)
|
153
|
+
@browser.type(locator, text)
|
154
|
+
end
|
155
|
+
|
156
|
+
def value(locator)
|
157
|
+
@browser.get_value(locator)
|
158
|
+
end
|
159
|
+
|
160
|
+
def alert_message
|
161
|
+
@browser.get_alert
|
162
|
+
end
|
163
|
+
|
164
|
+
def context_menu(locator)
|
165
|
+
@browser.context_menu(locator)
|
166
|
+
end
|
167
|
+
|
168
|
+
def fire_event(locator, event)
|
169
|
+
@browser.fire_event(locator, event)
|
170
|
+
end
|
171
|
+
|
172
|
+
def key_down(key)
|
173
|
+
message = "#{key}_key_down"
|
174
|
+
raise NoKeyError.new(key.to_s) unless @browser.respond_to? message
|
175
|
+
@browser.send message
|
176
|
+
end
|
177
|
+
|
178
|
+
def key_up(key)
|
179
|
+
message = "#{key}_key_up"
|
180
|
+
raise NoKeyError.new(key.to_s) unless @browser.respond_to? message
|
181
|
+
@browser.send message
|
182
|
+
end
|
183
|
+
|
184
|
+
def key_press(locator, key)
|
185
|
+
@browser.key_press(locator, key)
|
186
|
+
end
|
187
|
+
|
188
|
+
def focus(locator)
|
189
|
+
@browser.focus(locator)
|
190
|
+
end
|
191
|
+
|
192
|
+
def upload(locator, file)
|
193
|
+
# @browser.attach_file(locator, file)
|
194
|
+
@browser.click(locator)
|
195
|
+
require 'auto_it'
|
196
|
+
autoit = AutoIt.load
|
197
|
+
window = AutoItWindow.wait_for(autoit, 'File Upload')
|
198
|
+
puts window
|
199
|
+
end
|
200
|
+
|
201
|
+
def capture_page(file)
|
202
|
+
@browser.capture_entire_page_screenshot(file)
|
203
|
+
end
|
204
|
+
|
205
|
+
def capture_screen(file)
|
206
|
+
@browser.capture_screenshot(file)
|
207
|
+
end
|
208
|
+
|
209
|
+
def to_s
|
210
|
+
"#{self.class}('#{@expected_title}') - #{browser.to_s}"
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
end
|