zhimin-rwebspec 1.4.0 → 1.4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Rakefile +16 -4
- data/lib/rwebspec/driver.rb +3 -1
- data/lib/rwebspec/web_browser.rb +89 -40
- data/lib/rwebspec/web_page.rb +3 -1
- data/lib/rwebspec.rb +1 -1
- data/lib/watir_extensions.rb +53 -49
- metadata +1 -1
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
@@ -10,13 +10,13 @@ $:.unshift(File.dirname(__FILE__) + "/lib")
|
|
10
10
|
#require 'rwebspec'
|
11
11
|
|
12
12
|
desc "Default task"
|
13
|
-
task :default => [ :clean, :spec, :gem]
|
14
|
-
# task :default => [ :clean, :spec, :rdoc, :gem]
|
13
|
+
task :default => [ :clean, :spec, :rdoc, :chm, :gem]
|
15
14
|
|
16
15
|
desc "Clean generated files"
|
17
16
|
task :clean do
|
18
17
|
rm_rf 'pkg'
|
19
18
|
rm_rf 'doc'
|
19
|
+
rm_rf 'chm'
|
20
20
|
end
|
21
21
|
|
22
22
|
desc 'Run all specs'
|
@@ -39,7 +39,7 @@ end
|
|
39
39
|
# using DarkFish - http://deveiate.org/projects/Darkfish-Rdoc/
|
40
40
|
Rake::RDocTask.new do |rdoc|
|
41
41
|
rdoc.rdoc_dir = 'doc'
|
42
|
-
rdoc.title = '
|
42
|
+
rdoc.title = 'RWebSpec'
|
43
43
|
rdoc.rdoc_files.include('lib/rwebspec.rb')
|
44
44
|
rdoc.rdoc_files.include('lib/rwebspec/*.rb')
|
45
45
|
rdoc.options += [
|
@@ -48,10 +48,22 @@ Rake::RDocTask.new do |rdoc|
|
|
48
48
|
]
|
49
49
|
end
|
50
50
|
|
51
|
+
Rake::RDocTask.new("chm") do |rdoc|
|
52
|
+
rdoc.rdoc_dir = 'chm'
|
53
|
+
rdoc.title = 'RWebSpec'
|
54
|
+
rdoc.rdoc_files.include('lib/rwebspec.rb')
|
55
|
+
rdoc.rdoc_files.include('lib/rwebspec/*.rb')
|
56
|
+
rdoc.options += [
|
57
|
+
'-SHN',
|
58
|
+
'-f', 'chm', # This is the important bit
|
59
|
+
]
|
60
|
+
end
|
61
|
+
|
62
|
+
|
51
63
|
spec = Gem::Specification.new do |s|
|
52
64
|
s.platform= Gem::Platform::RUBY
|
53
65
|
s.name = "rwebspec"
|
54
|
-
s.version = "1.4.0"
|
66
|
+
s.version = "1.4.0.1"
|
55
67
|
s.summary = "Executable functional specification for web applications in RSpec syntax and Watir"
|
56
68
|
# s.description = ""
|
57
69
|
|
data/lib/rwebspec/driver.rb
CHANGED
@@ -346,7 +346,7 @@ module RWebSpec
|
|
346
346
|
spec_run_dir_name = spec_run_id.to_s.rjust(4, "0") unless spec_run_id == "unknown"
|
347
347
|
to_dir = File.join($ITEST2_DUMP_DIR, spec_run_dir_name)
|
348
348
|
else
|
349
|
-
to_dir = ENV['TEMP_DIR'] || "C:\\temp"
|
349
|
+
to_dir = ENV['TEMP_DIR'] || (is_windows? ? "C:\\temp" : "/tmp")
|
350
350
|
end
|
351
351
|
|
352
352
|
if options[:filename]
|
@@ -401,6 +401,7 @@ module RWebSpec
|
|
401
401
|
# absolutize_page referencs using hpricot
|
402
402
|
#
|
403
403
|
def absolutize_page_hpricot(content, base_url, parent_url)
|
404
|
+
return absolutize_page(content, base_url, parent_url) if RUBY_PLATFORM == 'java'
|
404
405
|
begin
|
405
406
|
require 'hpricot'
|
406
407
|
doc = Hpricot(content)
|
@@ -502,6 +503,7 @@ module RWebSpec
|
|
502
503
|
# Support browser (IE) operations using unicode
|
503
504
|
# Example:
|
504
505
|
# click_button("Google 搜索")
|
506
|
+
# Reference: http://jira.openqa.org/browse/WTR-219
|
505
507
|
def support_utf8
|
506
508
|
if is_windows?
|
507
509
|
require 'win32ole'
|
data/lib/rwebspec/web_browser.rb
CHANGED
@@ -42,54 +42,94 @@ module RWebSpec
|
|
42
42
|
attr_accessor :context
|
43
43
|
|
44
44
|
def initialize(base_url = nil, existing_browser = nil, options = {})
|
45
|
-
default_options = {:speed => "zippy",
|
46
|
-
|
45
|
+
default_options = {:speed => "zippy",
|
46
|
+
:visible => true,
|
47
|
+
:highlight_colour => 'yellow',
|
48
|
+
:close_others => true
|
49
|
+
}
|
47
50
|
options = default_options.merge options
|
48
51
|
@context = Context.new base_url if base_url
|
49
52
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
firefox_jssh = Net::Telnet::new("Host" => "127.0.0.1", "Port" => 9997)
|
62
|
-
FireWatir::Firefox.firefox_started = true
|
63
|
-
rescue => e
|
64
|
-
# puts "debug: XXX #{e}"
|
65
|
-
sleep 1
|
53
|
+
case RUBY_PLATFORM
|
54
|
+
when /java/i
|
55
|
+
# Java, maybe firewatir or celerity
|
56
|
+
puts "Ruby java platform"
|
57
|
+
raise "Not supported, no FireWatir or Celerity detected" unless $firewatir_loaded || $celerity_loaded
|
58
|
+
if $firewatir_loaded && $celerity_loaded then
|
59
|
+
# choose one out of two, :default to celerity
|
60
|
+
if options[:firefox] then
|
61
|
+
initialize_firefox_browser(existing_browser, base_url, options)
|
62
|
+
else
|
63
|
+
initialize_celerity_browser(base_url, options)
|
66
64
|
end
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
elsif $firewatir_loaded
|
66
|
+
initialize_firefox_browser(existing_browser, base_url, options)
|
67
|
+
else
|
68
|
+
initialize_celerity_browser(base_url, options)
|
70
69
|
end
|
71
|
-
end
|
72
70
|
|
71
|
+
when /mswin|windows|mingw/i
|
72
|
+
puts "Ruby windows platform"
|
73
|
+
raise "Not supported, no Watir or FireWatir detected" unless $watir_loaded || $firewatir_loaded
|
74
|
+
if $firewatir_loaded && options[:firefox] then
|
75
|
+
initialize_firefox_browser(existing_browser, base_url, options)
|
76
|
+
else
|
77
|
+
initialize_ie_browser(existing_browser, options)
|
78
|
+
end
|
79
|
+
else
|
80
|
+
raise "Not supported, no FireWatirdetected" unless $firewatir_loaded
|
81
|
+
puts "Ruby Linux or Mac platform: firefox"
|
82
|
+
initialize_firefox_browser(base_url, options)
|
73
83
|
end
|
84
|
+
end
|
74
85
|
|
75
|
-
|
76
|
-
if
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
86
|
+
def initialize_firefox_browser(existing_browser, base_url, options)
|
87
|
+
if existing_browser then
|
88
|
+
@browser = existing_browser
|
89
|
+
return
|
90
|
+
end
|
91
|
+
# JSSH is running, 9997
|
92
|
+
begin
|
93
|
+
require 'net/telnet'
|
94
|
+
firefox_jssh = Net::Telnet::new("Host" => "127.0.0.1", "Port" => 9997)
|
95
|
+
FireWatir::Firefox.firefox_started = true
|
96
|
+
rescue => e
|
97
|
+
# puts "debug: XXX #{e}"
|
98
|
+
sleep 1
|
99
|
+
end
|
100
|
+
@browser = FireWatir::Firefox.start(base_url)
|
101
|
+
end
|
85
102
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
103
|
+
def initialize_celerity_browser(base_url, options)
|
104
|
+
default_celerity_options = { :proxy => nil, :browser => :firefox, :resynchronize => true, :log_level => :off }
|
105
|
+
options = default_celerity_options.merge options
|
106
|
+
options.each { |k, v| options.delete(k) unless default_celerity_options.keys.include?(k)}
|
107
|
+
puts "Starting Celerity: #{options.inspect}"
|
108
|
+
@browser = Celerity::Browser.new(options)
|
109
|
+
@browser.goto(base_url)
|
110
|
+
end
|
90
111
|
|
112
|
+
def initialize_ie_browser(existing_browser, options)
|
113
|
+
if existing_browser then
|
114
|
+
@browser = existing_browser
|
115
|
+
return
|
91
116
|
end
|
92
117
|
|
118
|
+
@browser = Watir::IE.new
|
119
|
+
if $ITEST2_EMULATE_TYPING && $ITEST2_TYPING_SPEED then
|
120
|
+
@browser.set_slow_speed if $ITEST2_TYPING_SPEED == 'slow'
|
121
|
+
@browser.set_fast_speed if $ITEST2_TYPING_SPEED == 'fast'
|
122
|
+
else
|
123
|
+
@browser.speed = :zippy
|
124
|
+
end
|
125
|
+
@browser.activeObjectHighLightColor = options[:highlight_colour]
|
126
|
+
@browser.visible = options[:visible] unless $HIDE_IE
|
127
|
+
#NOTE: close_others fails
|
128
|
+
if RUBY_VERSION =~ /^1\.8/ && options[:close_others] then
|
129
|
+
@browser.close_others
|
130
|
+
else
|
131
|
+
puts "close other browser instances not working yet in Ruby 1.9.1 version of Watir"
|
132
|
+
end
|
93
133
|
end
|
94
134
|
|
95
135
|
def self.reuse(base_url, options)
|
@@ -139,6 +179,7 @@ module RWebSpec
|
|
139
179
|
@browser.html()
|
140
180
|
#@browser.document.body
|
141
181
|
end
|
182
|
+
|
142
183
|
alias html_body page_source
|
143
184
|
|
144
185
|
def html
|
@@ -150,10 +191,13 @@ module RWebSpec
|
|
150
191
|
end
|
151
192
|
|
152
193
|
def page_title
|
153
|
-
|
194
|
+
case @browser.class.to_s
|
195
|
+
when "FireWatir::Firefox"
|
154
196
|
@browser.title
|
155
|
-
|
197
|
+
when "Watir::IE"
|
156
198
|
@browser.document.title
|
199
|
+
else
|
200
|
+
@browser.title
|
157
201
|
end
|
158
202
|
end
|
159
203
|
|
@@ -188,13 +232,17 @@ module RWebSpec
|
|
188
232
|
# Close the browser window. Useful for automated test suites to reduce
|
189
233
|
# test interaction.
|
190
234
|
def close_browser
|
191
|
-
|
235
|
+
case @browser.class.to_s
|
236
|
+
when "FireWatir::Firefox"
|
192
237
|
@browser.close
|
238
|
+
when "Watir::IE"
|
239
|
+
@browser.getIE.quit
|
193
240
|
else
|
194
|
-
@browser.
|
241
|
+
puts "#{@browser.class} can't close, ignore"
|
195
242
|
end
|
196
243
|
sleep 2
|
197
244
|
end
|
245
|
+
|
198
246
|
alias close close_browser
|
199
247
|
|
200
248
|
#TODO determine browser type, check FireWatir support or not
|
@@ -273,6 +321,7 @@ module RWebSpec
|
|
273
321
|
wait_before_and_after { text_field(:name, name).set(text) }
|
274
322
|
end
|
275
323
|
end
|
324
|
+
|
276
325
|
alias set_form_element enter_text_into_field_with_name
|
277
326
|
alias enter_text enter_text_into_field_with_name
|
278
327
|
|
data/lib/rwebspec/web_page.rb
CHANGED
@@ -62,6 +62,7 @@ module RWebSpec
|
|
62
62
|
def source
|
63
63
|
@web_browser.page_source
|
64
64
|
end
|
65
|
+
alias html source
|
65
66
|
|
66
67
|
# return current page title
|
67
68
|
def title
|
@@ -75,9 +76,10 @@ module RWebSpec
|
|
75
76
|
|
76
77
|
# TO validate
|
77
78
|
def contains?(ary)
|
79
|
+
return true if ary.nil?
|
78
80
|
the_page_source = source
|
79
81
|
found = false
|
80
|
-
ary.
|
82
|
+
ary.each_line do |str|
|
81
83
|
found ||= the_page_source.include?(str)
|
82
84
|
end
|
83
85
|
return found
|
data/lib/rwebspec.rb
CHANGED
data/lib/watir_extensions.rb
CHANGED
@@ -1,65 +1,69 @@
|
|
1
|
+
if RUBY_PLATFORM == "java" then
|
2
|
+
# no need to load firefox extension
|
3
|
+
else
|
4
|
+
module FireWatir
|
5
|
+
class Firefox
|
1
6
|
|
2
|
-
|
3
|
-
class Firefox
|
7
|
+
@@firefox_started = false
|
4
8
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
options = {:waitTime => options}
|
10
|
-
end
|
9
|
+
def initialize(options = {})
|
10
|
+
if(options.kind_of?(Integer))
|
11
|
+
options = {:waitTime => options}
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
if(options[:profile])
|
15
|
+
profile_opt = "-no-remote -P #{options[:profile]}"
|
16
|
+
else
|
17
|
+
profile_opt = ""
|
18
|
+
end
|
17
19
|
|
18
|
-
|
20
|
+
waitTime = options[:waitTime] || 2
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
case RUBY_PLATFORM
|
23
|
+
when /mswin/
|
24
|
+
# Get the path to Firefox.exe using Registry.
|
25
|
+
require 'win32/registry.rb'
|
26
|
+
path_to_bin = ""
|
27
|
+
Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Mozilla\Mozilla Firefox') do |reg|
|
28
|
+
keys = reg.keys
|
29
|
+
reg1 = Win32::Registry::HKEY_LOCAL_MACHINE.open("SOFTWARE\\Mozilla\\Mozilla Firefox\\#{keys[0]}\\Main")
|
30
|
+
reg1.each do |subkey, type, data|
|
31
|
+
if(subkey =~ /pathtoexe/i)
|
32
|
+
path_to_bin = data
|
33
|
+
end
|
31
34
|
end
|
32
35
|
end
|
33
|
-
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
when /linux/i
|
38
|
+
path_to_bin = `which firefox`.strip
|
39
|
+
when /darwin/i
|
40
|
+
path_to_bin = '/Applications/Firefox.app/Contents/MacOS/firefox'
|
41
|
+
when /java/
|
42
|
+
raise "Not implemented: Create a browser finder in JRuby"
|
43
|
+
end
|
42
44
|
|
43
|
-
|
45
|
+
@t = Thread.new { system("#{path_to_bin} -jssh #{profile_opt}")} unless @@firefox_started
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
sleep waitTime
|
48
|
+
begin
|
49
|
+
set_defaults()
|
50
|
+
rescue Watir::Exception::UnableToStartJSShException
|
51
|
+
if !@t # no new thread starting browser, try again
|
52
|
+
puts "Firefox with JSSH not detected after you indicated @@firefox_started"
|
53
|
+
@t = Thread.new { system("#{path_to_bin} -jssh #{profile_opt}")}
|
54
|
+
sleep waitTime
|
55
|
+
set_defaults
|
56
|
+
end
|
54
57
|
end
|
58
|
+
get_window_number()
|
59
|
+
set_browser_document()
|
55
60
|
end
|
56
|
-
get_window_number()
|
57
|
-
set_browser_document()
|
58
|
-
end
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
|
62
|
+
def self.firefox_started=(value)
|
63
|
+
@@firefox_started = value
|
64
|
+
end
|
63
65
|
|
66
|
+
end
|
64
67
|
end
|
68
|
+
|
65
69
|
end
|