Selenium 1.0.9 → 1.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/selenium.rb +4 -1
- 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/autoit/README +1 -0
- data/lib/selenium/button.rb +4 -16
- data/lib/selenium/file_upload.rb +16 -0
- data/lib/selenium/html_element.rb +26 -0
- data/lib/selenium/link.rb +8 -18
- data/lib/selenium/selenium_server.rb +73 -44
- data/lib/selenium/server.rb +24 -0
- data/lib/selenium/server_manager.rb +2 -0
- data/lib/selenium/text_field.rb +6 -7
- data/lib/selenium/version +1 -1
- data/lib/selenium/web_page.rb +109 -2
- data/spec/selenium/examples/selenium_ruby/directory_listing_page.rb +9 -0
- data/spec/selenium/{download_page.rb → examples/selenium_ruby/download_page.rb} +0 -0
- data/spec/selenium/{home_page.rb → examples/selenium_ruby/home_page.rb} +0 -4
- data/spec/selenium/{license_page.rb → examples/selenium_ruby/license_page.rb} +0 -0
- data/spec/selenium/examples/selenium_ruby/menu.rb +29 -0
- data/spec/selenium/{selenium_ruby_page.rb → examples/selenium_ruby/selenium_ruby_page.rb} +2 -9
- data/spec/selenium/manual_tc_file_upload.rb +53 -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 +7 -11
- data/spec/selenium/tc_domain_example.rb +21 -22
- data/spec/selenium/tc_interaction_example.rb +9 -9
- data/spec/selenium/tc_web_page.rb +19 -0
- metadata +59 -39
- data/lib/selenium/directory_listing_page.rb +0 -20
- data/spec/selenium/menu.rb +0 -31
data/lib/selenium.rb
CHANGED
@@ -3,10 +3,13 @@ $:.unshift File.join(File.dirname(__FILE__), 'selenium')
|
|
3
3
|
require 'openqa/selenium'
|
4
4
|
|
5
5
|
require 'selenium_server'
|
6
|
+
require 'web_page'
|
6
7
|
require 'server'
|
7
|
-
require 'directory_listing_page'
|
8
8
|
|
9
|
+
require 'html_element'
|
9
10
|
require 'button'
|
10
11
|
require 'link'
|
11
12
|
require 'locator'
|
12
13
|
require 'text_field'
|
14
|
+
|
15
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Selenium
|
2
|
+
class AutoIt
|
3
|
+
@@autoit = nil
|
4
|
+
|
5
|
+
def self.load
|
6
|
+
begin
|
7
|
+
@@autoit = load_instance
|
8
|
+
rescue WIN32OLERuntimeError
|
9
|
+
registerAutoItDll
|
10
|
+
@@autoit = load_instance
|
11
|
+
end
|
12
|
+
@@autoit
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.load_instance
|
16
|
+
@@autoit = WIN32OLE.new('AutoItX3.Control') unless @@autoit
|
17
|
+
@@autoit
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.reset
|
21
|
+
if @@autoit
|
22
|
+
@@autoit.ole_free
|
23
|
+
@@autoit =nil
|
24
|
+
system("regsvr32.exe /s /u #{dll}")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.registerAutoItDll
|
29
|
+
system("regsvr32.exe /s #{dll}")
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.dll
|
33
|
+
File.join(File.dirname(__FILE__), 'autoit', 'AutoItX3.dll')
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize
|
37
|
+
@autoit = AutoIt.load
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_window_active(title, text = nil)
|
41
|
+
@autoit.WinWaitActive(title, text, 30)
|
42
|
+
yield @@autoit
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'auto_it'
|
4
|
+
|
5
|
+
class AutoItWindow
|
6
|
+
def initialize(autoit, title, text=nil)
|
7
|
+
@autoit = autoit
|
8
|
+
@title = title
|
9
|
+
@text = text
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.wait_for(autoit, title, text = nil)
|
13
|
+
window = self.new(autoit, title, text)
|
14
|
+
window.wait_for_appear
|
15
|
+
window
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.on_activation(autoit, title, text = nil)
|
19
|
+
window = wait_for(autoit, title, text)
|
20
|
+
yield window
|
21
|
+
end
|
22
|
+
|
23
|
+
def wait_for_activation
|
24
|
+
@autoit.WinWaitActive(@title, @text, 30)
|
25
|
+
end
|
26
|
+
|
27
|
+
def wait_for_appear
|
28
|
+
@autoit.WinWait(@title, @text, 30)
|
29
|
+
end
|
30
|
+
|
31
|
+
def activate
|
32
|
+
@autoit.WinActivate(@title, @text)
|
33
|
+
end
|
34
|
+
|
35
|
+
def active?
|
36
|
+
1 == @autoit.WinActive(@title, @text)
|
37
|
+
end
|
38
|
+
|
39
|
+
def state
|
40
|
+
AutoItWindowState.new(@autoit.WinGetState(@title, @text))
|
41
|
+
end
|
42
|
+
|
43
|
+
def send_keys(keys)
|
44
|
+
activate_if_needed
|
45
|
+
@autoit.Send(keys)
|
46
|
+
end
|
47
|
+
|
48
|
+
def close
|
49
|
+
@autoit.WinClose(@title)
|
50
|
+
end
|
51
|
+
|
52
|
+
def activate_if_needed
|
53
|
+
winstate = state
|
54
|
+
activate unless winstate.active?
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class AutoItWindowState
|
59
|
+
def initialize(state)
|
60
|
+
@state = state
|
61
|
+
end
|
62
|
+
|
63
|
+
def exists?
|
64
|
+
@state & 1 > 0
|
65
|
+
end
|
66
|
+
|
67
|
+
def visible?
|
68
|
+
@state & 2 > 0
|
69
|
+
end
|
70
|
+
|
71
|
+
def enabled?
|
72
|
+
@state & 4 > 0
|
73
|
+
end
|
74
|
+
|
75
|
+
def active?
|
76
|
+
@state & 8 > 0
|
77
|
+
end
|
78
|
+
|
79
|
+
def minimized?
|
80
|
+
@state & 16 > 0
|
81
|
+
end
|
82
|
+
|
83
|
+
def maxmized?
|
84
|
+
@state & 32 > 0
|
85
|
+
end
|
86
|
+
end
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
All the files in this foler are from the "AutoIt" project (http://www.autoitscript.com/autoit3/), under autoit3 license
|
data/lib/selenium/button.rb
CHANGED
@@ -1,19 +1,7 @@
|
|
1
1
|
module Selenium
|
2
|
-
class Button
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
@browser = browser
|
7
|
-
@locator = locator
|
2
|
+
class Button < HtmlElement
|
3
|
+
def initialize(webpage, locator)
|
4
|
+
super(webpage, locator)
|
5
|
+
end
|
8
6
|
end
|
9
|
-
|
10
|
-
def click
|
11
|
-
browser.click(@locator)
|
12
|
-
end
|
13
|
-
|
14
|
-
def click_wait
|
15
|
-
click
|
16
|
-
browser.wait_for_page_to_load()
|
17
|
-
end
|
18
|
-
end
|
19
7
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'auto_it_window'
|
4
|
+
|
5
|
+
module Selenium
|
6
|
+
class FileUpload
|
7
|
+
def initialize(webpage, locator)
|
8
|
+
@webpage = webpage
|
9
|
+
@locator = locator
|
10
|
+
end
|
11
|
+
|
12
|
+
def enter(file)
|
13
|
+
@webpage.upload(@locator, file)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,4 +1,30 @@
|
|
1
1
|
module Selenium
|
2
2
|
class HtmlElement
|
3
|
+
attr_reader :webpage, :locator
|
4
|
+
def initialize(webpage, locator)
|
5
|
+
webpage = WebPage.new(webpage) if webpage.is_a? SeleniumDriver
|
6
|
+
@webpage = webpage
|
7
|
+
@locator = locator
|
8
|
+
end
|
9
|
+
|
10
|
+
def browser
|
11
|
+
webpage.browser
|
12
|
+
end
|
13
|
+
|
14
|
+
def present?
|
15
|
+
webpage.browser.is_element_present @locator
|
16
|
+
end
|
17
|
+
|
18
|
+
# click the element
|
19
|
+
def click
|
20
|
+
@webpage.click(@locator)
|
21
|
+
end
|
22
|
+
|
23
|
+
# click the element and wait for page to load
|
24
|
+
# TODO: wait on block instead if givven
|
25
|
+
def click_wait
|
26
|
+
@webpage.click_wait(@locator)
|
27
|
+
end
|
28
|
+
|
3
29
|
end
|
4
30
|
end
|
data/lib/selenium/link.rb
CHANGED
@@ -1,32 +1,22 @@
|
|
1
1
|
module Selenium
|
2
2
|
|
3
3
|
# Link class that models the behavior of a link
|
4
|
-
class Link
|
5
|
-
attr_reader :browser
|
6
|
-
|
4
|
+
class Link < HtmlElement
|
7
5
|
def Link::by_id(browser, id, target = nil)
|
8
|
-
Link.new(browser, "id=#{id}", target)
|
6
|
+
Link.new(WebPage.new(browser), "id=#{id}", target)
|
9
7
|
end
|
10
8
|
|
11
9
|
def Link::by_text(browser, text, target = nil)
|
12
|
-
Link.new(browser, "link=#{text}", target)
|
10
|
+
Link.new(WebPage.new(browser), "link=#{text}", target)
|
13
11
|
end
|
14
12
|
|
15
|
-
def initialize(
|
16
|
-
|
17
|
-
@locator = locator
|
13
|
+
def initialize(webpage, locator, target = nil)
|
14
|
+
super(webpage, locator)
|
18
15
|
@target = target
|
19
16
|
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
@browser.click(@locator)
|
24
|
-
end
|
25
|
-
|
26
|
-
# click the link and wait for page to load
|
27
|
-
def click_wait
|
28
|
-
click
|
29
|
-
@browser.wait_for_page_to_load(30000)
|
18
|
+
def with_target(target)
|
19
|
+
Link.new(webpage, locator, target.new(webpage.browser))
|
30
20
|
end
|
31
21
|
|
32
22
|
# click the link, wait for the page to load, and asserts the target that
|
@@ -34,7 +24,7 @@ module Selenium
|
|
34
24
|
def go
|
35
25
|
raise "target page not defined for link #{@locator}" unless @target
|
36
26
|
click_wait
|
37
|
-
@target.
|
27
|
+
@target.ensure_present
|
38
28
|
@target
|
39
29
|
end
|
40
30
|
end
|
@@ -2,54 +2,83 @@ require 'net/http'
|
|
2
2
|
|
3
3
|
module Selenium
|
4
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
|
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
|
23
9
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
+
attr_accessor :print_log
|
38
|
+
|
39
|
+
# Initialize the server driver with an opitonal port number (default to 4444)
|
40
|
+
def initialize(port_number_to_use = 4444)
|
41
|
+
port_number_to_use = 4444 unless port_number_to_use
|
42
|
+
@port_number = port_number_to_use
|
43
|
+
@request_timeout = 30
|
44
|
+
@print_log = false
|
45
|
+
end
|
46
|
+
|
47
|
+
def port_number
|
48
|
+
@port_number
|
49
|
+
end
|
50
|
+
|
51
|
+
# Starts the Selenium server. This does not return until the server is shutdown.
|
52
|
+
def start(*argv)
|
53
|
+
logging_option = ''
|
54
|
+
logging_option = '-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog -Dorg.apache.commons.logging.simplelog.defaultlog=warn' unless @print_log
|
55
|
+
SeleniumServer.run(['-port', port_number.to_s, '-timeout', request_timeout.to_s] + argv, logging_option)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Stops the Selenium server
|
59
|
+
def stop
|
60
|
+
Net::HTTP.get('localhost', '/selenium-server/driver/?cmd=shutDown', @port_number)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Check if the Selenium is running by sending a test_complete command with invalid session ID
|
64
|
+
def running?
|
65
|
+
begin
|
66
|
+
ping
|
67
|
+
rescue Errno::EBADF, Errno::ECONNREFUSED => e
|
68
|
+
return false
|
69
|
+
end
|
70
|
+
return true
|
71
|
+
end
|
72
|
+
|
73
|
+
# ping the server to see if it is running, raises error if not
|
74
|
+
# returns the ping status
|
75
|
+
def ping
|
76
|
+
url = URI.parse("http://localhost:#{@port_number}/selenium-server/driver/?cmd=testComplete&sessionId=smoketest")
|
77
|
+
request = Net::HTTP::Get.new(url.path)
|
78
|
+
Net::HTTP.start(url.host, url.port) {|http|
|
45
79
|
http.read_timeout=5
|
46
80
|
http.request(request)
|
47
81
|
}
|
48
|
-
puts "response: #{res}"
|
49
|
-
rescue Errno::EBADF, Errno::ECONNREFUSED => e
|
50
|
-
return false
|
51
82
|
end
|
52
|
-
return true
|
53
83
|
end
|
54
|
-
end
|
55
84
|
end
|
data/lib/selenium/server.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
1
3
|
module Selenium
|
2
4
|
# The class that can manages the server driver classes.
|
3
5
|
# This class is originally copied from the BuildMaster project.
|
@@ -28,13 +30,33 @@ class Server
|
|
28
30
|
@status = 'stopped'
|
29
31
|
end
|
30
32
|
|
33
|
+
def print_log=(value)
|
34
|
+
@server.print_log = value
|
35
|
+
end
|
36
|
+
|
31
37
|
# Starts the server, returns when the server is up and running
|
32
38
|
def start(*argv)
|
39
|
+
puts "starting selenium server..."
|
33
40
|
starting_server(*argv)
|
34
41
|
wait_for_condition {@server.running?}
|
42
|
+
puts "started selenium server"
|
35
43
|
@status = 'started'
|
36
44
|
end
|
37
45
|
|
46
|
+
def driver(browser_start_command, browser_url)
|
47
|
+
SeleniumDriver.new('localhost', @server.port_number, browser_start_command, browser_url, @server.request_timeout * 1000)
|
48
|
+
end
|
49
|
+
|
50
|
+
def open(browser_start_command, browser_url)
|
51
|
+
url = URI.parse(browser_url)
|
52
|
+
browser = driver(browser_start_command, URI::Generic::new(url.scheme, url.userinfo, url.host, url.port, nil, nil, nil, nil, nil))
|
53
|
+
browser.start
|
54
|
+
browser.open(url.request_uri)
|
55
|
+
page = WebPage.new(browser)
|
56
|
+
page.wait_for_load
|
57
|
+
page
|
58
|
+
end
|
59
|
+
|
38
60
|
# Starts the server, does not return until the server shuts down
|
39
61
|
def run(*argv)
|
40
62
|
@server.start(*argv)
|
@@ -42,8 +64,10 @@ class Server
|
|
42
64
|
|
43
65
|
# Stops the server, returns when the server is no longer running
|
44
66
|
def stop
|
67
|
+
puts "stopping selenium server..."
|
45
68
|
stopping_server
|
46
69
|
wait_for_condition {not @server.running?}
|
70
|
+
puts "stopped selenium server."
|
47
71
|
@status = 'stopped'
|
48
72
|
end
|
49
73
|
|
data/lib/selenium/text_field.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
module Selenium
|
2
|
-
class TextField
|
2
|
+
class TextField < HtmlElement
|
3
3
|
attr_reader :browser
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
|
7
|
-
@locator = locator
|
5
|
+
def initialize(webpage, locator)
|
6
|
+
super(webpage, locator)
|
8
7
|
end
|
9
8
|
|
10
|
-
def
|
11
|
-
@
|
9
|
+
def enter(value)
|
10
|
+
@webpage.enter(@locator, value)
|
12
11
|
end
|
13
12
|
|
14
13
|
def value
|
15
|
-
@
|
14
|
+
@webpage.value(@locator)
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
data/lib/selenium/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.11
|
data/lib/selenium/web_page.rb
CHANGED
@@ -1,18 +1,125 @@
|
|
1
1
|
$:.unshift File.dirname(__FILE__)
|
2
2
|
|
3
|
+
require 'timeout'
|
4
|
+
|
3
5
|
module Selenium
|
4
6
|
# Class that models a web page with a title
|
5
7
|
class WebPage
|
6
|
-
attr_reader :
|
8
|
+
attr_reader :browser
|
9
|
+
attr_accessor :timeout, :interval_millis
|
7
10
|
|
8
|
-
def initialize(browser, expected_title)
|
11
|
+
def initialize(browser, expected_title = nil)
|
9
12
|
@browser = browser
|
10
13
|
@expected_title = expected_title
|
14
|
+
@timeout = 60
|
15
|
+
@interval_millis = 100
|
11
16
|
end
|
12
17
|
|
13
18
|
def title
|
19
|
+
raise 'nil as browser' unless @browser
|
14
20
|
@browser.get_title
|
15
21
|
end
|
22
|
+
|
23
|
+
def present?
|
24
|
+
title == @expected_title
|
25
|
+
end
|
26
|
+
|
27
|
+
def ensure_present
|
28
|
+
title.should == @expected_title
|
29
|
+
end
|
30
|
+
|
31
|
+
def html
|
32
|
+
@browser.get_html_source
|
33
|
+
end
|
34
|
+
|
35
|
+
def wait_for_load
|
36
|
+
@browser.wait_for_page_to_load
|
37
|
+
end
|
38
|
+
|
39
|
+
def wait_until(message, &block)
|
40
|
+
Timeout::timeout(timeout, "Timeout waiting for : #{message}") do
|
41
|
+
while(not yield message)
|
42
|
+
sleep interval_millis / 1000.0
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def link(how, what=nil)
|
48
|
+
if (how == :text)
|
49
|
+
locator = "link=#{what}"
|
50
|
+
elsif (how == :href)
|
51
|
+
locator = "xpath=//a[@href='#{what}']"
|
52
|
+
else
|
53
|
+
locator = element_locator(how, what)
|
54
|
+
end
|
55
|
+
Link.new(self, locator)
|
56
|
+
end
|
57
|
+
|
58
|
+
def text_field(how, what=nil)
|
59
|
+
TextField.new(self, element_locator(how, what))
|
60
|
+
end
|
61
|
+
|
62
|
+
def button(how, what=nil)
|
63
|
+
Button.new(self, element_locator(how, what))
|
64
|
+
end
|
65
|
+
|
66
|
+
def element_locator(how, what=nil)
|
67
|
+
locator = how
|
68
|
+
if (not what.nil?)
|
69
|
+
if (how == :xpath or how == :name or how == :id)
|
70
|
+
locator = "#{how}=#{what}"
|
71
|
+
else
|
72
|
+
raise "couldn't understand how to build locator using #{how} with #{what}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def file_upload(how, what)
|
78
|
+
FileUpload.new(self, element_locator(how, what))
|
79
|
+
end
|
80
|
+
|
81
|
+
def open(url)
|
82
|
+
@browser.open(url)
|
83
|
+
end
|
84
|
+
|
85
|
+
def close
|
86
|
+
@browser.stop
|
87
|
+
end
|
88
|
+
|
89
|
+
def click(locator)
|
90
|
+
@browser.click(locator)
|
91
|
+
end
|
92
|
+
|
93
|
+
def click_wait(locator)
|
94
|
+
click(locator)
|
95
|
+
wait_for_load
|
96
|
+
end
|
97
|
+
|
98
|
+
# enter the text to the element found by locator
|
99
|
+
def enter(locator, text)
|
100
|
+
@browser.type(locator, text)
|
101
|
+
end
|
102
|
+
|
103
|
+
def value(locator)
|
104
|
+
@browser.get_value(locator)
|
105
|
+
end
|
106
|
+
|
107
|
+
def upload(locator, file)
|
108
|
+
# @browser.attach_file(locator, file)
|
109
|
+
@browser.click(locator)
|
110
|
+
require 'auto_it'
|
111
|
+
autoit = AutoIt.load
|
112
|
+
window = AutoItWindow.wait_for(autoit, 'File Upload')
|
113
|
+
puts window
|
114
|
+
end
|
115
|
+
|
116
|
+
def capture_page(file)
|
117
|
+
@browser.capture_entire_page_screenshot(file)
|
118
|
+
end
|
119
|
+
|
120
|
+
def capture_screen(file)
|
121
|
+
@browser.capture_screenshot(file)
|
122
|
+
end
|
16
123
|
|
17
124
|
end
|
18
125
|
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'home_page'
|
4
|
+
require 'directory_listing_page'
|
5
|
+
require 'license_page'
|
6
|
+
|
7
|
+
module Selenium
|
8
|
+
class Menu
|
9
|
+
attr_reader :webpage
|
10
|
+
def initialize(webpage)
|
11
|
+
@webpage = webpage
|
12
|
+
end
|
13
|
+
|
14
|
+
def home_link
|
15
|
+
# todo there should be a way to alter this instance so that the click returns the directory listing page
|
16
|
+
webpage.link(:id, 'home').with_target(DirectoryListingPage)
|
17
|
+
end
|
18
|
+
|
19
|
+
#MENU START
|
20
|
+
def download_link
|
21
|
+
webpage.link(:text, 'Download')
|
22
|
+
end
|
23
|
+
|
24
|
+
def license_link
|
25
|
+
webpage.link(:text, 'License').with_target(LicensePage)
|
26
|
+
end
|
27
|
+
#MENU END
|
28
|
+
end
|
29
|
+
end
|
@@ -1,9 +1,6 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib', 'selenium')
|
2
|
-
|
3
|
-
require 'web_page'
|
4
|
-
|
5
1
|
$:.unshift File.dirname(__FILE__)
|
6
2
|
|
3
|
+
#require '../../../../lib/selenium'
|
7
4
|
require 'menu'
|
8
5
|
|
9
6
|
module Selenium
|
@@ -14,12 +11,8 @@ module Selenium
|
|
14
11
|
super(browser, expected_title)
|
15
12
|
end
|
16
13
|
|
17
|
-
def assert_page
|
18
|
-
title.should == @expected_title
|
19
|
-
end
|
20
|
-
|
21
14
|
def menu
|
22
|
-
Menu.new(
|
15
|
+
Menu.new(self)
|
23
16
|
end
|
24
17
|
end
|
25
18
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..')
|
2
|
+
|
3
|
+
require 'lib/selenium/auto_it'
|
4
|
+
require 'lib/selenium'
|
5
|
+
require 'spec'
|
6
|
+
|
7
|
+
module Selenium
|
8
|
+
describe FileUpload do
|
9
|
+
before(:all) do
|
10
|
+
@server = Server.on_port(4440)
|
11
|
+
# @server.print_log = true
|
12
|
+
@server.start
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:all) do
|
16
|
+
@server.stop
|
17
|
+
end
|
18
|
+
|
19
|
+
before do
|
20
|
+
# @page = @server.open('*iexplore', 'http://www.rubyforge.org/projects/selenium')
|
21
|
+
@page = @server.open('*chrome D:\Program Files\Mozilla Firefox2\firefox.exe', 'http://www.rubyforge.org/projects/selenium')
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
file = File.join(File.dirname(__FILE__), 'screenshot.png')
|
26
|
+
puts "image at #{file}"
|
27
|
+
@page.capture_screen(file)
|
28
|
+
@page.close
|
29
|
+
end
|
30
|
+
|
31
|
+
# this requires the user to manually enter the login information on rubyforge, and can only be run by selenium admin
|
32
|
+
it 'should handle firefox' do
|
33
|
+
login_link = @page.link(:text, 'Log In')
|
34
|
+
autoit = AutoIt.load
|
35
|
+
login_link.click if login_link.present?
|
36
|
+
AutoItWindow.wait_for(autoit, 'Website Certified by an Unknown Authority').send_keys(' ')
|
37
|
+
@page.wait_for_load
|
38
|
+
@page.wait_until('manual login for test') do |message|
|
39
|
+
puts message
|
40
|
+
not login_link.present?
|
41
|
+
end
|
42
|
+
@page.wait_for_load
|
43
|
+
selenium_project_link = @page.link(:text, 'Selenium')
|
44
|
+
selenium_project_link.should be_present
|
45
|
+
selenium_project_link.click_wait
|
46
|
+
@page.link(:text, 'Files').click_wait
|
47
|
+
@page.link(:href, '/frs/admin/?group_id=2789').click_wait
|
48
|
+
@page.link(:xpath, "//a[@href='qrs.php?package_id=3298&group_id=2789']").click_wait
|
49
|
+
@page.file_upload(:name, 'userfile').enter("file:///#{__FILE__}")
|
50
|
+
# @page.file_upload('userfile').enter("file:///#{__FILE__}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..')
|
2
|
+
|
3
|
+
require 'lib/selenium/auto_it'
|
4
|
+
require 'spec'
|
5
|
+
|
6
|
+
module Selenium
|
7
|
+
describe AutoIt do
|
8
|
+
it 'should control notepad' do
|
9
|
+
autoit = AutoIt.load
|
10
|
+
autoit.Run('Notepad.exe')
|
11
|
+
autoit.WinWaitActive('Untitled - Notepad')
|
12
|
+
autoit.Send('some text')
|
13
|
+
autoit.WinClose('Untitled - Notepad')
|
14
|
+
autoit.WinWaitActive('Notepad', 'Do you want to save')
|
15
|
+
autoit.Send('!n')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..')
|
2
|
+
|
3
|
+
require 'lib/selenium/auto_it'
|
4
|
+
require 'spec'
|
5
|
+
|
6
|
+
module Selenium
|
7
|
+
describe AutoItWindow do
|
8
|
+
it 'should control notepad' do
|
9
|
+
autoit = AutoIt.load
|
10
|
+
autoit.Run('Notepad.exe')
|
11
|
+
window = AutoItWindow.new(autoit, 'Untitled - Notepad')
|
12
|
+
window.wait_for_activation
|
13
|
+
window.send_keys('some text')
|
14
|
+
window.close
|
15
|
+
confirm = AutoItWindow.wait_for(autoit, 'Notepad', 'Do you want to save')
|
16
|
+
confirm.send_keys('!n')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -3,39 +3,35 @@ require 'spec'
|
|
3
3
|
$:.unshift File.join(File.dirname(__FILE__), '..', '..')
|
4
4
|
|
5
5
|
require 'lib/selenium'
|
6
|
-
require 'spec/selenium/home_page'
|
7
|
-
require 'spec/selenium/download_page'
|
6
|
+
require 'spec/selenium/examples/selenium_ruby/home_page'
|
7
|
+
require 'spec/selenium/examples/selenium_ruby/download_page'
|
8
8
|
|
9
9
|
module Selenium
|
10
10
|
describe 'basic operation with selenium' do
|
11
|
-
|
12
11
|
before do
|
13
12
|
port = 4567
|
14
13
|
@server = Selenium::Server.on_port(port)
|
15
14
|
@server.start
|
16
|
-
@
|
17
|
-
@browser.
|
18
|
-
@browser.open('http://localhost:2000/index.html')
|
15
|
+
@webpage = @server.open("*iexplore", 'http://localhost:2000/index.html')
|
16
|
+
@browser = @webpage.browser
|
19
17
|
end
|
20
18
|
|
21
19
|
after do
|
22
|
-
@
|
20
|
+
@webpage.close
|
23
21
|
@server.stop
|
24
22
|
end
|
25
23
|
|
26
24
|
it 'should click through menus' do
|
27
|
-
=begin comment
|
28
25
|
#TEST START
|
29
26
|
page = HomePage.new(@browser)
|
30
27
|
page.menu.download_link.click_wait
|
31
28
|
page = DownloadPage.new(@browser)
|
32
|
-
page.
|
29
|
+
page.should be_present
|
33
30
|
page = page.menu.home_link.go
|
34
|
-
page.
|
31
|
+
page.link(:text, 'index.txt').click_wait
|
35
32
|
page = HomePage.new(@browser)
|
36
33
|
page.menu.license_link.go
|
37
34
|
#TEST END
|
38
|
-
=end comment
|
39
35
|
end
|
40
36
|
end
|
41
37
|
end
|
@@ -1,55 +1,54 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', '..'
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..')
|
2
2
|
|
3
3
|
require 'spec'
|
4
|
-
require 'selenium'
|
4
|
+
require 'lib/selenium'
|
5
5
|
|
6
6
|
#START GOOGLEHOME
|
7
|
-
class GoogleHomPage
|
8
|
-
include Selenium::Locator
|
9
|
-
attr_reader :browser
|
10
|
-
|
11
|
-
def GoogleHomPage::open(sel)
|
12
|
-
sel.open("http://www.google.com/webhp")
|
13
|
-
GoogleHomPage.new(sel)
|
14
|
-
end
|
15
|
-
|
7
|
+
class GoogleHomPage < Selenium::WebPage
|
16
8
|
def initialize(browser)
|
17
|
-
|
18
|
-
|
9
|
+
super(browser, 'Google')
|
10
|
+
end
|
19
11
|
|
20
12
|
def title
|
21
13
|
browser.get_title
|
22
14
|
end
|
23
15
|
|
24
16
|
def search_field
|
25
|
-
|
17
|
+
text_field(:name, 'q')
|
26
18
|
end
|
27
19
|
|
28
20
|
def search_button
|
29
|
-
|
21
|
+
button(:name, 'btnG')
|
30
22
|
end
|
31
23
|
|
32
24
|
end
|
33
25
|
#END GOOGLEHOME
|
34
26
|
|
35
27
|
context 'Test goole search' do
|
36
|
-
before do
|
28
|
+
before(:all) do
|
37
29
|
port = 4567
|
38
30
|
@server = Selenium::Server.on_port(port)
|
39
31
|
@server.start
|
40
|
-
@sel = Selenium::SeleniumDriver.new("localhost", port, "*chrome", "http://www.google.com", 15000)
|
41
|
-
@sel.start
|
42
32
|
end
|
43
33
|
|
44
|
-
|
45
|
-
@
|
34
|
+
before(:each) do
|
35
|
+
@webpage = @server.open('*chrome D:\Program Files\Mozilla Firefox2\firefox.exe', 'http://www.google.com/webhp')
|
36
|
+
end
|
37
|
+
|
38
|
+
after(:each) do
|
39
|
+
@webpage.close if @webpage
|
40
|
+
end
|
41
|
+
|
42
|
+
after(:all) do
|
43
|
+
puts "stopping server"
|
46
44
|
@server.stop
|
47
45
|
end
|
48
46
|
|
49
47
|
#START DOMAIN
|
50
48
|
specify'searh hello world with google using docmain based script' do
|
51
|
-
page = GoogleHomPage.
|
52
|
-
page.
|
49
|
+
page = GoogleHomPage.new(@webpage.browser)
|
50
|
+
page.should be_present
|
51
|
+
page.search_field.enter('hello world')
|
53
52
|
page.search_button.click_wait
|
54
53
|
page.title.should == 'hello world - Google Search'
|
55
54
|
page.search_field.value.should == 'hello world'
|
@@ -7,23 +7,23 @@ require 'selenium'
|
|
7
7
|
context 'Test goole search' do
|
8
8
|
before do
|
9
9
|
port = 4567
|
10
|
-
@server = Selenium::Server.on_port(
|
10
|
+
@server = Selenium::Server.on_port(port)
|
11
11
|
@server.start
|
12
|
-
@
|
13
|
-
@sel.start
|
12
|
+
@page = @server.open('*chrome D:\Program Files\Mozilla Firefox2\firefox.exe', 'http://www.google.com')
|
14
13
|
end
|
15
14
|
|
16
15
|
after do
|
17
|
-
@
|
16
|
+
@page.close
|
18
17
|
@server.stop
|
19
18
|
end
|
20
19
|
|
21
20
|
specify'searh hello world with google using interaction based script' do
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@
|
25
|
-
@
|
26
|
-
@
|
21
|
+
@page.open("/")
|
22
|
+
@page.title.should == 'Google'
|
23
|
+
@page.enter("q", "hello world")
|
24
|
+
@page.click("btnG")
|
25
|
+
@page.wait_for_load
|
26
|
+
@page.title.should == 'hello world - Google Search'
|
27
27
|
end
|
28
28
|
|
29
29
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec'
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..')
|
4
|
+
|
5
|
+
require 'lib/selenium'
|
6
|
+
|
7
|
+
module Selenium
|
8
|
+
describe WebPage do
|
9
|
+
it 'should create link based on text' do
|
10
|
+
webpage = WebPage.new('browser')
|
11
|
+
webpage.link(:text, 'text').locator.should == 'link=text'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should create link based on href' do
|
15
|
+
webpage = WebPage.new('browser')
|
16
|
+
webpage.link(:href, 'a.html').locator.should == "xpath=//a[@href='a.html']"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,38 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: Selenium
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date: 2008-05-18 00:00:00 -07: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:
|
4
|
+
version: 1.1.11
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Shane Duan
|
8
|
+
autorequire: selenium
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-07-12 00:00:00 -07:00
|
13
|
+
default_executable: selenium
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: selenium-ruby@googlegroups.com
|
18
|
+
executables:
|
19
|
+
- selenium
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
31
24
|
files:
|
32
25
|
- bin/selenium
|
33
26
|
- lib/selenium
|
27
|
+
- lib/selenium/autoit
|
28
|
+
- lib/selenium/autoit/AutoItX3.dll
|
29
|
+
- lib/selenium/autoit/README
|
30
|
+
- lib/selenium/auto_it.rb
|
31
|
+
- lib/selenium/auto_it_driver.rb
|
32
|
+
- lib/selenium/auto_it_window.rb
|
34
33
|
- lib/selenium/button.rb
|
35
|
-
- lib/selenium/
|
34
|
+
- lib/selenium/file_upload.rb
|
36
35
|
- lib/selenium/html_element.rb
|
37
36
|
- lib/selenium/link.rb
|
38
37
|
- lib/selenium/locator.rb
|
@@ -50,29 +49,50 @@ files:
|
|
50
49
|
- lib/selenium/web_page.rb
|
51
50
|
- lib/selenium.rb
|
52
51
|
- spec/selenium
|
53
|
-
- spec/selenium/
|
54
|
-
- spec/selenium/
|
55
|
-
- spec/selenium/
|
52
|
+
- spec/selenium/examples
|
53
|
+
- spec/selenium/examples/selenium_ruby
|
54
|
+
- spec/selenium/examples/selenium_ruby/directory_listing_page.rb
|
55
|
+
- spec/selenium/examples/selenium_ruby/download_page.rb
|
56
|
+
- spec/selenium/examples/selenium_ruby/home_page.rb
|
57
|
+
- spec/selenium/examples/selenium_ruby/license_page.rb
|
58
|
+
- spec/selenium/examples/selenium_ruby/menu.rb
|
59
|
+
- spec/selenium/examples/selenium_ruby/selenium_ruby_page.rb
|
60
|
+
- spec/selenium/manual_tc_file_upload.rb
|
56
61
|
- spec/selenium/manual_tc_timout.rb
|
57
|
-
- spec/selenium/
|
58
|
-
- spec/selenium/
|
62
|
+
- spec/selenium/tc_auto_it.rb
|
63
|
+
- spec/selenium/tc_auto_it_window.rb
|
59
64
|
- spec/selenium/tc_basic_operation.rb
|
60
65
|
- spec/selenium/tc_domain_example.rb
|
61
66
|
- spec/selenium/tc_interaction_example.rb
|
62
67
|
- spec/selenium/tc_server.rb
|
68
|
+
- spec/selenium/tc_web_page.rb
|
63
69
|
- spec/ts_selenium.rb
|
64
70
|
- README
|
65
|
-
|
66
|
-
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: http://selenium.rubyforge.org/
|
73
|
+
post_install_message:
|
67
74
|
rdoc_options: []
|
68
75
|
|
69
|
-
|
70
|
-
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "0"
|
89
|
+
version:
|
75
90
|
requirements: []
|
76
91
|
|
77
|
-
|
92
|
+
rubyforge_project: selenium
|
93
|
+
rubygems_version: 1.2.0
|
94
|
+
signing_key:
|
95
|
+
specification_version: 2
|
96
|
+
summary: A project that wraps selenium API into object-oriented testing style and packages it into a RubyGem.
|
97
|
+
test_files: []
|
78
98
|
|
@@ -1,20 +0,0 @@
|
|
1
|
-
$:.unshift File.dirname(__FILE__)
|
2
|
-
require 'link'
|
3
|
-
|
4
|
-
module Selenium
|
5
|
-
class DirectoryListingPage
|
6
|
-
attr_reader :browser
|
7
|
-
|
8
|
-
def initialize(browser)
|
9
|
-
@browser = browser
|
10
|
-
end
|
11
|
-
|
12
|
-
def link_to_entry(text)
|
13
|
-
Link.new(browser, "link=#{text}")
|
14
|
-
end
|
15
|
-
|
16
|
-
def assert_page
|
17
|
-
@browser.get_title.should == 'Index of /'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/spec/selenium/menu.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
$:.unshift File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require 'home_page'
|
4
|
-
|
5
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib', 'selenium')
|
6
|
-
|
7
|
-
require 'directory_listing_page'
|
8
|
-
require 'license_page'
|
9
|
-
|
10
|
-
module Selenium
|
11
|
-
class Menu
|
12
|
-
attr_reader :browser
|
13
|
-
def initialize(browser)
|
14
|
-
@browser = browser
|
15
|
-
end
|
16
|
-
def home_link
|
17
|
-
# todo there should be a way to alter this instance so that the click returns the directory listing page
|
18
|
-
Link.by_id(browser, 'home', DirectoryListingPage.new(@browser))
|
19
|
-
end
|
20
|
-
|
21
|
-
#MENU START
|
22
|
-
def download_link
|
23
|
-
Link.by_text(browser, 'Download')
|
24
|
-
end
|
25
|
-
|
26
|
-
def license_link
|
27
|
-
Link.by_text(browser, 'License', LicensePage.new(@browser))
|
28
|
-
end
|
29
|
-
#MENU END
|
30
|
-
end
|
31
|
-
end
|