zhimin-rwebspec 1.4.0.1 → 1.4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/README +1 -1
- data/Rakefile +16 -6
- data/lib/rwebspec.rb +1 -1
- data/lib/rwebspec/web_browser.rb +81 -43
- data/lib/rwebspec/web_page.rb +11 -1
- data/lib/rwebspec/web_testcase.rb +2 -0
- metadata +1 -1
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
|
2
|
+
RWebSpec wraps the popular web testing framework WATIR with RSpec Syntax to provide better easy to read automated web test cases. By using iTest/Watir recorder, the rWebUnit test scripts can be recorded in Firefox. iTest2 makes editing/executing test cases with ease.
|
3
3
|
|
4
4
|
Sample rWebUnit Test:
|
5
5
|
|
data/Rakefile
CHANGED
@@ -41,11 +41,14 @@ Rake::RDocTask.new do |rdoc|
|
|
41
41
|
rdoc.rdoc_dir = 'doc'
|
42
42
|
rdoc.title = 'RWebSpec'
|
43
43
|
rdoc.rdoc_files.include('lib/rwebspec.rb')
|
44
|
-
rdoc.rdoc_files.include('lib/rwebspec/*.rb')
|
45
|
-
|
44
|
+
rdoc.rdoc_files.include('lib/rwebspec/*.rb')
|
45
|
+
rdoc.rdoc_files.delete("lib/rwebspec/test_utils.rb")
|
46
|
+
rdoc.rdoc_files.delete("lib/rwebspec/web_testcase.rb")
|
47
|
+
rdoc.rdoc_files.delete("lib/rwebspec/checkJSDialog.rb")
|
48
|
+
rdoc.options += [
|
46
49
|
'-SHN',
|
47
50
|
'-f', 'darkfish', # This is the important bit
|
48
|
-
|
51
|
+
]
|
49
52
|
end
|
50
53
|
|
51
54
|
Rake::RDocTask.new("chm") do |rdoc|
|
@@ -53,6 +56,9 @@ Rake::RDocTask.new("chm") do |rdoc|
|
|
53
56
|
rdoc.title = 'RWebSpec'
|
54
57
|
rdoc.rdoc_files.include('lib/rwebspec.rb')
|
55
58
|
rdoc.rdoc_files.include('lib/rwebspec/*.rb')
|
59
|
+
rdoc.rdoc_files.delete("lib/rwebspec/test_utils.rb")
|
60
|
+
rdoc.rdoc_files.delete("lib/rwebspec/web_testcase.rb")
|
61
|
+
rdoc.rdoc_files.delete("lib/rwebspec/checkJSDialog.rb")
|
56
62
|
rdoc.options += [
|
57
63
|
'-SHN',
|
58
64
|
'-f', 'chm', # This is the important bit
|
@@ -63,7 +69,7 @@ end
|
|
63
69
|
spec = Gem::Specification.new do |s|
|
64
70
|
s.platform= Gem::Platform::RUBY
|
65
71
|
s.name = "rwebspec"
|
66
|
-
s.version = "1.4.0.
|
72
|
+
s.version = "1.4.0.2"
|
67
73
|
s.summary = "Executable functional specification for web applications in RSpec syntax and Watir"
|
68
74
|
# s.description = ""
|
69
75
|
|
@@ -83,10 +89,14 @@ spec = Gem::Specification.new do |s|
|
|
83
89
|
s.files = s.files + Dir.glob( "sample/**/*")
|
84
90
|
s.files = s.files + Dir.glob( "docs/**/*" )
|
85
91
|
s.add_dependency(%q<rspec>, ["= 1.1.12"])
|
92
|
+
if RUBY_PLATFORM.downcase.include?("mswin") or RUBY_PLATFORM.downcase.include?("mingw")
|
93
|
+
s.add_dependency("watir", ">= 1.6.2")
|
94
|
+
else
|
95
|
+
s.add_dependency("firewatir", ">= 1.6.2")
|
96
|
+
end
|
97
|
+
|
86
98
|
s.add_dependency("commonwatir", ">= 1.6.2")
|
87
99
|
s.add_dependency("test-unit", ">= 2.0.2")
|
88
|
-
# s.add_dependency("watir", ">= 1.6.2")
|
89
|
-
# s.add_dependency("firewatir", ">= 1.6.2")
|
90
100
|
end
|
91
101
|
|
92
102
|
Rake::GemPackageTask.new(spec) do |pkg|
|
data/lib/rwebspec.rb
CHANGED
@@ -13,7 +13,7 @@ end
|
|
13
13
|
require 'active_support/core_ext'
|
14
14
|
require 'spec'
|
15
15
|
|
16
|
-
RWEBSPEC_VERSION = RWEBUNIT_VERSION = "1.4.0.
|
16
|
+
RWEBSPEC_VERSION = RWEBUNIT_VERSION = "1.4.0.2"
|
17
17
|
|
18
18
|
# Extra full path to load libraries
|
19
19
|
require File.dirname(__FILE__) + "/rwebspec/using_pages"
|
data/lib/rwebspec/web_browser.rb
CHANGED
@@ -43,43 +43,42 @@ module RWebSpec
|
|
43
43
|
|
44
44
|
def initialize(base_url = nil, existing_browser = nil, options = {})
|
45
45
|
default_options = {:speed => "zippy",
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
:visible => true,
|
47
|
+
:highlight_colour => 'yellow',
|
48
|
+
:close_others => true
|
49
49
|
}
|
50
50
|
options = default_options.merge options
|
51
51
|
@context = Context.new base_url if base_url
|
52
52
|
|
53
53
|
case RUBY_PLATFORM
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
initialize_firefox_browser(existing_browser, base_url, options)
|
62
|
-
else
|
63
|
-
initialize_celerity_browser(base_url, options)
|
64
|
-
end
|
65
|
-
elsif $firewatir_loaded
|
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
|
66
61
|
initialize_firefox_browser(existing_browser, base_url, options)
|
67
62
|
else
|
68
63
|
initialize_celerity_browser(base_url, options)
|
69
64
|
end
|
65
|
+
elsif $firewatir_loaded
|
66
|
+
initialize_firefox_browser(existing_browser, base_url, options)
|
67
|
+
else
|
68
|
+
initialize_celerity_browser(base_url, options)
|
69
|
+
end
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
initialize_firefox_browser(existing_browser, base_url, options)
|
76
|
-
else
|
77
|
-
initialize_ie_browser(existing_browser, options)
|
78
|
-
end
|
71
|
+
when /mswin|windows|mingw/i
|
72
|
+
raise "Not supported, no Watir or FireWatir detected" unless $watir_loaded || $firewatir_loaded
|
73
|
+
if $firewatir_loaded && options[:firefox] then
|
74
|
+
initialize_firefox_browser(existing_browser, base_url, options)
|
79
75
|
else
|
80
|
-
|
81
|
-
|
82
|
-
|
76
|
+
initialize_ie_browser(existing_browser, options)
|
77
|
+
end
|
78
|
+
else
|
79
|
+
raise "Not supported, no FireWatirdetected" unless $firewatir_loaded
|
80
|
+
puts "Ruby Linux or Mac platform: firefox"
|
81
|
+
initialize_firefox_browser(existing_browser, base_url, options)
|
83
82
|
end
|
84
83
|
end
|
85
84
|
|
@@ -133,7 +132,7 @@ module RWebSpec
|
|
133
132
|
end
|
134
133
|
|
135
134
|
def self.reuse(base_url, options)
|
136
|
-
if
|
135
|
+
if self.is_windows? && $ITEST2_BROWSER != "Firefox"
|
137
136
|
Watir::IE.each do |browser_window|
|
138
137
|
return WebBrowser.new(base_url, browser_window, options)
|
139
138
|
end
|
@@ -162,7 +161,9 @@ module RWebSpec
|
|
162
161
|
alias check_box checkbox # seems watir doc is wrong, checkbox not check_box
|
163
162
|
alias tr row
|
164
163
|
|
165
|
-
#
|
164
|
+
# Wrapp of Watir's area to support Firefox and Watir
|
165
|
+
#
|
166
|
+
# Note: FireWatir does not support area directly, treat it as text_field
|
166
167
|
def area(*args)
|
167
168
|
if is_firefox?
|
168
169
|
text_field(*args)
|
@@ -175,24 +176,23 @@ module RWebSpec
|
|
175
176
|
@browser.contains_text(text);
|
176
177
|
end
|
177
178
|
|
179
|
+
# return HTML of current web page
|
178
180
|
def page_source
|
179
181
|
@browser.html()
|
180
182
|
#@browser.document.body
|
181
183
|
end
|
182
|
-
|
183
184
|
alias html_body page_source
|
185
|
+
alias html page_source
|
184
186
|
|
185
|
-
def html
|
186
|
-
@browser.html
|
187
|
-
end
|
188
187
|
|
188
|
+
# return plain text of current web page
|
189
189
|
def text
|
190
190
|
@browser.text
|
191
191
|
end
|
192
192
|
|
193
193
|
def page_title
|
194
|
-
|
195
|
-
|
194
|
+
case @browser.class.to_s
|
195
|
+
when "FireWatir::Firefox"
|
196
196
|
@browser.title
|
197
197
|
when "Watir::IE"
|
198
198
|
@browser.document.title
|
@@ -232,11 +232,11 @@ module RWebSpec
|
|
232
232
|
# Close the browser window. Useful for automated test suites to reduce
|
233
233
|
# test interaction.
|
234
234
|
def close_browser
|
235
|
-
|
236
|
-
|
235
|
+
case @browser.class.to_s
|
236
|
+
when "FireWatir::Firefox"
|
237
237
|
@browser.close
|
238
238
|
when "Watir::IE"
|
239
|
-
@browser.getIE.quit
|
239
|
+
@browser.getIE.quit
|
240
240
|
else
|
241
241
|
puts "#{@browser.class} can't close, ignore"
|
242
242
|
end
|
@@ -304,10 +304,17 @@ module RWebSpec
|
|
304
304
|
alias go_back back
|
305
305
|
alias go_forward forward
|
306
306
|
|
307
|
+
# Go to a page
|
308
|
+
# Usage:
|
309
|
+
# open_browser("http://www.itest2.com"
|
310
|
+
# ....
|
311
|
+
# goto_page("/purchase") # full url => http://www.itest.com/purchase
|
307
312
|
def goto_page(page)
|
308
313
|
@browser.goto full_url(page);
|
309
314
|
end
|
310
315
|
|
316
|
+
# Go to a URL directly
|
317
|
+
# goto_url("http://www.itest2.com/downloads")
|
311
318
|
def goto_url(url)
|
312
319
|
@browser.goto url
|
313
320
|
end
|
@@ -334,25 +341,37 @@ module RWebSpec
|
|
334
341
|
wait_before_and_after { link(:text, text).click }
|
335
342
|
end
|
336
343
|
|
337
|
-
|
338
|
-
#
|
339
|
-
|
344
|
+
# Click a button with give HTML id
|
345
|
+
# Usage:
|
346
|
+
# click_button_with_id("btn_sumbit")
|
340
347
|
def click_button_with_id(id)
|
341
348
|
wait_before_and_after { button(:id, id).click }
|
342
349
|
end
|
343
350
|
|
351
|
+
# Click a button with give name
|
352
|
+
# Usage:
|
353
|
+
# click_button_with_name("confirm")
|
344
354
|
def click_button_with_name(name)
|
345
355
|
wait_before_and_after { button(:name, name).click }
|
346
356
|
end
|
347
357
|
|
358
|
+
# Click a button with caption
|
359
|
+
# Usage:
|
360
|
+
# click_button_with_caption("Confirm payment")
|
348
361
|
def click_button_with_caption(caption)
|
349
362
|
wait_before_and_after { button(:caption, caption).click }
|
350
363
|
end
|
351
364
|
|
365
|
+
# Click a button with value
|
366
|
+
# Usage:
|
367
|
+
# click_button_with_value("Confirm payment")
|
352
368
|
def click_button_with_value(value)
|
353
369
|
wait_before_and_after { button(:value, value).click }
|
354
370
|
end
|
355
371
|
|
372
|
+
# Select a dropdown list by name
|
373
|
+
# Usage:
|
374
|
+
# select_option("country", "Australia")
|
356
375
|
def select_option(selectName, option)
|
357
376
|
select_list(:name, selectName).select(option)
|
358
377
|
end
|
@@ -370,7 +389,10 @@ module RWebSpec
|
|
370
389
|
end
|
371
390
|
end
|
372
391
|
|
373
|
-
# checkbox
|
392
|
+
# Check a checkbox
|
393
|
+
# Usage:
|
394
|
+
# check_checkbox("agree")
|
395
|
+
# check_checkbox("agree", "true")
|
374
396
|
def check_checkbox(checkBoxName, values=nil)
|
375
397
|
if values
|
376
398
|
values.class == Array ? arys = values : arys = [values]
|
@@ -382,6 +404,10 @@ module RWebSpec
|
|
382
404
|
end
|
383
405
|
end
|
384
406
|
|
407
|
+
# Check a checkbox
|
408
|
+
# Usage:
|
409
|
+
# uncheck_checkbox("agree")
|
410
|
+
# uncheck_checkbox("agree", "false")
|
385
411
|
def uncheck_checkbox(checkBoxName, values = nil)
|
386
412
|
if values
|
387
413
|
values.class == Array ? arys = values : arys = [values]
|
@@ -394,15 +420,21 @@ module RWebSpec
|
|
394
420
|
end
|
395
421
|
|
396
422
|
|
397
|
-
#
|
423
|
+
# Click a radio button
|
424
|
+
# Usage:
|
425
|
+
# click_radio_option("country", "Australia")
|
398
426
|
def click_radio_option(radio_group, radio_option)
|
399
427
|
radio(:name, radio_group, radio_option).set
|
400
428
|
end
|
401
429
|
|
430
|
+
# Clear a radio button
|
431
|
+
# Usage:
|
432
|
+
# click_radio_option("country", "Australia")
|
402
433
|
def clear_radio_option(radio_group, radio_option)
|
403
434
|
radio(:name, radio_group, radio_option).clear
|
404
435
|
end
|
405
436
|
|
437
|
+
# Deprecated: using Watir style directly instead
|
406
438
|
def element_by_id(elem_id)
|
407
439
|
if is_firefox?
|
408
440
|
# elem = @browser.document.getElementById(elem_id)
|
@@ -508,18 +540,24 @@ module RWebSpec
|
|
508
540
|
@browser
|
509
541
|
end
|
510
542
|
|
543
|
+
# return underlying firefox browser object, raise error if not running using Firefox
|
511
544
|
def firefox
|
512
545
|
raise "can't call this as it is configured to use IE" unless is_firefox?
|
513
546
|
@browser
|
514
547
|
end
|
515
548
|
|
549
|
+
# Save current web page source to file
|
550
|
+
# usage:
|
551
|
+
# save_page("/tmp/01.html")
|
552
|
+
# save_page() => # will save to "20090830112200.html"
|
516
553
|
def save_page(file_name = nil)
|
517
554
|
file_name ||= Time.now.strftime("%Y%m%d%H%M%S") + ".html"
|
518
|
-
puts "about to save page: #{File.expand_path(file_name)}"
|
555
|
+
puts "about to save page: #{File.expand_path(file_name)}" if $DEBUG
|
519
556
|
File.open(file_name, "w").puts page_source
|
520
557
|
end
|
521
558
|
|
522
559
|
|
560
|
+
# is it running in MS Windows platforms?
|
523
561
|
def self.is_windows?
|
524
562
|
RUBY_PLATFORM.downcase.include?("mswin") or RUBY_PLATFORM.downcase.include?("mingw")
|
525
563
|
end
|
data/lib/rwebspec/web_page.rb
CHANGED
@@ -42,10 +42,16 @@ module RWebSpec
|
|
42
42
|
assert_on_page
|
43
43
|
end
|
44
44
|
|
45
|
+
# return the browser instance in page objects
|
45
46
|
def browser
|
46
47
|
@web_browser
|
47
48
|
end
|
48
49
|
|
50
|
+
# Assert is on current page
|
51
|
+
# Example
|
52
|
+
# home_page = HomePage.new("Welcome to iTest2")
|
53
|
+
# ....
|
54
|
+
# home_page.assert_on_page # will check the text 'Welcome to iTest2' still present on the page
|
49
55
|
def assert_on_page()
|
50
56
|
assert_text_present(@page_text) if @page_text
|
51
57
|
end
|
@@ -58,7 +64,7 @@ module RWebSpec
|
|
58
64
|
@web_browser.dump_response(stream)
|
59
65
|
end
|
60
66
|
|
61
|
-
|
67
|
+
# Page source (html)
|
62
68
|
def source
|
63
69
|
@web_browser.page_source
|
64
70
|
end
|
@@ -85,6 +91,10 @@ module RWebSpec
|
|
85
91
|
return found
|
86
92
|
end
|
87
93
|
|
94
|
+
# Will save current page source to a file
|
95
|
+
# home_page = HomePage.new("Welcome to iTest2")
|
96
|
+
# ...
|
97
|
+
# home_page.snapshot() # => save to 20090830100102_HomePage.html
|
88
98
|
def snapshot(replace_css = false)
|
89
99
|
save_current_page(:filename => Time.now.strftime("%m%d%H%M%S") + "_" + self.class.name.gsub(" ", "") + ".html" )
|
90
100
|
end
|
@@ -3,6 +3,8 @@
|
|
3
3
|
#* Distributed open-source, see full license in MIT-LICENSE
|
4
4
|
#***********************************************************
|
5
5
|
|
6
|
+
# Deprecated, use RSpec syntax instead
|
7
|
+
|
6
8
|
require 'test/unit'
|
7
9
|
require File.join(File.dirname(__FILE__), 'assert')
|
8
10
|
require File.join(File.dirname(__FILE__), 'driver')
|