rwebspec 1.9 → 1.9.2
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 +8 -2
- data/Rakefile +3 -3
- data/lib/rwebspec/driver.rb +8 -30
- data/lib/rwebspec/rspec_helper.rb +1 -1
- data/lib/rwebspec/test_utils.rb +5 -1
- data/lib/rwebspec/testwise_plugin.rb +92 -82
- data/lib/rwebspec/web_browser.rb +8 -16
- data/lib/rwebspec/web_page.rb +2 -2
- metadata +7 -7
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
@@ -70,9 +70,9 @@ end
|
|
70
70
|
spec = Gem::Specification.new do |s|
|
71
71
|
s.platform= Gem::Platform::RUBY
|
72
72
|
s.name = "rwebspec"
|
73
|
-
s.version = "1.9"
|
73
|
+
s.version = "1.9.2"
|
74
74
|
s.summary = "Executable functional specification for web applications in RSpec syntax and Watir"
|
75
|
-
|
75
|
+
s.description = "Executable functional specification for web applications in RSpec syntax and Watir"
|
76
76
|
|
77
77
|
s.author = "Zhimin Zhan"
|
78
78
|
s.email = "zhimin@agileway.com.au"
|
@@ -91,7 +91,7 @@ spec = Gem::Specification.new do |s|
|
|
91
91
|
s.files = s.files + Dir.glob( "docs/**/*" )
|
92
92
|
s.add_dependency(%q<rspec>, ["= 1.1.12"])
|
93
93
|
|
94
|
-
s.add_dependency("commonwatir", ">=
|
94
|
+
s.add_dependency("commonwatir", ">= 2.0")
|
95
95
|
end
|
96
96
|
|
97
97
|
Rake::GemPackageTask.new(spec) do |pkg|
|
data/lib/rwebspec/driver.rb
CHANGED
@@ -41,6 +41,7 @@ module RWebSpec
|
|
41
41
|
puts "Unicode may not work in IE, #{e}"
|
42
42
|
end
|
43
43
|
|
44
|
+
base_url ||= $TESTWISE_PROJECT_BASE_URL
|
44
45
|
base_url ||= $ITEST2_PROJECT_BASE_URL
|
45
46
|
base_url ||= $BASE_URL
|
46
47
|
raise "base_url must be set" if base_url.nil?
|
@@ -53,8 +54,8 @@ module RWebSpec
|
|
53
54
|
:go => true}
|
54
55
|
|
55
56
|
options = default_options.merge options
|
56
|
-
options[:firefox] = true if "Firefox" == $ITEST2_BROWSER || "Firefox" == $BROWSER
|
57
|
-
($ITEST2_HIDE_BROWSER) ? $HIDE_IE = true : $HIDE_IE = false
|
57
|
+
options[:firefox] = true if "Firefox" == $ITEST2_BROWSER || "Firefox" == $TESTWISE_BROWSER || "Firefox" == $BROWSER
|
58
|
+
($TESTWISE_HIDE_BROWSER || $ITEST2_HIDE_BROWSER) ? $HIDE_IE = true : $HIDE_IE = false
|
58
59
|
|
59
60
|
if base_url =~ /^file:/
|
60
61
|
uri_base = base_url
|
@@ -196,7 +197,7 @@ module RWebSpec
|
|
196
197
|
if url && url =~ /^http/
|
197
198
|
http_response = client.get(url).body
|
198
199
|
else
|
199
|
-
base_url = $ITEST2_PROJECT_BASE_URL || $BASE_URL
|
200
|
+
base_url = $TESTWISE_PROJECT_BASE_URL || $ITEST2_PROJECT_BASE_URL || $BASE_URL
|
200
201
|
http_response = client.get("#{base_url}#{url}").body
|
201
202
|
end
|
202
203
|
|
@@ -397,14 +398,14 @@ module RWebSpec
|
|
397
398
|
end
|
398
399
|
|
399
400
|
def default_dump_dir
|
400
|
-
if $ITEST2_RUNNING_SPEC_ID && $ITEST2_WORKING_DIR
|
401
|
+
if ($TESTWISE_RUNNING_SPEC_ID && $TESTWISE_WORKING_DIR) || ($ITEST2_RUNNING_SPEC_ID && $ITEST2_WORKING_DIR)
|
401
402
|
|
402
|
-
$ITEST2_DUMP_DIR = File.join($ITEST2_WORKING_DIR, "dump")
|
403
|
+
$TESTWISE_DUMP_DIR = $ITEST2_DUMP_DIR = File.join($ITEST2_WORKING_DIR, "dump")
|
403
404
|
FileUtils.mkdir($ITEST2_DUMP_DIR) unless File.exists?($ITEST2_DUMP_DIR)
|
404
405
|
|
405
|
-
spec_run_id = $ITEST2_RUNNING_SPEC_ID
|
406
|
+
spec_run_id = $TESTWISE_RUNNING_SPEC_ID || $ITEST2_RUNNING_SPEC_ID
|
406
407
|
spec_run_dir_name = spec_run_id.to_s.rjust(4, "0") unless spec_run_id == "unknown"
|
407
|
-
to_dir = File.join($
|
408
|
+
to_dir = File.join($TESTWISE_DUMP_DIR, spec_run_dir_name)
|
408
409
|
else
|
409
410
|
to_dir = ENV['TEMP_DIR'] || (is_windows? ? "C:\\temp" : "/tmp")
|
410
411
|
end
|
@@ -973,29 +974,6 @@ module RWebSpec
|
|
973
974
|
end
|
974
975
|
end
|
975
976
|
|
976
|
-
# take_screenshot to save the current active window
|
977
|
-
# TODO can't move mouse
|
978
|
-
def take_screenshot_old
|
979
|
-
if is_windows? && $ITEST2_DUMP_PAGE
|
980
|
-
begin
|
981
|
-
puts "[DEBUG] Capturing screenshots..."
|
982
|
-
screenshot_image_filename = "rwebspec_" + Time.now.strftime("%m%d%H%M%S") + ".jpg"
|
983
|
-
the_dump_dir = default_dump_dir
|
984
|
-
FileUtils.mkdir_p(the_dump_dir) unless File.exists?(the_dump_dir)
|
985
|
-
screenshot_image_filepath = File.join(the_dump_dir, screenshot_image_filename)
|
986
|
-
|
987
|
-
screenshot_image_filepath.gsub!("/", "\\") if is_windows?
|
988
|
-
screen_capture(screenshot_image_filepath, true)
|
989
|
-
|
990
|
-
notify_screenshot_location(screenshot_image_filepath)
|
991
|
-
rescue
|
992
|
-
puts "error: #{Failed to capture screen}"
|
993
|
-
end
|
994
|
-
end
|
995
|
-
end
|
996
|
-
|
997
|
-
|
998
|
-
|
999
977
|
# use win32screenshot library to save curernt active window, which shall be IE
|
1000
978
|
#
|
1001
979
|
def take_screenshot
|
@@ -80,7 +80,7 @@ module RWebSpec
|
|
80
80
|
|
81
81
|
# When running
|
82
82
|
def debugging?
|
83
|
-
$ITEST2_DEBUGGING && $ITEST2_RUNNING_AS == "test_case"
|
83
|
+
($ITEST2_DEBUGGING && $ITEST2_RUNNING_AS == "test_case") || ($TESTWISE_DEBUGGING && $TESTWISE_RUNNING_AS == "test_case")
|
84
84
|
end
|
85
85
|
|
86
86
|
# RSpec Matchers
|
data/lib/rwebspec/test_utils.rb
CHANGED
@@ -133,7 +133,11 @@ module RWebSpec
|
|
133
133
|
# Generate a given number of words. If a range is passed, it will generate
|
134
134
|
# a random number of words within that range.
|
135
135
|
def words(total)
|
136
|
-
|
136
|
+
if total.class == Range
|
137
|
+
(1..interpret_value(total)).map { WORDS[random_number(total.min, total.max)] }.join(' ')
|
138
|
+
else
|
139
|
+
(1..interpret_value(total)).map { WORDS[random_number(0, total)] }.join(' ')
|
140
|
+
end
|
137
141
|
end
|
138
142
|
|
139
143
|
# Generate a given number of sentences. If a range is passed, it will generate
|
@@ -1,83 +1,93 @@
|
|
1
|
-
require 'socket'
|
2
|
-
|
3
|
-
module RWebSpec
|
4
|
-
module TestWisePlugin
|
5
|
-
|
6
|
-
def debug(message)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
module RWebSpec
|
4
|
+
module TestWisePlugin
|
5
|
+
|
6
|
+
def debug(message)
|
7
|
+
Thread.pass
|
8
|
+
connect_to_testwise(" DEBUG", message.to_s + "\r\n") if $RUN_IN_TESTWISE && message
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
# Support of iTest to ajust the intervals between keystroke/mouse operations
|
13
|
+
def operation_delay
|
14
|
+
begin
|
15
|
+
if $ITEST2_OPERATION_DELAY && $ITEST2_OPERATION_DELAY > 0 &&
|
16
|
+
$ITEST2_OPERATION_DELAY < 30000 then # max 30 seconds
|
17
|
+
Thread.pass
|
18
|
+
sleep($ITEST2_OPERATION_DELAY / 1000)
|
19
|
+
end
|
20
|
+
|
21
|
+
if $TESTWISE_OPERATION_DELAY && $TESTWISE_OPERATION_DELAY > 0 &&
|
22
|
+
$TESTWISE_OPERATION_DELAY < 30000 then # max 30 seconds
|
23
|
+
Thread.pass
|
24
|
+
sleep($TESTWISE_OPERATION_DELAY / 1000)
|
25
|
+
end
|
26
|
+
|
27
|
+
while $TESTWISE_PAUSE || $ITEST2_PAUSE
|
28
|
+
Thread.pass
|
29
|
+
debug("Paused, waiting ...")
|
30
|
+
sleep 1
|
31
|
+
end
|
32
|
+
rescue => e
|
33
|
+
puts "Error on delaying: #{e}"
|
34
|
+
# ignore
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def notify_screenshot_location(image_file_path)
|
39
|
+
connect_to_testwise(" SHOT", image_file_path)
|
40
|
+
end
|
41
|
+
|
42
|
+
# find out the line (and file) the execution is on, and notify iTest via Socket
|
43
|
+
def dump_caller_stack
|
44
|
+
return unless ($TESTWISE_TRACE_EXECUTION || $ITEST2_TRACE_EXECUTION)
|
45
|
+
begin
|
46
|
+
trace_lines = []
|
47
|
+
trace_file = nil
|
48
|
+
found_first_spec_reference = false
|
49
|
+
caller.each_with_index do |position, idx|
|
50
|
+
next unless position =~ /\A(.*?):(\d+)/
|
51
|
+
trace_file = $1
|
52
|
+
if trace_file =~ /(_spec|_test|_rwebspec)\.rb\s*$/ || trace_file =~ /\.feature$/
|
53
|
+
found_first_spec_reference = true
|
54
|
+
trace_lines << position
|
55
|
+
break
|
56
|
+
end
|
57
|
+
trace_lines << position
|
58
|
+
break if trace_file =~ /example\/example_methods\.rb$/ or trace_file =~ /example\/example_group_methods\.rb$/
|
59
|
+
break if trace_lines.size > 10
|
60
|
+
# TODO: send multiple trace to be parse with pages.rb
|
61
|
+
# 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
|
62
|
+
end
|
63
|
+
|
64
|
+
# (trace_file.include?("_spec.rb") || trace_file.include?("_rwebspec.rb") || trace_file.include?("_test.rb") || trace_file.include?("_cmd.rb"))
|
65
|
+
if !trace_lines.empty?
|
66
|
+
connect_to_testwise(" TRACE", trace_lines.reverse.join("|"))
|
67
|
+
end
|
68
|
+
|
69
|
+
rescue => e
|
70
|
+
puts "failed to capture log: #{e}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def connect_to_testwise (message_type, body)
|
76
|
+
Thread.pass
|
77
|
+
begin
|
78
|
+
the_message = message_type + "|" + body
|
79
|
+
if @last_message == the_message then # ignore the message same as preivous one
|
80
|
+
return
|
81
|
+
end
|
82
|
+
itest_port = $TESTWISE_TRACE_PORT || $ITEST2_TRACE_PORT || 7025
|
83
|
+
itest_socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
|
84
|
+
itest_socket.connect(Socket.pack_sockaddr_in(itest_port, '127.0.0.1'))
|
85
|
+
itest_socket.puts(the_message)
|
86
|
+
@last_message = the_message
|
87
|
+
itest_socket.close
|
88
|
+
rescue => e
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
83
93
|
end
|
data/lib/rwebspec/web_browser.rb
CHANGED
@@ -111,24 +111,16 @@ module RWebSpec
|
|
111
111
|
end
|
112
112
|
|
113
113
|
def initialize_ie_browser(existing_browser, options)
|
114
|
-
|
115
|
-
|
116
|
-
if $
|
117
|
-
|
118
|
-
@browser.set_fast_speed if $ITEST2_TYPING_SPEED == 'fast'
|
119
|
-
else
|
120
|
-
@browser.speed = :zippy
|
121
|
-
end
|
122
|
-
return
|
123
|
-
end
|
124
|
-
|
125
|
-
@browser = Watir::IE.new
|
126
|
-
if $ITEST2_EMULATE_TYPING && $ITEST2_TYPING_SPEED then
|
127
|
-
@browser.set_slow_speed if $ITEST2_TYPING_SPEED == 'slow'
|
128
|
-
@browser.set_fast_speed if $ITEST2_TYPING_SPEED == 'fast'
|
114
|
+
@browser = existing_browser || Watir::IE.new
|
115
|
+
if ($TESTWISE_EMULATE_TYPING && $TESTWISE_TYPING_SPEED) || ($ITEST2_EMULATE_TYPING && $ITEST2_TYPING_SPEED) then
|
116
|
+
@browser.set_slow_speed if $TESTWISE_TYPING_SPEED == "slow" || $ITEST2_TYPING_SPEED == 'slow'
|
117
|
+
@browser.set_fast_speed if $TESTWISE_TYPING_SPEED == 'fast' || $ITEST2_TYPING_SPEED == 'fast'
|
129
118
|
else
|
130
119
|
@browser.speed = :zippy
|
131
120
|
end
|
121
|
+
|
122
|
+
return if existing_browser
|
123
|
+
|
132
124
|
@browser.activeObjectHighLightColor = options[:highlight_colour]
|
133
125
|
@browser.visible = options[:visible] unless $HIDE_IE
|
134
126
|
#NOTE: close_others fails
|
@@ -144,7 +136,7 @@ module RWebSpec
|
|
144
136
|
end
|
145
137
|
|
146
138
|
def self.reuse(base_url, options)
|
147
|
-
if self.is_windows? && $ITEST2_BROWSER != "Firefox"
|
139
|
+
if self.is_windows? && ($TESTWISE_BROWSER != "Firefox" && $ITEST2_BROWSER != "Firefox")
|
148
140
|
Watir::IE.each do |browser_window|
|
149
141
|
return WebBrowser.new(base_url, browser_window, options)
|
150
142
|
end
|
data/lib/rwebspec/web_page.rb
CHANGED
@@ -34,8 +34,8 @@ module RWebSpec
|
|
34
34
|
@web_tester = the_browser
|
35
35
|
@page_specific_text = page_specific_text
|
36
36
|
begin
|
37
|
-
snapshot if $ITEST2_DUMP_PAGE
|
38
|
-
delay = $ITEST2_PAGE_DELAY
|
37
|
+
snapshot if $TESTWISE_DUMP_PAGE || $ITEST2_DUMP_PAGE
|
38
|
+
delay = $TESTWISE_PAGE_DELAY || $ITEST2_PAGE_DELAY
|
39
39
|
sleep(delay)
|
40
40
|
rescue => e
|
41
41
|
end
|
metadata
CHANGED
@@ -5,7 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 9
|
8
|
-
|
8
|
+
- 2
|
9
|
+
version: 1.9.2
|
9
10
|
platform: ruby
|
10
11
|
authors:
|
11
12
|
- Zhimin Zhan
|
@@ -13,7 +14,7 @@ autorequire: rwebspec
|
|
13
14
|
bindir: bin
|
14
15
|
cert_chain: []
|
15
16
|
|
16
|
-
date: 2011-08-
|
17
|
+
date: 2011-08-18 00:00:00 +10:00
|
17
18
|
default_executable:
|
18
19
|
dependencies:
|
19
20
|
- !ruby/object:Gem::Dependency
|
@@ -38,13 +39,12 @@ dependencies:
|
|
38
39
|
- - ">="
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
segments:
|
41
|
-
-
|
42
|
-
-
|
43
|
-
|
44
|
-
version: 1.8.1
|
42
|
+
- 2
|
43
|
+
- 0
|
44
|
+
version: "2.0"
|
45
45
|
type: :runtime
|
46
46
|
version_requirements: *id002
|
47
|
-
description:
|
47
|
+
description: Executable functional specification for web applications in RSpec syntax and Watir
|
48
48
|
email: zhimin@agileway.com.au
|
49
49
|
executables: []
|
50
50
|
|