rformspec 0.4-x86-mingw32 → 0.5.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,72 +1,120 @@
1
- require 'win32ole'
2
-
3
- module RFormSpec
4
- module Driver
5
-
6
- def driver
7
- return $a3 if $a3
8
- return RFormSpec::AutoIt.init
9
- end
10
-
11
- def wait_for_window(win, timeout=30)
12
- driver.WinWait(win.title, win.text, timeout * 1000)
13
- win
14
- end
15
-
16
- def wait_and_focus_window(title, text="", timeout=30)
17
- driver.WinWaitActive(title, text, timeout * 1000)
18
- driver.WinActivate(title, text)
19
- end
20
-
21
- def window_exists?(title)
22
- driver.WinExists(title) > 0
23
- end
24
-
25
- def focus_window(title)
26
- driver.WinActivate(title)
27
- end
28
-
29
- def close_window(title)
30
- driver.WinClose(title)
31
- end
32
-
33
- # wrapper of keyboard operations
34
- def key_press(keys)
35
- if keys =~ /^Ctrl\+([A-Z])$/
36
- filtered_keys = "^+#{$1}"
37
- elsif keys =~ /^Ctrl\+Shift\+([A-Z])$/
38
- filtered_keys = "^+#{$1.downcase}"
39
- elsif keys =~ /^Alt+([A-Z])$/
40
- filtered_keys = "!+#{$1}"
41
- elsif keys =~ /^Alt\+Shift\+([a-z])$/
42
- filtered_keys = "!+#{$1.downcase}"
43
- else
44
- filtered_keys = keys
45
- end
46
- filtered_keys = keys.gsub("Alt+", "!+").gsub("Ctrl+", "^+")
47
- RFormSpec::Keyboard.press(filtered_keys)
48
- sleep 0.5
49
- end
50
- alias press_key key_press
51
-
52
- # Wrapper of mouse operation
53
- def mouse_move(x, y)
54
- RFormSpec::Mouse.move_to(x, y)
55
- end
56
-
57
- def mouse_click(x, y)
58
- RFormSpec::Mouse.click(x, y)
59
- end
60
-
61
- # standard open file dialog
62
- def open_file_dialog(title, filepath)
63
- wait_and_focus_window(title)
64
- dialog = RFormSpec::OpenFileDialog.new(title)
65
- dialog.enter_filepath(filepath)
66
- sleep 1
67
- dialog.click_open
68
- end
69
-
70
- #TODO: save as file dialog
71
- end
72
- end
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
@@ -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
@@ -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