rformspec 0.3.2-x86-mingw32 → 0.4-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 +7 -0
- data/Rakefile +1 -1
- data/lib/rformspec/driver.rb +12 -20
- data/lib/rformspec/window.rb +17 -7
- data/lib/rformspec.rb +26 -0
- data/sample/form_calculator/calc_helper.rb +68 -0
- data/sample/form_calculator/calc_spec.rb +33 -0
- data/sample/form_calculator/calculator.tpr +27 -0
- data/sample/form_calculator/calculator.tws +13 -0
- data/sample/mouse.rb +19 -0
- data/sample/notepad.rb +1 -1
- data/sample/notepad1.rb +2 -2
- data/sample/test_calc.rb +12 -2
- metadata +11 -12
- data/sample/calc.rb +0 -25
- data/sample/calc_spec.rb +0 -16
- data/sample/rspec_calc.rb +0 -24
data/CHANGELOG
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
|
+
|
4
|
+
0.4 (2011-10)
|
5
|
+
- Change Window class: not wait for active by default
|
6
|
+
- using global variable reference to AutoIt3 OLE
|
7
|
+
- New AutoIt class
|
8
|
+
- Examples update
|
9
|
+
|
3
10
|
0.3.2
|
4
11
|
|
5
12
|
Add option in Window class to wait to focus window (default)
|
data/Rakefile
CHANGED
@@ -34,7 +34,7 @@ Rake::RDocTask.new { |rdoc|
|
|
34
34
|
spec = Gem::Specification.new do |s|
|
35
35
|
s.platform= Gem::Platform::CURRENT
|
36
36
|
s.name = "rformspec"
|
37
|
-
s.version = "0.
|
37
|
+
s.version = "0.4"
|
38
38
|
s.summary = "An wrap of AUTOIT3 for functional testing of Windows form applications"
|
39
39
|
# s.description = ""
|
40
40
|
|
data/lib/rformspec/driver.rb
CHANGED
@@ -3,26 +3,9 @@ require 'win32ole'
|
|
3
3
|
module RFormSpec
|
4
4
|
module Driver
|
5
5
|
|
6
|
-
def init
|
7
|
-
driver
|
8
|
-
end
|
9
|
-
|
10
6
|
def driver
|
11
|
-
return
|
12
|
-
|
13
|
-
@a3 = WIN32OLE.new('AutoItX3.Control')
|
14
|
-
|
15
|
-
@a3.AutoItSetOption("CaretCoordMode", 0);
|
16
|
-
@a3.AutoItSetOption("ColorMode", 1);
|
17
|
-
@a3.AutoItSetOption("MouseCoordMode", 0);
|
18
|
-
@a3.AutoItSetOption("PixelCoordMode", 0);
|
19
|
-
@a3.AutoItSetOption("SendKeyDelay", 15)
|
20
|
-
return @a3
|
21
|
-
end
|
22
|
-
|
23
|
-
def set_autoit_option(key, value)
|
24
|
-
init if @a3.nil?
|
25
|
-
@a3.AutoItSetOption(key, value)
|
7
|
+
return $a3 if $a3
|
8
|
+
return RFormSpec::AutoIt.init
|
26
9
|
end
|
27
10
|
|
28
11
|
def wait_for_window(win, timeout=30)
|
@@ -32,6 +15,7 @@ module RFormSpec
|
|
32
15
|
|
33
16
|
def wait_and_focus_window(title, text="", timeout=30)
|
34
17
|
driver.WinWaitActive(title, text, timeout * 1000)
|
18
|
+
driver.WinActivate(title, text)
|
35
19
|
end
|
36
20
|
|
37
21
|
def window_exists?(title)
|
@@ -65,6 +49,15 @@ module RFormSpec
|
|
65
49
|
end
|
66
50
|
alias press_key key_press
|
67
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
|
+
|
68
61
|
# standard open file dialog
|
69
62
|
def open_file_dialog(title, filepath)
|
70
63
|
wait_and_focus_window(title)
|
@@ -75,6 +68,5 @@ module RFormSpec
|
|
75
68
|
end
|
76
69
|
|
77
70
|
#TODO: save as file dialog
|
78
|
-
|
79
71
|
end
|
80
72
|
end
|
data/lib/rformspec/window.rb
CHANGED
@@ -3,16 +3,24 @@ require File.dirname(__FILE__) + "/control"
|
|
3
3
|
|
4
4
|
module RFormSpec
|
5
5
|
|
6
|
-
|
7
6
|
class Window < BaseControl
|
8
7
|
attr_accessor :title, :text
|
9
|
-
|
10
|
-
|
8
|
+
|
9
|
+
##
|
10
|
+
# title : page title, depends autoit options, might use as substring match or exact match
|
11
|
+
# text: some text in window for further identifing the window
|
12
|
+
# options:
|
13
|
+
# present => true | false, already there
|
14
|
+
# wait_timeout: wiat for maxium seconds if not active, throw error
|
15
|
+
# (active: means the window becomes the active window)
|
16
|
+
# otherwise, inside window class, using focus_window methods
|
17
|
+
def initialize(title, text = '', options = {:present => false, :wait_timeout => 0})
|
11
18
|
# for some windows, the title might change depends when it is invoked
|
12
19
|
if title.class == Array
|
13
20
|
title.each { |a_title|
|
14
21
|
@title = a_title
|
15
22
|
@text = text if text
|
23
|
+
timeout = options[:wait_timeout]
|
16
24
|
result = driver.WinWaitActive(@title, @text, timeout)
|
17
25
|
return if result != 0
|
18
26
|
}
|
@@ -21,12 +29,14 @@ module RFormSpec
|
|
21
29
|
|
22
30
|
@title = title
|
23
31
|
@text = text if text
|
24
|
-
|
25
|
-
|
26
|
-
else
|
32
|
+
timeout = options[:wait_timeout]
|
33
|
+
if options[:present]
|
27
34
|
result = driver.WinActivate(@title, @text)
|
35
|
+
raise "window not found: #{self.to_s}" if result == 0
|
36
|
+
elsif timeout && timeout.to_i > 1 then
|
37
|
+
result = driver.WinWaitActive(@title, @text, timeout)
|
38
|
+
raise "timeout while waiting for window: #{self.to_s}" if result == 0
|
28
39
|
end
|
29
|
-
raise "timeout while waiting for window: #{self.to_s}" if result == 0
|
30
40
|
end
|
31
41
|
|
32
42
|
def focus
|
data/lib/rformspec.rb
CHANGED
@@ -13,3 +13,29 @@ require File.dirname(__FILE__) + "/rformspec/open_file_dialog"
|
|
13
13
|
require File.dirname(__FILE__) + "/rformspec/saveas_file_dialog"
|
14
14
|
require File.dirname(__FILE__) + "/rformspec/process"
|
15
15
|
require File.dirname(__FILE__) + "/rformspec/form_testcase"
|
16
|
+
|
17
|
+
module RFormSpec
|
18
|
+
|
19
|
+
class AutoIt
|
20
|
+
|
21
|
+
def self.init
|
22
|
+
$a3 = WIN32OLE.new('AutoItX3.Control')
|
23
|
+
|
24
|
+
$a3.AutoItSetOption("WinSearchChildren", 1); # Search Children window as well
|
25
|
+
$a3.AutoItSetOption("WinTitleMatchMode", 2);
|
26
|
+
|
27
|
+
$a3.AutoItSetOption("CaretCoordMode", 0);
|
28
|
+
$a3.AutoItSetOption("ColorMode", 1);
|
29
|
+
$a3.AutoItSetOption("MouseCoordMode", 0);
|
30
|
+
$a3.AutoItSetOption("PixelCoordMode", 0);
|
31
|
+
$a3.AutoItSetOption("SendKeyDelay", 15)
|
32
|
+
return $a3
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.set_option(key, value)
|
36
|
+
self.init if $a3.nil?
|
37
|
+
$a3.AutoItSetOption(key, value)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'rformspec'
|
2
|
+
|
3
|
+
module CalcSpecHelper
|
4
|
+
include RFormSpec::Driver
|
5
|
+
|
6
|
+
def run_calc
|
7
|
+
RFormSpec::Process.run("calc.exe")
|
8
|
+
@calc_win = RFormSpec::Window.new('Calculator', "", :wait_timeout => 2)
|
9
|
+
end
|
10
|
+
alias start_calc run_calc
|
11
|
+
|
12
|
+
def exit_calc
|
13
|
+
@calc_win.close
|
14
|
+
end
|
15
|
+
|
16
|
+
def click_3
|
17
|
+
@calc_win.click_button('127') #3
|
18
|
+
sleep(0.5)
|
19
|
+
end
|
20
|
+
|
21
|
+
def click_7
|
22
|
+
@calc_win.click_button('131') #7
|
23
|
+
sleep(0.5)
|
24
|
+
end
|
25
|
+
|
26
|
+
def click_add
|
27
|
+
@calc_win.click_button('92') # +
|
28
|
+
sleep(0.5)
|
29
|
+
end
|
30
|
+
alias click_plus click_add
|
31
|
+
|
32
|
+
def click_multiply
|
33
|
+
@calc_win.click_button('91') #*
|
34
|
+
sleep(0.5)
|
35
|
+
end
|
36
|
+
|
37
|
+
def click_equals
|
38
|
+
@calc_win.click_button('112') #=
|
39
|
+
sleep(0.5)
|
40
|
+
end
|
41
|
+
|
42
|
+
def result
|
43
|
+
@calc_win.get_control_text('403')
|
44
|
+
end
|
45
|
+
alias get_result result
|
46
|
+
|
47
|
+
def perform(actions)
|
48
|
+
methods_to_call = actions.collect { |act|
|
49
|
+
case act
|
50
|
+
when '+':
|
51
|
+
'plus'
|
52
|
+
when '-':
|
53
|
+
'minus'
|
54
|
+
when '*':
|
55
|
+
'multiply'
|
56
|
+
when '=':
|
57
|
+
'equals'
|
58
|
+
else
|
59
|
+
act
|
60
|
+
end
|
61
|
+
}
|
62
|
+
|
63
|
+
methods_to_call.each { |met|
|
64
|
+
self.send("click_#{met}")
|
65
|
+
}
|
66
|
+
get_result
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'calc_helper')
|
2
|
+
|
3
|
+
describe 'Simple Calculation' do
|
4
|
+
include CalcSpecHelper
|
5
|
+
|
6
|
+
before (:all) do
|
7
|
+
start_calc
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:all) do
|
11
|
+
exit_calc
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can do adding" do
|
15
|
+
click_3
|
16
|
+
click_add
|
17
|
+
click_7
|
18
|
+
click_equals
|
19
|
+
result.should == "10. "
|
20
|
+
end
|
21
|
+
|
22
|
+
it "can do muliply" do
|
23
|
+
click_3
|
24
|
+
click_multiply
|
25
|
+
click_7
|
26
|
+
click_equals
|
27
|
+
result.should == "21. "
|
28
|
+
end
|
29
|
+
|
30
|
+
it "if you think above is good, we can make it more readable" do
|
31
|
+
perform(%w(3 + 7 =)).should == "10. "
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<?xml version="1.1" encoding="US-ASCII"?>
|
2
|
+
<project>
|
3
|
+
<name>Calculator</name>
|
4
|
+
<default_browser></default_browser>
|
5
|
+
<test_framework>Watir</test_framework>
|
6
|
+
<syntax_framework>RWebSpec</syntax_framework>
|
7
|
+
<environments>
|
8
|
+
</environments>
|
9
|
+
<exclude_dirs></exclude_dirs>
|
10
|
+
<exclude_files></exclude_files>
|
11
|
+
<test_named_as>specification</test_named_as>
|
12
|
+
<spec_template></spec_template>
|
13
|
+
<page_template></page_template>
|
14
|
+
<storywise_url></storywise_url>
|
15
|
+
<jira_url></jira_url>
|
16
|
+
<jira_project></jira_project>
|
17
|
+
<jira_login></jira_login>
|
18
|
+
<jira_password></jira_password>
|
19
|
+
<heart_beat>
|
20
|
+
<spec_suite></spec_suite>
|
21
|
+
<environment></environment>
|
22
|
+
<start_time></start_time>
|
23
|
+
<repeat></repeat>
|
24
|
+
<end_repeat></end_repeat>
|
25
|
+
<emails></emails>
|
26
|
+
</heart_beat>
|
27
|
+
</project>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<?xml version="1.1" encoding="US-ASCII"?>
|
2
|
+
<workspace>
|
3
|
+
<project_name>Calculator</project_name>
|
4
|
+
<project_file>C:\work\testwise\samples\form_calculator\calculator.tpr</project_file>
|
5
|
+
<opened_files>
|
6
|
+
<entry name="$PROJECT_DIR$/calc_spec.rb"/>
|
7
|
+
</opened_files>
|
8
|
+
<recent_files>
|
9
|
+
<entry name="$PROJECT_DIR$/calc_spec.rb"/>
|
10
|
+
</recent_files>
|
11
|
+
<test_suites>
|
12
|
+
</test_suites>
|
13
|
+
</workspace>
|
data/sample/mouse.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rformspec'
|
3
|
+
|
4
|
+
RFormSpec::AutoIt.set_option("WinSearchChildren", 1)
|
5
|
+
|
6
|
+
class TextWiseWindow < RFormSpec::Window
|
7
|
+
def initialize(title = "TextWise", text = "", opts = {})
|
8
|
+
super(title, text, opts)
|
9
|
+
wait_and_focus_window(title)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
win = TextWiseWindow.new("TextWise", "", :present => true)
|
16
|
+
win.mouse_move(90, 30)
|
17
|
+
#win.mouse_click(241, 645)
|
18
|
+
win.mouse_click(220, 640)
|
19
|
+
#RFormSpec::Mouse.move_to(200, 40)
|
data/sample/notepad.rb
CHANGED
@@ -3,7 +3,7 @@ require 'rformspec'
|
|
3
3
|
include RFormSpec::Driver
|
4
4
|
|
5
5
|
RFormSpec::Process.run("C:\\WINDOWS\\NOTEPAD.EXE")
|
6
|
-
notepad_win = RFormSpec::Window.new('Untitled - Notepad')
|
6
|
+
notepad_win = RFormSpec::Window.new('Untitled - Notepad', "", :wait_timeout => 2)
|
7
7
|
RFormSpec::Keyboard.type("Hello, Missing No. 5.{ENTER}1 2 3 4 6 7 8 9 10{ENTER}")
|
8
8
|
RFormSpec::Keyboard.press("+{UP 2}")
|
9
9
|
|
data/sample/notepad1.rb
CHANGED
@@ -3,12 +3,12 @@ require 'rformspec'
|
|
3
3
|
include RFormSpec::Driver
|
4
4
|
|
5
5
|
RFormSpec::Process.run("C:\\WINDOWS\\NOTEPAD.EXE")
|
6
|
-
notepad_win = RFormSpec::Window.new('Untitled - Notepad')
|
6
|
+
notepad_win = RFormSpec::Window.new('Untitled - Notepad', "", :wait_timeout => 2)
|
7
7
|
RFormSpec::Keyboard.type("Hello from Notepad, {ENTER}1 2 3 4 5 6 7 8 9 10{ENTER}")
|
8
8
|
sleep(0.5)
|
9
9
|
RFormSpec::Keyboard.press("+{UP 2}")
|
10
10
|
sleep(0.5)
|
11
11
|
notepad_win.close
|
12
12
|
|
13
|
-
notepad_confirm_dialog = RFormSpec::Window.new('Notepad', 'No')
|
13
|
+
notepad_confirm_dialog = RFormSpec::Window.new('Notepad', 'No', :wait_timeout => 1)
|
14
14
|
notepad_confirm_dialog.click_button('&No')
|
data/sample/test_calc.rb
CHANGED
@@ -1,14 +1,23 @@
|
|
1
1
|
require 'rformspec'
|
2
2
|
|
3
3
|
class CalcTest < RFormSpec::FormTestCase
|
4
|
+
include RFormSpec::Driver
|
4
5
|
|
5
6
|
def setup
|
7
|
+
RFormSpec::AutoIt.init
|
8
|
+
|
9
|
+
if window_exists?("Calculator")
|
10
|
+
focus_window('Calculator')
|
11
|
+
RFormSpec::Window.new('Calculator')
|
12
|
+
else
|
6
13
|
RFormSpec::Process.run("calc.exe")
|
7
|
-
|
14
|
+
end
|
15
|
+
|
16
|
+
@calc_win = RFormSpec::Window.new('Calculator', "", :wait_timeout => 2)
|
8
17
|
end
|
9
18
|
|
10
19
|
def teardown
|
11
|
-
@calc_win.close
|
20
|
+
# @calc_win.close
|
12
21
|
end
|
13
22
|
|
14
23
|
def test_multiple
|
@@ -16,6 +25,7 @@ class CalcTest < RFormSpec::FormTestCase
|
|
16
25
|
@calc_win.click_button('91') #*
|
17
26
|
@calc_win.click_button('131') #7
|
18
27
|
@calc_win.click_button('112') #=
|
28
|
+
sleep 1
|
19
29
|
assert_equal "21. ", @calc_win.get_control_text('403')
|
20
30
|
|
21
31
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rformspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 3
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.3.2
|
8
|
+
- 4
|
9
|
+
version: "0.4"
|
11
10
|
platform: x86-mingw32
|
12
11
|
authors:
|
13
12
|
- Zhimin Zhan
|
@@ -15,8 +14,7 @@ autorequire: rformspec
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
17
|
+
date: 2011-10-07 00:00:00 Z
|
20
18
|
dependencies: []
|
21
19
|
|
22
20
|
description:
|
@@ -43,14 +41,15 @@ files:
|
|
43
41
|
- lib/rformspec/saveas_file_dialog.rb
|
44
42
|
- lib/rformspec/window.rb
|
45
43
|
- lib/rformspec.rb
|
46
|
-
- sample/
|
47
|
-
- sample/
|
44
|
+
- sample/form_calculator/calculator.tpr
|
45
|
+
- sample/form_calculator/calculator.tws
|
46
|
+
- sample/form_calculator/calc_helper.rb
|
47
|
+
- sample/form_calculator/calc_spec.rb
|
48
|
+
- sample/mouse.rb
|
48
49
|
- sample/notepad.rb
|
49
50
|
- sample/notepad1.rb
|
50
|
-
- sample/rspec_calc.rb
|
51
51
|
- sample/test_calc.rb
|
52
52
|
- docs/index.html
|
53
|
-
has_rdoc: true
|
54
53
|
homepage: http://github.com/zhimin/rformspec
|
55
54
|
licenses: []
|
56
55
|
|
@@ -80,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
79
|
requirements:
|
81
80
|
- none
|
82
81
|
rubyforge_project:
|
83
|
-
rubygems_version: 1.
|
82
|
+
rubygems_version: 1.7.2
|
84
83
|
signing_key:
|
85
84
|
specification_version: 3
|
86
85
|
summary: An wrap of AUTOIT3 for functional testing of Windows form applications
|
data/sample/calc.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'rformspec'
|
2
|
-
|
3
|
-
module Calc
|
4
|
-
include RFormSpec::Driver
|
5
|
-
|
6
|
-
def start_calc
|
7
|
-
RFormSpec::Process.run("calc.exe")
|
8
|
-
RFormSpec::Window.new('Calculator')
|
9
|
-
end
|
10
|
-
|
11
|
-
def find_existing_calc_win
|
12
|
-
if window_exists?("Calculator")
|
13
|
-
focus_window('Calculator')
|
14
|
-
RFormSpec::Window.new('Calculator')
|
15
|
-
else
|
16
|
-
nil
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def quit_calc
|
21
|
-
focus_window('Calculator')
|
22
|
-
RFormSpec::Keyboard.press("!{F4}")
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
data/sample/calc_spec.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/rspec_calc'
|
2
|
-
|
3
|
-
context "Calculator" do
|
4
|
-
|
5
|
-
setup do
|
6
|
-
end
|
7
|
-
|
8
|
-
specify "Multiple works" do
|
9
|
-
@calc_win.click_button('127') #3
|
10
|
-
@calc_win.click_button('91') #*
|
11
|
-
@calc_win.click_button('131') #7
|
12
|
-
@calc_win.click_button('112') #=
|
13
|
-
@calc_win.get_control_text('403').should == '21. '
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
data/sample/rspec_calc.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/calc'
|
2
|
-
|
3
|
-
class RSpecCalc
|
4
|
-
include Calc
|
5
|
-
|
6
|
-
def setup
|
7
|
-
init # initialize
|
8
|
-
@calc_win = find_existing_calc_win
|
9
|
-
if @calc_win.nil?
|
10
|
-
@calc_win = start_calc
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
module Spec
|
16
|
-
module Runner
|
17
|
-
class Context
|
18
|
-
def before_context_eval
|
19
|
-
#inherit RSpecCalc # inherit not supported after 0.8
|
20
|
-
inherit_context_eval_module_from RSpecCalc
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|