rformspec 0.4-x86-mingw32 → 0.5.1-x86-mingw32
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 +57 -49
- data/MIT-LICENSE +21 -21
- data/README +24 -24
- data/Rakefile +63 -63
- data/docs/index.html +183 -183
- data/lib/ext/rspec_rformunit.rb +46 -46
- data/lib/rformspec.rb +41 -41
- data/lib/rformspec/control.rb +160 -153
- data/lib/rformspec/driver.rb +120 -72
- data/lib/rformspec/form_testcase.rb +40 -40
- data/lib/rformspec/keyboard.rb +24 -24
- data/lib/rformspec/mouse.rb +55 -55
- data/lib/rformspec/open_file_dialog.rb +19 -19
- data/lib/rformspec/process.rb +27 -27
- data/lib/rformspec/saveas_file_dialog.rb +18 -18
- data/lib/rformspec/testwise_plugin.rb +92 -0
- data/lib/rformspec/window.rb +130 -114
- data/sample/form_calculator/calc_helper.rb +68 -68
- data/sample/form_calculator/calc_spec.rb +33 -33
- data/sample/form_calculator/calculator.tpr +27 -27
- data/sample/form_calculator/calculator.tws +13 -13
- data/sample/mouse.rb +19 -19
- data/sample/notepad.rb +19 -19
- data/sample/notepad1.rb +14 -14
- data/sample/test_calc.rb +33 -33
- metadata +9 -7
data/lib/rformspec/driver.rb
CHANGED
@@ -1,72 +1,120 @@
|
|
1
|
-
require 'win32ole'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def
|
17
|
-
driver.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
def
|
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
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
1
|
+
require 'win32ole'
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), "testwise_plugin.rb")
|
4
|
+
|
5
|
+
module RFormSpec
|
6
|
+
module Driver
|
7
|
+
|
8
|
+
include TestWisePlugin
|
9
|
+
|
10
|
+
def driver
|
11
|
+
dump_caller_stack
|
12
|
+
return $a3 if $a3
|
13
|
+
return RFormSpec::AutoIt.init
|
14
|
+
end
|
15
|
+
|
16
|
+
def wait_for_window(win, timeout=30)
|
17
|
+
driver.WinWait(win.title, win.text, timeout * 1000)
|
18
|
+
end
|
19
|
+
|
20
|
+
def wait_and_focus_window(title, text="", timeout=5)
|
21
|
+
try_for(timeout) {
|
22
|
+
found_window = driver.WinExists(title, text)
|
23
|
+
raise "Window '#{title}' not found" unless found_window.to_i == 1
|
24
|
+
}
|
25
|
+
driver.WinActivate(title, text)
|
26
|
+
sleep 0.5
|
27
|
+
# check whether suceed
|
28
|
+
if driver.WinActive(title, text).to_i != 1
|
29
|
+
raise "Failed to make window '#{title}' active"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def window_exists?(title)
|
35
|
+
driver.WinExists(title) > 0
|
36
|
+
end
|
37
|
+
|
38
|
+
def focus_window(title, text = nil)
|
39
|
+
if text
|
40
|
+
driver.WinActivate(title, text)
|
41
|
+
else
|
42
|
+
driver.WinActivate(title)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def close_window(title)
|
47
|
+
driver.WinClose(title)
|
48
|
+
end
|
49
|
+
|
50
|
+
# wrapper of keyboard operations
|
51
|
+
def key_press(keys)
|
52
|
+
dump_caller_stack
|
53
|
+
|
54
|
+
if keys =~ /^Ctrl\+([A-Z])$/
|
55
|
+
filtered_keys = "^+#{$1}"
|
56
|
+
elsif keys =~ /^Ctrl\+Shift\+([A-Z])$/
|
57
|
+
filtered_keys = "^+#{$1.downcase}"
|
58
|
+
elsif keys =~ /^Alt+([A-Z])$/
|
59
|
+
filtered_keys = "!+#{$1}"
|
60
|
+
elsif keys =~ /^Alt\+Shift\+([a-z])$/
|
61
|
+
filtered_keys = "!+#{$1.downcase}"
|
62
|
+
else
|
63
|
+
filtered_keys = keys
|
64
|
+
end
|
65
|
+
filtered_keys = keys.gsub("Alt+", "!+").gsub("Ctrl+", "^+")
|
66
|
+
RFormSpec::Keyboard.press(filtered_keys)
|
67
|
+
sleep 0.5
|
68
|
+
end
|
69
|
+
alias press_key key_press
|
70
|
+
|
71
|
+
# Wrapper of mouse operation
|
72
|
+
def mouse_move(x, y)
|
73
|
+
RFormSpec::Mouse.move_to(x, y)
|
74
|
+
end
|
75
|
+
|
76
|
+
def mouse_click(x, y)
|
77
|
+
RFormSpec::Mouse.click(x, y)
|
78
|
+
end
|
79
|
+
|
80
|
+
# standard open file dialog
|
81
|
+
def open_file_dialog(title, filepath, text="")
|
82
|
+
wait_and_focus_window(title)
|
83
|
+
dialog = RFormSpec::OpenFileDialog.new(title, text)
|
84
|
+
dialog.enter_filepath(filepath)
|
85
|
+
sleep 1
|
86
|
+
dialog.click_open
|
87
|
+
end
|
88
|
+
|
89
|
+
#TODO: save as file dialog
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
# helper
|
94
|
+
# Try the operation up to specified timeout (in seconds), and sleep given interval (in seconds).
|
95
|
+
# Error will be ignored until timeout
|
96
|
+
# Example
|
97
|
+
# try_for { click_link('waiting')}
|
98
|
+
# try_for (10, 2) { click_button('Search' } # try to click the 'Search' button upto 10 seconds, try every 2 seconds
|
99
|
+
# try_for { click_button('Search' }
|
100
|
+
def try_for(timeout = 30, polling_interval = 1, &block)
|
101
|
+
start_time = Time.now
|
102
|
+
|
103
|
+
last_error = nil
|
104
|
+
until (duration = Time.now - start_time) > timeout
|
105
|
+
begin
|
106
|
+
yield
|
107
|
+
last_error = nil
|
108
|
+
return true
|
109
|
+
rescue => e
|
110
|
+
last_error = e
|
111
|
+
end
|
112
|
+
sleep polling_interval
|
113
|
+
end
|
114
|
+
|
115
|
+
raise "Timeout after #{duration.to_i} seconds with error: #{last_error}." if last_error
|
116
|
+
raise "Timeout after #{duration.to_i} seconds."
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
@@ -1,40 +1,40 @@
|
|
1
|
-
#***********************************************************
|
2
|
-
#* Copyright (c) 2006, Zhimin Zhan.
|
3
|
-
#* Distributed open-source, see full license in MIT-LICENSE
|
4
|
-
#***********************************************************
|
5
|
-
|
6
|
-
require 'test/unit'
|
7
|
-
|
8
|
-
module RFormSpec
|
9
|
-
class FormTestCase < Test::Unit::TestCase
|
10
|
-
include RFormSpec::Driver
|
11
|
-
|
12
|
-
def default_test
|
13
|
-
super unless(self.class == FormTestCase)
|
14
|
-
end
|
15
|
-
|
16
|
-
# assert the block's return value instance every 1 second until timeout with specifed duration
|
17
|
-
def timeout_check_equal(duration, expected, &block)
|
18
|
-
execute_ok = false
|
19
|
-
duration.times do
|
20
|
-
sleep(1)
|
21
|
-
text = instance_eval(&block)
|
22
|
-
execute_ok = true and break if (text == expected)
|
23
|
-
end
|
24
|
-
execute_ok.should == true
|
25
|
-
end
|
26
|
-
|
27
|
-
#
|
28
|
-
def timeout_check_include?(duration, expected, &block)
|
29
|
-
execute_ok = false
|
30
|
-
duration.times do
|
31
|
-
sleep(1)
|
32
|
-
text = instance_eval(&block)
|
33
|
-
execute_ok = true and break if text and text.include?(expected)
|
34
|
-
end
|
35
|
-
execute_ok.should == true
|
36
|
-
end
|
37
|
-
alias timeout_check_include timeout_check_include?
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
1
|
+
#***********************************************************
|
2
|
+
#* Copyright (c) 2006, Zhimin Zhan.
|
3
|
+
#* Distributed open-source, see full license in MIT-LICENSE
|
4
|
+
#***********************************************************
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
|
8
|
+
module RFormSpec
|
9
|
+
class FormTestCase < Test::Unit::TestCase
|
10
|
+
include RFormSpec::Driver
|
11
|
+
|
12
|
+
def default_test
|
13
|
+
super unless(self.class == FormTestCase)
|
14
|
+
end
|
15
|
+
|
16
|
+
# assert the block's return value instance every 1 second until timeout with specifed duration
|
17
|
+
def timeout_check_equal(duration, expected, &block)
|
18
|
+
execute_ok = false
|
19
|
+
duration.times do
|
20
|
+
sleep(1)
|
21
|
+
text = instance_eval(&block)
|
22
|
+
execute_ok = true and break if (text == expected)
|
23
|
+
end
|
24
|
+
execute_ok.should == true
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
def timeout_check_include?(duration, expected, &block)
|
29
|
+
execute_ok = false
|
30
|
+
duration.times do
|
31
|
+
sleep(1)
|
32
|
+
text = instance_eval(&block)
|
33
|
+
execute_ok = true and break if text and text.include?(expected)
|
34
|
+
end
|
35
|
+
execute_ok.should == true
|
36
|
+
end
|
37
|
+
alias timeout_check_include timeout_check_include?
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/lib/rformspec/keyboard.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/driver"
|
2
|
-
require 'singleton'
|
3
|
-
|
4
|
-
module RFormSpec
|
5
|
-
class Keyboard
|
6
|
-
include Singleton
|
7
|
-
include Driver
|
8
|
-
|
9
|
-
def self.type(keys)
|
10
|
-
instance._type(keys)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.press(key)
|
14
|
-
instance._type(key)
|
15
|
-
end
|
16
|
-
|
17
|
-
# instance methods
|
18
|
-
def _type(keystrokes)
|
19
|
-
driver.Send(keystrokes)
|
20
|
-
end
|
21
|
-
alias _press _type
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
1
|
+
require File.dirname(__FILE__) + "/driver"
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module RFormSpec
|
5
|
+
class Keyboard
|
6
|
+
include Singleton
|
7
|
+
include Driver
|
8
|
+
|
9
|
+
def self.type(keys)
|
10
|
+
instance._type(keys)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.press(key)
|
14
|
+
instance._type(key)
|
15
|
+
end
|
16
|
+
|
17
|
+
# instance methods
|
18
|
+
def _type(keystrokes)
|
19
|
+
driver.Send(keystrokes)
|
20
|
+
end
|
21
|
+
alias _press _type
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/rformspec/mouse.rb
CHANGED
@@ -1,55 +1,55 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/driver"
|
2
|
-
require 'singleton'
|
3
|
-
|
4
|
-
module RFormSpec
|
5
|
-
|
6
|
-
class Mouse
|
7
|
-
include Singleton
|
8
|
-
include Driver
|
9
|
-
|
10
|
-
def self.click(x=nil, y=nil)
|
11
|
-
instance._click(x, y)
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.right_click(x=nil, y=nil)
|
15
|
-
instance._right_click(x, y)
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.double_click(x, y)
|
19
|
-
instance._double_click(x,y)
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.move_to(x, y)
|
23
|
-
instance._move_to(x,y)
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
# intance methods
|
28
|
-
|
29
|
-
def _click(x=nil, y=nil)
|
30
|
-
if (x and y) then
|
31
|
-
driver.MouseClick("left", x, y)
|
32
|
-
else
|
33
|
-
driver.MouseClick("left")
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def _right_click(x=nil, y=nil)
|
38
|
-
if (x and y) then
|
39
|
-
driver.MouseClick("right", x, y)
|
40
|
-
else
|
41
|
-
driver.MouseClick("right")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def _double_click(x, y)
|
46
|
-
driver.MouseClick("left", x, y, 2)
|
47
|
-
end
|
48
|
-
|
49
|
-
def _move_to(x, y)
|
50
|
-
driver.MouseMove(x,y)
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
1
|
+
require File.dirname(__FILE__) + "/driver"
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module RFormSpec
|
5
|
+
|
6
|
+
class Mouse
|
7
|
+
include Singleton
|
8
|
+
include Driver
|
9
|
+
|
10
|
+
def self.click(x=nil, y=nil)
|
11
|
+
instance._click(x, y)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.right_click(x=nil, y=nil)
|
15
|
+
instance._right_click(x, y)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.double_click(x, y)
|
19
|
+
instance._double_click(x,y)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.move_to(x, y)
|
23
|
+
instance._move_to(x,y)
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
# intance methods
|
28
|
+
|
29
|
+
def _click(x=nil, y=nil)
|
30
|
+
if (x and y) then
|
31
|
+
driver.MouseClick("left", x, y)
|
32
|
+
else
|
33
|
+
driver.MouseClick("left")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def _right_click(x=nil, y=nil)
|
38
|
+
if (x and y) then
|
39
|
+
driver.MouseClick("right", x, y)
|
40
|
+
else
|
41
|
+
driver.MouseClick("right")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def _double_click(x, y)
|
46
|
+
driver.MouseClick("left", x, y, 2)
|
47
|
+
end
|
48
|
+
|
49
|
+
def _move_to(x, y)
|
50
|
+
driver.MouseMove(x,y)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
module RFormSpec
|
2
|
-
class OpenFileDialog < RFormSpec::Window
|
3
|
-
|
4
|
-
def initialize(title = "Open File")
|
5
|
-
focus_window(title)
|
6
|
-
end
|
7
|
-
|
8
|
-
def enter_filepath(file_path)
|
9
|
-
get_text # somehow calling it get it loaded
|
10
|
-
set_control_text("Edit1", file_path)
|
11
|
-
end
|
12
|
-
|
13
|
-
def click_open
|
14
|
-
click_button("Button2")
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
1
|
+
module RFormSpec
|
2
|
+
class OpenFileDialog < RFormSpec::Window
|
3
|
+
|
4
|
+
def initialize(title = "Open File", text = "")
|
5
|
+
focus_window(title, text)
|
6
|
+
end
|
7
|
+
|
8
|
+
def enter_filepath(file_path)
|
9
|
+
get_text # somehow calling it get it loaded
|
10
|
+
set_control_text("Edit1", file_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def click_open
|
14
|
+
click_button("Button2")
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|