Selenium 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +17 -0
- data/bin/selenium +5 -0
- data/lib/selenium.rb +13 -0
- data/lib/selenium/button.rb +19 -0
- data/lib/selenium/directory_listing_page.rb +16 -0
- data/lib/selenium/link.rb +27 -0
- data/lib/selenium/locator.rb +15 -0
- data/lib/selenium/openqa/README +5 -0
- data/lib/selenium/openqa/selenium-server.jar.txt +0 -0
- data/lib/selenium/openqa/selenium.rb +1363 -0
- data/lib/selenium/selenium_server.rb +55 -0
- data/lib/selenium/server_manager.rb +82 -0
- data/lib/selenium/text_field.rb +18 -0
- data/lib/selenium/version +1 -0
- data/test/selenium/download_page.rb +13 -0
- data/test/selenium/home_page.rb +18 -0
- data/test/selenium/menu.rb +18 -0
- data/test/selenium/tc_basic_operation.rb +33 -0
- data/test/selenium/tc_selenium_server.rb +19 -0
- metadata +67 -0
@@ -0,0 +1,55 @@
|
|
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
|
+
def SeleniumServer::run(argv)
|
10
|
+
jar_file = SeleniumServer.jar_file
|
11
|
+
command = "java -jar #{jar_file} #{argv.join(' ')}"
|
12
|
+
puts command
|
13
|
+
system(command)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def SeleniumServer::jar_file
|
18
|
+
File.join(File.dirname(__FILE__), 'openqa', 'selenium-server.jar.txt')
|
19
|
+
end
|
20
|
+
|
21
|
+
public
|
22
|
+
attr_reader :port_number
|
23
|
+
|
24
|
+
# Initialize the server driver with an opitonal port number (default to 4444)
|
25
|
+
def initialize(port_number = 4444)
|
26
|
+
@port_number = port_number
|
27
|
+
end
|
28
|
+
|
29
|
+
# Starts the Selenium server. This does not return until the server is shutdown.
|
30
|
+
def start
|
31
|
+
SeleniumServer.run(['-port', port_number.to_s])
|
32
|
+
end
|
33
|
+
|
34
|
+
# Stops the Selenium server
|
35
|
+
def stop
|
36
|
+
Net::HTTP.get('localhost', '/selenium-server/driver/?cmd=shutDown', @port_number)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Check if the Selenium is running by sending a test_complete command with invalid session ID
|
40
|
+
def running?
|
41
|
+
url = URI.parse("http://localhost:#{@port_number}/selenium-server/driver/?cmd=testComplete&sessionId=smoketest")
|
42
|
+
request = Net::HTTP::Get.new(url.path)
|
43
|
+
begin
|
44
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
45
|
+
http.read_timeout=5
|
46
|
+
http.request(request)
|
47
|
+
}
|
48
|
+
puts "response: #{res}"
|
49
|
+
rescue Errno::EBADF => e
|
50
|
+
return false
|
51
|
+
end
|
52
|
+
return true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Selenium
|
2
|
+
# The class that can manages the server driver classes.
|
3
|
+
# This class is copied from the BuildMaster project.
|
4
|
+
# You can setup your build task to start the server before
|
5
|
+
# the tests and shutdown when it is finished
|
6
|
+
# manager = Selenium::ServerManager.new(Selenium::Server.new)
|
7
|
+
# begin
|
8
|
+
# manager.start
|
9
|
+
# tests.run # run your tests here
|
10
|
+
# ensure
|
11
|
+
# manager.stop
|
12
|
+
# end
|
13
|
+
class ServerManager
|
14
|
+
# The status of the server. Values are
|
15
|
+
# * stopped
|
16
|
+
# * starting
|
17
|
+
# * started
|
18
|
+
# * stopping
|
19
|
+
# * error
|
20
|
+
attr_reader :status
|
21
|
+
|
22
|
+
def initialize(server)
|
23
|
+
@server = server
|
24
|
+
@status = 'stopped'
|
25
|
+
end
|
26
|
+
|
27
|
+
# Starts the server, returns when the server is up and running
|
28
|
+
def start
|
29
|
+
starting_server
|
30
|
+
wait_for_condition {@server.running?}
|
31
|
+
@status = 'started'
|
32
|
+
end
|
33
|
+
|
34
|
+
# Stops the server, returns when the server is no longer running
|
35
|
+
def stop
|
36
|
+
stopping_server
|
37
|
+
wait_for_condition {not @server.running?}
|
38
|
+
@status = 'stopped'
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def starting_server
|
43
|
+
@status = 'starting'
|
44
|
+
['INT', 'TERM'].each { |signal|
|
45
|
+
trap(signal){ @server.stop}
|
46
|
+
}
|
47
|
+
start_thread {@server.start}
|
48
|
+
end
|
49
|
+
|
50
|
+
def stopping_server
|
51
|
+
@status = 'stopping'
|
52
|
+
start_thread {@server.stop}
|
53
|
+
end
|
54
|
+
|
55
|
+
def start_thread
|
56
|
+
Thread.new do
|
57
|
+
begin
|
58
|
+
yield
|
59
|
+
rescue Exception => exception
|
60
|
+
@exception = exception
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def wait_for_condition
|
66
|
+
count = 0
|
67
|
+
sleep 1
|
68
|
+
while not (result = yield)
|
69
|
+
if (@exception)
|
70
|
+
error = @exception
|
71
|
+
@exception = nil
|
72
|
+
@status = 'error'
|
73
|
+
raise error
|
74
|
+
end
|
75
|
+
count = count + 1
|
76
|
+
raise 'wait timed out' unless count < 10
|
77
|
+
sleep 1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Selenium
|
2
|
+
class TextField
|
3
|
+
attr_reader :browser
|
4
|
+
|
5
|
+
def initialize(browser, locator)
|
6
|
+
@browser = browser
|
7
|
+
@locator = locator
|
8
|
+
end
|
9
|
+
|
10
|
+
def type(value)
|
11
|
+
@browser.type(@locator, value)
|
12
|
+
end
|
13
|
+
|
14
|
+
def value
|
15
|
+
@browser.get_value(@locator)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'menu'
|
3
|
+
|
4
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib', 'selenium')
|
5
|
+
|
6
|
+
require 'link'
|
7
|
+
|
8
|
+
module Selenium
|
9
|
+
class HomePage
|
10
|
+
include Menu
|
11
|
+
attr_reader :browser
|
12
|
+
|
13
|
+
def initialize(browser)
|
14
|
+
@browser = browser
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Selenium
|
2
|
+
module Menu
|
3
|
+
def home_link
|
4
|
+
# todo there should be a way to alter this instance so that the click returns the directory listing page
|
5
|
+
Link.by_id(browser, 'home')
|
6
|
+
end
|
7
|
+
|
8
|
+
#MENU START
|
9
|
+
def download_link
|
10
|
+
Link.by_text(browser, 'Download')
|
11
|
+
end
|
12
|
+
|
13
|
+
def license_link
|
14
|
+
Link.by_text(browser, 'License')
|
15
|
+
end
|
16
|
+
#MENU END
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec'
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..')
|
4
|
+
|
5
|
+
require 'lib/selenium'
|
6
|
+
require 'test/selenium/home_page'
|
7
|
+
require 'test/selenium/download_page'
|
8
|
+
|
9
|
+
module Selenium
|
10
|
+
context 'basic operation with selenium' do
|
11
|
+
context_setup do
|
12
|
+
@browser = Selenium::SeleniumDriver.new("localhost", 4444, "*iexplore", "http://localhost:2000", 10000)
|
13
|
+
@browser.start
|
14
|
+
end
|
15
|
+
|
16
|
+
setup do
|
17
|
+
@browser.open('http://localhost:2000/index.html')
|
18
|
+
end
|
19
|
+
|
20
|
+
specify 'click through menus' do
|
21
|
+
#TEST START
|
22
|
+
page = HomePage.new(@browser)
|
23
|
+
page.download_link.click_wait
|
24
|
+
page = DownloadPage.new(@browser)
|
25
|
+
page.home_link.click_wait
|
26
|
+
page = DirectoryListingPage.new(@browser)
|
27
|
+
page.link_to_entry('index.txt').click_wait
|
28
|
+
page = HomePage.new(@browser)
|
29
|
+
page.license_link.click_wait
|
30
|
+
#TEST END
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec'
|
2
|
+
require 'buildmaster/cotta'
|
3
|
+
require 'buildmaster/project/server_manager'
|
4
|
+
|
5
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib', 'selenium')
|
6
|
+
|
7
|
+
require 'selenium_server'
|
8
|
+
|
9
|
+
module Selenium
|
10
|
+
context 'selenium server' do
|
11
|
+
specify 'start and stop server' do
|
12
|
+
server = BuildMaster::ServerManager.new(SeleniumServer.new(4321))
|
13
|
+
puts 'starting server...'
|
14
|
+
server.start
|
15
|
+
puts 'stopping server...'
|
16
|
+
server.stop
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: Selenium
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2007-01-01 00:00:00 -08:00
|
8
|
+
summary: A project that wraps selenium API into object-oriented testing style and packages it into a RubyGem.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: selenium@gmail.com
|
12
|
+
homepage: http://selenium.rubyforge.org/
|
13
|
+
rubyforge_project: selenium
|
14
|
+
description:
|
15
|
+
autorequire: selenium
|
16
|
+
default_executable: selenium
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Shane Duan
|
31
|
+
files:
|
32
|
+
- bin/selenium
|
33
|
+
- lib/selenium
|
34
|
+
- lib/selenium.rb
|
35
|
+
- lib/selenium/button.rb
|
36
|
+
- lib/selenium/directory_listing_page.rb
|
37
|
+
- lib/selenium/link.rb
|
38
|
+
- lib/selenium/locator.rb
|
39
|
+
- lib/selenium/openqa
|
40
|
+
- lib/selenium/selenium_server.rb
|
41
|
+
- lib/selenium/server_manager.rb
|
42
|
+
- lib/selenium/text_field.rb
|
43
|
+
- lib/selenium/version
|
44
|
+
- lib/selenium/openqa/README
|
45
|
+
- lib/selenium/openqa/selenium-server.jar.txt
|
46
|
+
- lib/selenium/openqa/selenium.rb
|
47
|
+
- test/selenium
|
48
|
+
- test/selenium/download_page.rb
|
49
|
+
- test/selenium/home_page.rb
|
50
|
+
- test/selenium/menu.rb
|
51
|
+
- test/selenium/tc_basic_operation.rb
|
52
|
+
- test/selenium/tc_selenium_server.rb
|
53
|
+
- README
|
54
|
+
test_files: []
|
55
|
+
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
extra_rdoc_files:
|
59
|
+
- README
|
60
|
+
executables:
|
61
|
+
- selenium
|
62
|
+
extensions: []
|
63
|
+
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
dependencies: []
|
67
|
+
|