rwebspec 1.4.0.2 → 1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +37 -0
- data/Rakefile +6 -9
- data/lib/rwebspec/assert.rb +95 -70
- data/lib/rwebspec/database_checker.rb +74 -0
- data/lib/rwebspec/driver.rb +878 -741
- data/lib/rwebspec/load_test_helper.rb +110 -0
- data/lib/rwebspec/matchers/contains_text.rb +2 -2
- data/lib/rwebspec/test_utils.rb +57 -16
- data/lib/rwebspec/{itest_plugin.rb → testwise_plugin.rb} +82 -78
- data/lib/rwebspec/web_browser.rb +67 -17
- data/lib/rwebspec/web_page.rb +6 -6
- data/lib/rwebspec.rb +6 -2
- data/lib/watir_extensions.rb +49 -43
- metadata +10 -28
@@ -0,0 +1,110 @@
|
|
1
|
+
|
2
|
+
module RWebSpec
|
3
|
+
module LoadTestHelper
|
4
|
+
|
5
|
+
include RWebSpec::Utils
|
6
|
+
include RWebSpec::Assert
|
7
|
+
|
8
|
+
# only support firefox or Celerity
|
9
|
+
def open_browser(base_url, options)
|
10
|
+
options[:firefox] ||= (ENV['ILOAD2_PREVIEW'] == true)
|
11
|
+
RWebSpec::WebBrowser.new(base_url, nil, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
# maybe attach_browser
|
15
|
+
|
16
|
+
# Does not provide real function, other than make enhancing test syntax
|
17
|
+
#
|
18
|
+
# Example:
|
19
|
+
# allow { click_button('Register') }
|
20
|
+
def allow(&block)
|
21
|
+
yield
|
22
|
+
end
|
23
|
+
alias shall_allow allow
|
24
|
+
alias allowing allow
|
25
|
+
|
26
|
+
# try operation, ignore if errors occur
|
27
|
+
#
|
28
|
+
# Example:
|
29
|
+
# failsafe { click_link("Logout") } # try logout, but it still OK if not being able to (already logout))
|
30
|
+
def failsafe(&block)
|
31
|
+
begin
|
32
|
+
yield
|
33
|
+
rescue =>e
|
34
|
+
end
|
35
|
+
end
|
36
|
+
alias fail_safe failsafe
|
37
|
+
|
38
|
+
# Try the operation up to specified timeout (in seconds), and sleep given interval (in seconds).
|
39
|
+
# Error will be ignored until timeout
|
40
|
+
# Example
|
41
|
+
# try { click_link('waiting')}
|
42
|
+
# try(10, 2) { click_button('Search' } # try to click the 'Search' button upto 10 seconds, try every 2 seconds
|
43
|
+
# try { click_button('Search' }
|
44
|
+
def try(timeout = @@default_timeout, polling_interval = @@default_polling_interval || 1, &block)
|
45
|
+
start_time = Time.now
|
46
|
+
|
47
|
+
last_error = nil
|
48
|
+
until (duration = Time.now - start_time) > timeout
|
49
|
+
begin
|
50
|
+
return if yield
|
51
|
+
last_error = nil
|
52
|
+
rescue => e
|
53
|
+
last_error = e
|
54
|
+
end
|
55
|
+
sleep polling_interval
|
56
|
+
end
|
57
|
+
|
58
|
+
raise "Timeout after #{duration.to_i} seconds with error: #{last_error}." if last_error
|
59
|
+
raise "Timeout after #{duration.to_i} seconds."
|
60
|
+
end
|
61
|
+
alias try_upto try
|
62
|
+
|
63
|
+
##
|
64
|
+
# Convert :first to 1, :second to 2, and so on...
|
65
|
+
def symbol_to_sequence(symb)
|
66
|
+
value = { :zero => 0,
|
67
|
+
:first => 1,
|
68
|
+
:second => 2,
|
69
|
+
:third => 3,
|
70
|
+
:fourth => 4,
|
71
|
+
:fifth => 5,
|
72
|
+
:sixth => 6,
|
73
|
+
:seventh => 7,
|
74
|
+
:eighth => 8,
|
75
|
+
:ninth => 9,
|
76
|
+
:tenth => 10 }[symb]
|
77
|
+
return value || symb.to_i
|
78
|
+
end
|
79
|
+
|
80
|
+
# monitor current execution using
|
81
|
+
#
|
82
|
+
# Usage
|
83
|
+
# log_time { browser.click_button('Confirm') }
|
84
|
+
def log_time(msg, &block)
|
85
|
+
start_time = Time.now
|
86
|
+
yield
|
87
|
+
Thread.current[:log] ||= []
|
88
|
+
Thread.current[:log] << [File.basename(__FILE__), msg, Time.now, Time.now - start_time]
|
89
|
+
end
|
90
|
+
|
91
|
+
def run_with_virtual_users(virtual_user_count = 2, &block)
|
92
|
+
raise "too many virtual users" if virtual_user_count > 100 #TODO
|
93
|
+
if (virtual_user_count <= 1)
|
94
|
+
yield
|
95
|
+
else
|
96
|
+
threads = []
|
97
|
+
virtual_user_count.times do |idx|
|
98
|
+
threads[idx] = Thread.new do
|
99
|
+
start_time = Time.now
|
100
|
+
yield
|
101
|
+
puts "Thread[#{idx+1}] #{Time.now - start_time}s"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
threads.each {|t| t.join }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
@@ -19,12 +19,12 @@ class ContainsText
|
|
19
19
|
|
20
20
|
# error message for should
|
21
21
|
def failure_message
|
22
|
-
"expected #{actual_text}
|
22
|
+
"expected '#{actual_text}' to contain '#{@expected}', but it did't"
|
23
23
|
end
|
24
24
|
|
25
25
|
# error message for should_not
|
26
26
|
def negative_failure_message
|
27
|
-
"expected #{actual_text} not to
|
27
|
+
"expected '#{actual_text}' not to contain '#{@expected}', but it did"
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
data/lib/rwebspec/test_utils.rb
CHANGED
@@ -3,6 +3,14 @@
|
|
3
3
|
#* Distributed open-source, see full license in MIT-LICENSE
|
4
4
|
#***********************************************************
|
5
5
|
|
6
|
+
|
7
|
+
class Array
|
8
|
+
|
9
|
+
def average
|
10
|
+
inject(0.0) { |sum, e| sum + e } / length
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
6
14
|
# useful hekoer methods for testing
|
7
15
|
#
|
8
16
|
module RWebSpec
|
@@ -39,33 +47,34 @@ module RWebSpec
|
|
39
47
|
# %Z - Time zone name
|
40
48
|
# %% - Literal ``%'' character
|
41
49
|
|
42
|
-
def today(format =
|
43
|
-
format_date(Time.now, format)
|
50
|
+
def today(format = nil)
|
51
|
+
format_date(Time.now, date_format(format))
|
44
52
|
end
|
45
53
|
alias getToday_AU today
|
46
54
|
alias getToday_US today
|
47
55
|
alias getToday today
|
48
56
|
|
49
57
|
|
50
|
-
def days_before(days, format =
|
51
|
-
nil if !(days.instance_of?(Fixnum))
|
52
|
-
format_date(Time.now - days * 24 * 3600, format)
|
58
|
+
def days_before(days, format = nil)
|
59
|
+
return nil if !(days.instance_of?(Fixnum))
|
60
|
+
format_date(Time.now - days * 24 * 3600, date_format(format))
|
53
61
|
end
|
54
62
|
|
55
|
-
def yesterday
|
56
|
-
days_before(1)
|
63
|
+
def yesterday(format = nil)
|
64
|
+
days_before(1, date_format(format))
|
57
65
|
end
|
58
66
|
|
59
|
-
def days_from_now(days, format =
|
60
|
-
nil if !(days.instance_of?(Fixnum))
|
61
|
-
format_date(Time.now + days * 24 * 3600, format)
|
67
|
+
def days_from_now(days, format = nil)
|
68
|
+
return nil if !(days.instance_of?(Fixnum))
|
69
|
+
format_date(Time.now + days * 24 * 3600, date_format(format))
|
62
70
|
end
|
63
71
|
alias days_after days_from_now
|
64
72
|
|
65
|
-
def tomorrow
|
66
|
-
days_from_now(1)
|
73
|
+
def tomorrow(format = nil)
|
74
|
+
days_from_now(1, date_format(format))
|
67
75
|
end
|
68
76
|
|
77
|
+
|
69
78
|
# return a random number >= min, but <= max
|
70
79
|
def random_number(min, max)
|
71
80
|
rand(max-min+1)+min
|
@@ -76,8 +85,11 @@ module RWebSpec
|
|
76
85
|
end
|
77
86
|
|
78
87
|
def random_char(lowercase = true)
|
79
|
-
|
80
|
-
|
88
|
+
if lowercase
|
89
|
+
sprintf("%c", random_number(97, 122))
|
90
|
+
else
|
91
|
+
sprintf("%c", random_number(65, 90))
|
92
|
+
end
|
81
93
|
end
|
82
94
|
|
83
95
|
def random_digit()
|
@@ -116,7 +128,7 @@ module RWebSpec
|
|
116
128
|
# Generate a given number of words. If a range is passed, it will generate
|
117
129
|
# a random number of words within that range.
|
118
130
|
def words(total)
|
119
|
-
(1..interpret_value(total)).map { WORDS
|
131
|
+
(1..interpret_value(total)).map { WORDS[random_number(0, total)] }.join(' ')
|
120
132
|
end
|
121
133
|
|
122
134
|
# Generate a given number of sentences. If a range is passed, it will generate
|
@@ -148,7 +160,7 @@ module RWebSpec
|
|
148
160
|
private
|
149
161
|
|
150
162
|
def time_in_range(range)
|
151
|
-
Time.at number_in_range(Range.new(range.first.to_i, range.last.to_i,
|
163
|
+
Time.at number_in_range(Range.new(range.first.to_i, range.last.to_i, rangee.exclude_end?))
|
152
164
|
end
|
153
165
|
|
154
166
|
def date_in_range(range)
|
@@ -167,5 +179,34 @@ module RWebSpec
|
|
167
179
|
date.strftime(date_format)
|
168
180
|
end
|
169
181
|
|
182
|
+
def date_format(format_argument)
|
183
|
+
if format_argument.nil? then
|
184
|
+
get_locale_date_format(default_locale)
|
185
|
+
elsif format_argument.class == Symbol then
|
186
|
+
get_locale_date_format(format_argument)
|
187
|
+
elsif format_argument.class == String then
|
188
|
+
format_argument
|
189
|
+
else
|
190
|
+
# invalid input, use default
|
191
|
+
get_locale_date_format(default_date_format)
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
def get_locale_date_format(locale)
|
197
|
+
case locale
|
198
|
+
when :us
|
199
|
+
"%m/%d/%Y"
|
200
|
+
when :au, :uk
|
201
|
+
"%d/%m/%Y"
|
202
|
+
else
|
203
|
+
"%Y-%m-%d"
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
def default_locale
|
208
|
+
return :au
|
209
|
+
end
|
210
|
+
|
170
211
|
end
|
171
212
|
end
|
@@ -1,79 +1,83 @@
|
|
1
|
-
require 'socket'
|
2
|
-
|
3
|
-
module RWebSpec
|
4
|
-
module
|
5
|
-
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
if
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
module RWebSpec
|
4
|
+
module TestWisePlugin
|
5
|
+
|
6
|
+
def debug(message)
|
7
|
+
connect_to_testwise(" DEBUG", message.to_s + "\r\n") if $RUN_IN_TESTWISE && message
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
# Support of iTest to ajust the intervals between keystroke/mouse operations
|
12
|
+
def operation_delay
|
13
|
+
begin
|
14
|
+
if $ITEST2_OPERATION_DELAY && $ITEST2_OPERATION_DELAY > 0 &&
|
15
|
+
$ITEST2_OPERATION_DELAY && $ITEST2_OPERATION_DELAY < 30000 then # max 30 seconds
|
16
|
+
sleep($ITEST2_OPERATION_DELAY / 1000)
|
17
|
+
end
|
18
|
+
|
19
|
+
while $ITEST2_PAUSE
|
20
|
+
debug("Paused, waiting ...")
|
21
|
+
sleep 1
|
22
|
+
end
|
23
|
+
rescue => e
|
24
|
+
puts "Error on delaying: #{e}"
|
25
|
+
# ignore
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def notify_screenshot_location(image_file_path)
|
30
|
+
connect_to_testwise(" SHOT", image_file_path)
|
31
|
+
end
|
32
|
+
|
33
|
+
# find out the line (and file) the execution is on, and notify iTest via Socket
|
34
|
+
def dump_caller_stack
|
35
|
+
return unless $ITEST2_TRACE_EXECUTION
|
36
|
+
begin
|
37
|
+
trace_lines = []
|
38
|
+
trace_file = nil
|
39
|
+
found_first_spec_reference = false
|
40
|
+
caller.each_with_index do |position, idx|
|
41
|
+
next unless position =~ /\A(.*?):(\d+)/
|
42
|
+
trace_file = $1
|
43
|
+
if trace_file =~ /(_spec|_test|_rwebspec)\.rb\s*$/
|
44
|
+
found_first_spec_reference = true
|
45
|
+
trace_lines << position
|
46
|
+
break
|
47
|
+
end
|
48
|
+
trace_lines << position
|
49
|
+
break if trace_file =~ /example\/example_methods\.rb$/ or trace_file =~ /example\/example_group_methods\.rb$/
|
50
|
+
break if trace_lines.size > 10
|
51
|
+
# TODO: send multiple trace to be parse with pages.rb
|
52
|
+
# break if trace_file =~ /example\/example_methods\.rb$/ or trace_file =~ /example\/example_group_methods\.rb$/ or trace_file =~ /driver\.rb$/ or trace_file =~ /timeout\.rb$/ # don't include rspec or ruby trace
|
53
|
+
end
|
54
|
+
|
55
|
+
# (trace_file.include?("_spec.rb") || trace_file.include?("_rwebspec.rb") || trace_file.include?("_test.rb") || trace_file.include?("_cmd.rb"))
|
56
|
+
if !trace_lines.empty?
|
57
|
+
connect_to_testwise(" TRACE", trace_lines.reverse.join("|"))
|
58
|
+
end
|
59
|
+
|
60
|
+
rescue => e
|
61
|
+
puts "failed to capture log: #{e}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def connect_to_testwise (message_type, body)
|
67
|
+
begin
|
68
|
+
the_message = message_type + "|" + body
|
69
|
+
if @last_message == the_message then # ignore the message same as preivous one
|
70
|
+
return
|
71
|
+
end
|
72
|
+
itest_port = $ITEST2_TRACE_PORT || 7025
|
73
|
+
itest_socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
|
74
|
+
itest_socket.connect(Socket.pack_sockaddr_in(itest_port, '127.0.0.1'))
|
75
|
+
itest_socket.puts(the_message)
|
76
|
+
@last_message = the_message
|
77
|
+
itest_socket.close
|
78
|
+
rescue => e
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
79
83
|
end
|
data/lib/rwebspec/web_browser.rb
CHANGED
@@ -5,10 +5,12 @@
|
|
5
5
|
|
6
6
|
begin
|
7
7
|
require 'watir'
|
8
|
-
require 'watir/ie'
|
9
8
|
require 'watir/contrib/enabled_popup'
|
10
|
-
require 'watir/contrib/visible'
|
11
9
|
require 'watir/close_all'
|
10
|
+
require 'watir/screen_capture'
|
11
|
+
# NO need any more
|
12
|
+
# require 'watir/ie'
|
13
|
+
# require 'watir/contrib/visible'
|
12
14
|
$watir_loaded = true
|
13
15
|
rescue LoadError => e
|
14
16
|
$watir_loaded = false
|
@@ -93,7 +95,7 @@ module RWebSpec
|
|
93
95
|
firefox_jssh = Net::Telnet::new("Host" => "127.0.0.1", "Port" => 9997)
|
94
96
|
FireWatir::Firefox.firefox_started = true
|
95
97
|
rescue => e
|
96
|
-
|
98
|
+
puts "The firefox brower with JSSH is not available, #{e}"
|
97
99
|
sleep 1
|
98
100
|
end
|
99
101
|
@browser = FireWatir::Firefox.start(base_url)
|
@@ -103,7 +105,6 @@ module RWebSpec
|
|
103
105
|
default_celerity_options = { :proxy => nil, :browser => :firefox, :resynchronize => true, :log_level => :off }
|
104
106
|
options = default_celerity_options.merge options
|
105
107
|
options.each { |k, v| options.delete(k) unless default_celerity_options.keys.include?(k)}
|
106
|
-
puts "Starting Celerity: #{options.inspect}"
|
107
108
|
@browser = Celerity::Browser.new(options)
|
108
109
|
@browser.goto(base_url)
|
109
110
|
end
|
@@ -111,6 +112,12 @@ module RWebSpec
|
|
111
112
|
def initialize_ie_browser(existing_browser, options)
|
112
113
|
if existing_browser then
|
113
114
|
@browser = existing_browser
|
115
|
+
if $ITEST2_EMULATE_TYPING && $ITEST2_TYPING_SPEED then
|
116
|
+
@browser.set_slow_speed if $ITEST2_TYPING_SPEED == 'slow'
|
117
|
+
@browser.set_fast_speed if $ITEST2_TYPING_SPEED == 'fast'
|
118
|
+
else
|
119
|
+
@browser.speed = :zippy
|
120
|
+
end
|
114
121
|
return
|
115
122
|
end
|
116
123
|
|
@@ -136,7 +143,7 @@ module RWebSpec
|
|
136
143
|
Watir::IE.each do |browser_window|
|
137
144
|
return WebBrowser.new(base_url, browser_window, options)
|
138
145
|
end
|
139
|
-
puts "no browser instance found"
|
146
|
+
#puts "no browser instance found"
|
140
147
|
WebBrowser.new(base_url, nil, options)
|
141
148
|
else
|
142
149
|
WebBrowser.new(base_url, nil, options)
|
@@ -331,42 +338,71 @@ module RWebSpec
|
|
331
338
|
|
332
339
|
alias set_form_element enter_text_into_field_with_name
|
333
340
|
alias enter_text enter_text_into_field_with_name
|
341
|
+
alias set_hidden_field set_form_element
|
334
342
|
|
335
343
|
#links
|
336
|
-
def click_link_with_id(link_id)
|
337
|
-
|
344
|
+
def click_link_with_id(link_id, opts = {})
|
345
|
+
if opts && opts[:index]
|
346
|
+
wait_before_and_after { link(:id => link_id, :index => opts[:index]).click }
|
347
|
+
else
|
348
|
+
wait_before_and_after { link(:id, link_id).click }
|
349
|
+
end
|
338
350
|
end
|
339
351
|
|
340
|
-
def click_link_with_text(text)
|
341
|
-
|
352
|
+
def click_link_with_text(text, opts = {})
|
353
|
+
if opts && opts[:index]
|
354
|
+
wait_before_and_after { link(:text => text, :index => opts[:index]).click }
|
355
|
+
else
|
356
|
+
wait_before_and_after { link(:text, text).click }
|
357
|
+
end
|
342
358
|
end
|
359
|
+
alias click_link click_link_with_text
|
343
360
|
|
361
|
+
|
344
362
|
# Click a button with give HTML id
|
345
363
|
# Usage:
|
346
364
|
# click_button_with_id("btn_sumbit")
|
347
|
-
def click_button_with_id(id)
|
348
|
-
|
365
|
+
def click_button_with_id(id, opts = {})
|
366
|
+
if opts && opts[:index]
|
367
|
+
wait_before_and_after { button(:id => id, :index => opts[:index]).click }
|
368
|
+
else
|
369
|
+
wait_before_and_after { button(:id, id).click }
|
370
|
+
end
|
349
371
|
end
|
350
372
|
|
351
373
|
# Click a button with give name
|
352
374
|
# Usage:
|
353
375
|
# click_button_with_name("confirm")
|
354
|
-
def click_button_with_name(name)
|
355
|
-
|
376
|
+
def click_button_with_name(name, opts={})
|
377
|
+
if opts && opts[:index]
|
378
|
+
wait_before_and_after { button(:name => name, :index => opts[:index]).click }
|
379
|
+
else
|
380
|
+
wait_before_and_after { button(:name, name).click }
|
381
|
+
end
|
356
382
|
end
|
357
383
|
|
358
384
|
# Click a button with caption
|
359
385
|
# Usage:
|
360
386
|
# click_button_with_caption("Confirm payment")
|
361
|
-
def click_button_with_caption(caption)
|
362
|
-
|
387
|
+
def click_button_with_caption(caption, opts={})
|
388
|
+
if opts && opts[:index]
|
389
|
+
wait_before_and_after { button(:caption => caption, :index => opts[:index]).click }
|
390
|
+
else
|
391
|
+
wait_before_and_after { button(:caption, caption).click }
|
392
|
+
end
|
363
393
|
end
|
394
|
+
alias click_button click_button_with_caption
|
395
|
+
alias click_button_with_text click_button_with_caption
|
364
396
|
|
365
397
|
# Click a button with value
|
366
398
|
# Usage:
|
367
399
|
# click_button_with_value("Confirm payment")
|
368
|
-
def click_button_with_value(value)
|
369
|
-
|
400
|
+
def click_button_with_value(value, opts={})
|
401
|
+
if opts && opts[:index]
|
402
|
+
wait_before_and_after { button(:value => value, :index => opts[:index]).click }
|
403
|
+
else
|
404
|
+
wait_before_and_after { button(:value, value).click }
|
405
|
+
end
|
370
406
|
end
|
371
407
|
|
372
408
|
# Select a dropdown list by name
|
@@ -426,6 +462,7 @@ module RWebSpec
|
|
426
462
|
def click_radio_option(radio_group, radio_option)
|
427
463
|
radio(:name, radio_group, radio_option).set
|
428
464
|
end
|
465
|
+
alias click_radio_button click_radio_option
|
429
466
|
|
430
467
|
# Clear a radio button
|
431
468
|
# Usage:
|
@@ -433,6 +470,7 @@ module RWebSpec
|
|
433
470
|
def clear_radio_option(radio_group, radio_option)
|
434
471
|
radio(:name, radio_group, radio_option).clear
|
435
472
|
end
|
473
|
+
alias clear_radio_button clear_radio_option
|
436
474
|
|
437
475
|
# Deprecated: using Watir style directly instead
|
438
476
|
def element_by_id(elem_id)
|
@@ -557,6 +595,18 @@ module RWebSpec
|
|
557
595
|
end
|
558
596
|
|
559
597
|
|
598
|
+
# Verify the next page following an operation.
|
599
|
+
#
|
600
|
+
# Typical usage:
|
601
|
+
# browser.expect_page HomePage
|
602
|
+
def expect_page(page_clazz, argument = nil)
|
603
|
+
if argument
|
604
|
+
page_clazz.new(self, argument)
|
605
|
+
else
|
606
|
+
page_clazz.new(self)
|
607
|
+
end
|
608
|
+
end
|
609
|
+
|
560
610
|
# is it running in MS Windows platforms?
|
561
611
|
def self.is_windows?
|
562
612
|
RUBY_PLATFORM.downcase.include?("mswin") or RUBY_PLATFORM.downcase.include?("mingw")
|
data/lib/rwebspec/web_page.rb
CHANGED
@@ -27,12 +27,12 @@ module RWebSpec
|
|
27
27
|
|
28
28
|
# browser: passed to do assertion within the page
|
29
29
|
# page_text: text used to identify the page, title will be the first candidate
|
30
|
-
attr_accessor :
|
30
|
+
attr_accessor :page_specific_text
|
31
31
|
|
32
|
-
def initialize(the_browser,
|
32
|
+
def initialize(the_browser, page_specific_text = nil)
|
33
33
|
@web_browser = the_browser
|
34
34
|
@web_tester = the_browser
|
35
|
-
@
|
35
|
+
@page_specific_text = page_specific_text
|
36
36
|
begin
|
37
37
|
snapshot if $ITEST2_DUMP_PAGE
|
38
38
|
delay = $ITEST2_PAGE_DELAY
|
@@ -53,11 +53,11 @@ module RWebSpec
|
|
53
53
|
# ....
|
54
54
|
# home_page.assert_on_page # will check the text 'Welcome to iTest2' still present on the page
|
55
55
|
def assert_on_page()
|
56
|
-
assert_text_present(@
|
56
|
+
assert_text_present(@page_specific_text) if @page_specific_text
|
57
57
|
end
|
58
58
|
|
59
59
|
def assert_not_on_page()
|
60
|
-
assert_text_not_present(@
|
60
|
+
assert_text_not_present(@page_specific_text) if @page_specific_text
|
61
61
|
end
|
62
62
|
|
63
63
|
def dump(stream = nil)
|
@@ -90,7 +90,7 @@ module RWebSpec
|
|
90
90
|
end
|
91
91
|
return found
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
# Will save current page source to a file
|
95
95
|
# home_page = HomePage.new("Welcome to iTest2")
|
96
96
|
# ...
|
data/lib/rwebspec.rb
CHANGED
@@ -13,19 +13,23 @@ end
|
|
13
13
|
require 'active_support/core_ext'
|
14
14
|
require 'spec'
|
15
15
|
|
16
|
-
|
16
|
+
unless defined? RWEBSPEC_VERSION
|
17
|
+
RWEBSPEC_VERSION = RWEBUNIT_VERSION = "1.6"
|
18
|
+
end
|
17
19
|
|
18
20
|
# Extra full path to load libraries
|
19
21
|
require File.dirname(__FILE__) + "/rwebspec/using_pages"
|
20
22
|
require File.dirname(__FILE__) + "/rwebspec/test_utils"
|
21
23
|
require File.dirname(__FILE__) + "/rwebspec/web_page"
|
22
24
|
require File.dirname(__FILE__) + "/rwebspec/assert"
|
23
|
-
require File.dirname(__FILE__) + "/rwebspec/itest_plugin"
|
24
25
|
require File.dirname(__FILE__) + "/rwebspec/web_browser"
|
25
26
|
require File.dirname(__FILE__) + "/rwebspec/driver"
|
26
27
|
require File.dirname(__FILE__) + "/rwebspec/test_script"
|
27
28
|
require File.dirname(__FILE__) + "/rwebspec/context"
|
28
29
|
require File.dirname(__FILE__) + "/rwebspec/rspec_helper"
|
30
|
+
require File.dirname(__FILE__) + "/rwebspec/load_test_helper"
|
29
31
|
require File.dirname(__FILE__) + "/rspec_extensions"
|
30
32
|
require File.dirname(__FILE__) + "/watir_extensions"
|
31
33
|
require File.dirname(__FILE__) + "/rwebspec/matchers/contains_text"
|
34
|
+
require File.dirname(__FILE__) + "/rwebspec/testwise_plugin"
|
35
|
+
|