rautomation 0.17.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -72,27 +72,27 @@ module RAutomation
72
72
  @@wait_timeout = 60
73
73
 
74
74
  # Change the timeout to wait before {WaitHelper::TimeoutError} is raised.
75
- # @param [Fixnum] timeout in seconds.
75
+ # @param [Integer] timeout in seconds.
76
76
  def wait_timeout=(timeout)
77
77
  @@wait_timeout = timeout
78
78
  end
79
79
 
80
80
  # Retrieve current timeout in seconds to wait before {WaitHelper::TimeoutError} is raised.
81
- # @return [Fixnum] timeout in seconds
81
+ # @return [Integer] timeout in seconds
82
82
  def wait_timeout
83
83
  @@wait_timeout
84
84
  end
85
85
 
86
86
  end
87
87
 
88
- # @return [Fixnum] handle of the window which is used internally for other methods.
88
+ # @return [Integer] handle of the window which is used internally for other methods.
89
89
  # @raise [UnknownWindowException] if the window doesn't exist.
90
90
  def hwnd
91
91
  wait_until_present
92
92
  @window.hwnd
93
93
  end
94
94
 
95
- # @return [Fixnum] process identifier (PID) of the window.
95
+ # @return [Integer] process identifier (PID) of the window.
96
96
  # @raise [UnknownWindowException] if the window doesn't exist.
97
97
  def pid
98
98
  wait_until_present
@@ -1,34 +1,36 @@
1
- # -*- encoding: utf-8 -*-
2
- Gem::Specification.new do |s|
3
- s.name = %q{rautomation}
4
- s.version = File.read("VERSION").strip
5
- s.authors = [%q{Jarmo Pertman}]
6
- s.email = %q{jarmo.p@gmail.com}
7
- s.description = %q{RAutomation is a small and easy to use library for helping out to automate windows and their controls
8
- for automated testing.
9
-
10
- RAutomation provides:
11
- * Easy to use and user-friendly API (inspired by Watir http://www.watir.com)
12
- * Cross-platform compatibility
13
- * Easy extensibility - with small scripting effort it's possible to add support for not yet
14
- supported platforms or technologies}
15
- s.homepage = %q{http://github.com/jarmo/RAutomation}
16
- s.summary = %q{Automate windows and their controls through user-friendly API with Ruby}
17
- s.license = "MIT"
18
-
19
- ext_binaries = [
20
- "ext/IAccessibleDLL/Release/IAccessibleDLL.dll",
21
- "ext/UiaDll/Release/UiaDll.dll",
22
- "ext/UiaDll/Release/RAutomation.UIA.dll",
23
- "ext/WindowsForms/Release/WindowsForms.exe"
24
- ]
25
- s.files = `git ls-files`.split("\n") + ext_binaries
26
- s.test_files = `git ls-files -- spec/*`.split("\n")
27
- s.require_paths = ["lib"]
28
-
29
- s.add_dependency("ffi", "~>1.9.0")
30
- s.add_development_dependency("rspec", "~> 2.14")
31
- s.add_development_dependency("rake")
32
- s.add_development_dependency("yard")
33
- end
34
-
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |s|
3
+ s.name = %q{rautomation}
4
+ s.version = File.read("VERSION").strip
5
+ s.authors = [%q{Jarmo Pertman}]
6
+ s.email = %q{jarmo.p@gmail.com}
7
+ s.description = %q{RAutomation is a small and easy to use library for helping out to automate windows and their controls
8
+ for automated testing.
9
+
10
+ RAutomation provides:
11
+ * Easy to use and user-friendly API (inspired by Watir http://www.watir.com)
12
+ * Cross-platform compatibility
13
+ * Easy extensibility - with small scripting effort it's possible to add support for not yet
14
+ supported platforms or technologies}
15
+ s.homepage = %q{http://github.com/jarmo/RAutomation}
16
+ s.summary = %q{Automate windows and their controls through user-friendly API with Ruby}
17
+ s.license = "MIT"
18
+
19
+ ext_binaries = [
20
+ "ext/IAccessibleDLL/Release/IAccessibleDLL.dll",
21
+ "ext/UiaDll/Release/UiaDll.dll",
22
+ "ext/UiaDll/Release/RAutomation.UIA.dll",
23
+ "ext/WindowsForms/Release/WindowsForms.exe"
24
+ ]
25
+ s.files = `git ls-files`.split("\n") + ext_binaries
26
+ s.test_files = `git ls-files -- spec/*`.split("\n")
27
+ s.require_paths = ["lib"]
28
+
29
+ s.add_dependency("ffi", "~> 1.11.0")
30
+ s.add_development_dependency("rspec", "~> 2.14")
31
+ s.add_development_dependency("rake")
32
+ s.add_development_dependency("yard")
33
+ s.add_development_dependency("redcarpet")
34
+ s.add_development_dependency("github-markup")
35
+ end
36
+
@@ -1,69 +1,68 @@
1
- require 'spec_helper'
2
-
3
- describe RAutomation::Button do
4
- it "#button" do
5
- RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title]).
6
- button(:value => "Close").should exist
7
-
8
- RAutomation::Window.wait_timeout = 0.1
9
- expect {RAutomation::Window.new(:title => "non-existing-window").button(:value => "Something")}.
10
- to raise_exception(RAutomation::UnknownWindowException)
11
- end
12
-
13
- it "#value" do
14
- RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title]).
15
- button(:value => "Close").value.should == "Close"
16
-
17
- RAutomation::Window.wait_timeout = 0.1
18
- expect {RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title]).button(:value => "non-existent-button").value}.
19
- to raise_exception(RAutomation::UnknownButtonException)
20
- end
21
-
22
- it "#exists?" do
23
- window = RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title])
24
- window.button(:value => "Close").should exist
25
- window.button(:value => "non-existent-button").should_not exist
26
- end
27
-
28
- it "clicking non-existing button raises exception" do
29
- window = RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title])
30
- RAutomation::Window.wait_timeout = 0.1
31
- expect {window.button(:value => "non-existent-button").click}.
32
- to raise_exception(RAutomation::UnknownButtonException)
33
- end
34
-
35
- #This spec will randomly fail. Why?
36
- it "#click" do
37
- window = RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title])
38
-
39
- button = window.button(:value => "Close")
40
- button.should exist
41
- button.click
42
-
43
- button.should_not exist
44
- window.should_not exist
45
- end
46
-
47
- it "#click with a block for defining successful click returning false raises a TimeoutError" do
48
- window = RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title])
49
- RAutomation::Window.wait_timeout = 5
50
- button = window.button(:value => "Close")
51
- expect {button.click {false}}.
52
- to raise_exception(RAutomation::WaitHelper::TimeoutError)
53
-
54
- button.should_not exist
55
- window.should_not exist
56
- end
57
-
58
- it "#click with a block for defining successful click returning true" do
59
- RAutomation::Window.wait_timeout = 10
60
- window = RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title])
61
- button = window.button(:value => "Close")
62
- button.should exist
63
- button.click {|button| !button.exists? && !window.exists?}
64
-
65
- button.should_not exist
66
- window.should_not exist
67
- end
68
-
69
- end
1
+ require 'spec_helper'
2
+
3
+ describe RAutomation::Button do
4
+ it "#button" do
5
+ RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title]).
6
+ button(:value => "Close").should exist
7
+
8
+ RAutomation::Window.wait_timeout = 0.1
9
+ expect {RAutomation::Window.new(:title => "non-existing-window").button(:value => "Something")}.
10
+ to raise_exception(RAutomation::UnknownWindowException)
11
+ end
12
+
13
+ it "#value" do
14
+ RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title]).
15
+ button(:value => "Close").value.should == "Close"
16
+
17
+ RAutomation::Window.wait_timeout = 0.1
18
+ expect {RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title]).button(:value => "non-existent-button").value}.
19
+ to raise_exception(RAutomation::UnknownButtonException)
20
+ end
21
+
22
+ it "#exists?" do
23
+ window = RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title])
24
+ window.button(:value => "Close").should exist
25
+ window.button(:value => "non-existent-button").should_not exist
26
+ end
27
+
28
+ it "clicking non-existing button raises exception" do
29
+ window = RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title])
30
+ RAutomation::Window.wait_timeout = 0.1
31
+ expect {window.button(:value => "non-existent-button").click}.
32
+ to raise_exception(RAutomation::UnknownButtonException)
33
+ end
34
+
35
+ it "#click" do
36
+ window = RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title])
37
+
38
+ button = window.button(:value => "Close")
39
+ button.should exist
40
+ button.click
41
+
42
+ button.should_not exist
43
+ RAutomation::WaitHelper.wait_until { !window.exists? }
44
+ end
45
+
46
+ it "#click with a block for defining successful click returning false raises a TimeoutError" do
47
+ window = RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title])
48
+ RAutomation::Window.wait_timeout = 5
49
+ button = window.button(:value => "Close")
50
+ expect {button.click {false}}.
51
+ to raise_exception(RAutomation::WaitHelper::TimeoutError)
52
+
53
+ button.should_not exist
54
+ window.should_not exist
55
+ end
56
+
57
+ it "#click with a block for defining successful click returning true" do
58
+ RAutomation::Window.wait_timeout = 10
59
+ window = RAutomation::Window.new(:title => SpecHelper::DATA[:window1_title])
60
+ button = window.button(:value => "Close")
61
+ button.should exist
62
+ button.click {|button| !button.exists? && !window.exists?}
63
+
64
+ button.should_not exist
65
+ window.should_not exist
66
+ end
67
+
68
+ end
@@ -1,122 +1,122 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- require 'rautomation'
3
- require 'rspec'
4
- require 'timeout'
5
-
6
- module SpecHelper
7
- # @private
8
- def adapter
9
- ENV["RAUTOMATION_ADAPTER"] && ENV["RAUTOMATION_ADAPTER"].to_sym || RAutomation::Adapter::Helper.default_adapter
10
- end
11
-
12
- def navigate_to_simple_elements
13
- main_window = RAutomation::Window.new(:title => "MainFormWindow")
14
- main_window.button(:value => "Simple Elements").click { RAutomation::Window.new(:title => "SimpleElementsForm").present? }
15
- end
16
-
17
- module_function :adapter, :navigate_to_simple_elements
18
-
19
- # Since adapters are different then the windows to be tested
20
- # might be different also.
21
- #
22
- # This constant allows to create input data for specs which could differ between the adapters.
23
- #
24
- # There has to be 2 windows:
25
- # 1) Some random window, which is maximizable, minimizable, close'able and etc.
26
- # 2) Browser window, which opens up a test.html where JavaScript prompt with a Button and a TextField objects will be shown.
27
- DATA = {
28
- # This adapter needs Windows OS with Internet Explorer installed into 'c:\program files\internet explorer'.
29
- :autoit => {
30
- # Path to some binary, which opens up a window, what can be
31
- # minimized, maximized, activated, closed and etc.
32
- :window1 => "ext\\WindowsForms\\Release\\WindowsForms.exe",
33
- :window2 => "calc",
34
- :window2_title => /calc/i,
35
- # Window 1 title, has to be a Regexp.
36
- :window1_title => /FormWindow/i,
37
- :window1_full_title => 'MainFormWindow',
38
- # Window 1 should have this text on it.
39
- :window1_text => "This is a sample text",
40
- # When sending ENTER on Window 2, then the window OK button should be pressed and Window 2 should be closed.
41
- # "A" key
42
- :window1_send_keys => "A",
43
- :proc_after_send_keys => lambda do
44
- about_box = RAutomation::Window.new(:title => /About/i)
45
- RAutomation::WaitHelper.wait_until {about_box.present?}
46
- end,
47
- # Window 1 should have a button with the following text.
48
- :window1_button_text => "&About",
49
- # Window 1 should have a text field with the specified class name.
50
- :window1_text_field_class => "Edit",
51
- # Adapter internal method invocation for getting title of window2
52
- :title_proc => lambda {|win| win.WinGetTitle("[TITLE:MainFormWindow]")}
53
- },
54
- :win_32 => {
55
- # Path to some binary, which opens up a window, what can be
56
- # minimized, maximized, activated, closed and etc.
57
- :window1 => "ext\\WindowsForms\\Release\\WindowsForms.exe",
58
- :window2 => "calc",
59
- :window2_title => /calc/i,
60
- # Window 1 title, has to be a Regexp.
61
- :window1_title => /FormWindow/i,
62
- :window1_full_title => 'MainFormWindow',
63
- # Window 1 should have this text on it.
64
- :window1_text => "This is a sample text",
65
- # When sending ENTER on Window 2, then the window OK button should be pressed and Window 2 should be closed.
66
- # "A" key
67
- :window1_send_keys => "A",
68
- :proc_after_send_keys => lambda do
69
- about_box = RAutomation::Window.new(:title => /About/i)
70
- RAutomation::WaitHelper.wait_until {about_box.present?}
71
- end,
72
- # Window 1 should have a button with the following text.
73
- :window1_button_text => "&About",
74
- # Window 1 should have a text field with the specified class name.
75
- :window1_text_field_class => "Edit",
76
- # Adapter internal method invocation for getting title of window2
77
- :title_proc => lambda {|win| win.window_title(win.hwnd)}
78
- },
79
- #Just copying :win_ffi data for now
80
- :ms_uia => {
81
- # Path to some binary, which opens up a window, what can be
82
- # minimized, maximized, activated, closed and etc.
83
- :window1 => "ext\\WindowsForms\\Release\\WindowsForms.exe",
84
- :window2 => "calc",
85
- :window2_title => /calc/i,
86
- # Window 1 title, has to be a Regexp.
87
- :window1_title => /FormWindow/i,
88
- :window1_full_title => 'MainFormWindow',
89
- # Window 1 should have this text on it.
90
- :window1_text => "This is a sample text",
91
- # When sending ENTER on Window 2, then the window OK button should be pressed and Window 2 should be closed.
92
- # "A" key
93
- :window1_send_keys => "A",
94
- :proc_after_send_keys => lambda do
95
- about_box = RAutomation::Window.new(:title => /About/i)
96
- RAutomation::WaitHelper.wait_until {about_box.present?}
97
- end,
98
- # Window 1 should have a button with the following text.
99
- :window1_button_text => "&About",
100
- # Window 1 should have a text field with the specified class name.
101
- :window1_text_field_class => "Edit",
102
- # Adapter internal method invocation for getting title of window2
103
- :title_proc => lambda {|win| win.window_title(win.hwnd)}
104
- }
105
- }[adapter]
106
- end
107
-
108
-
109
- RSpec.configure do |config|
110
- config.before(:each) do
111
- RAutomation::Window.wait_timeout = 15
112
-
113
- unless example.metadata[:pure_unit]
114
- @pid1 = IO.popen(SpecHelper::DATA[:window1]).pid
115
- RAutomation::WaitHelper.wait_until { RAutomation::Window.new(:pid => @pid1).present? }
116
- end
117
- end
118
-
119
- config.after(:each) do
120
- Process.kill(9, @pid1) rescue nil
121
- end
122
- end
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'rautomation'
3
+ require 'rspec'
4
+ require 'timeout'
5
+
6
+ module SpecHelper
7
+ # @private
8
+ def adapter
9
+ ENV["RAUTOMATION_ADAPTER"] && ENV["RAUTOMATION_ADAPTER"].to_sym || RAutomation::Adapter::Helper.default_adapter
10
+ end
11
+
12
+ def navigate_to_simple_elements
13
+ main_window = RAutomation::Window.new(:title => "MainFormWindow")
14
+ main_window.button(:value => "Simple Elements").click { RAutomation::Window.new(:title => "SimpleElementsForm").present? }
15
+ end
16
+
17
+ module_function :adapter, :navigate_to_simple_elements
18
+
19
+ # Since adapters are different then the windows to be tested
20
+ # might be different also.
21
+ #
22
+ # This constant allows to create input data for specs which could differ between the adapters.
23
+ #
24
+ # There has to be 2 windows:
25
+ # 1) Some random window, which is maximizable, minimizable, close'able and etc.
26
+ # 2) Browser window, which opens up a test.html where JavaScript prompt with a Button and a TextField objects will be shown.
27
+ DATA = {
28
+ # This adapter needs Windows OS with Internet Explorer installed into 'c:\program files\internet explorer'.
29
+ :autoit => {
30
+ # Path to some binary, which opens up a window, what can be
31
+ # minimized, maximized, activated, closed and etc.
32
+ :window1 => "ext\\WindowsForms\\Release\\WindowsForms.exe",
33
+ :window2 => "notepad",
34
+ :window2_title => /notepad/i,
35
+ # Window 1 title, has to be a Regexp.
36
+ :window1_title => /FormWindow/i,
37
+ :window1_full_title => 'MainFormWindow',
38
+ # Window 1 should have this text on it.
39
+ :window1_text => "This is a sample text",
40
+ # When sending ENTER on Window 2, then the window OK button should be pressed and Window 2 should be closed.
41
+ # "A" key
42
+ :window1_send_keys => "A",
43
+ :proc_after_send_keys => lambda do
44
+ about_box = RAutomation::Window.new(:title => /About/i)
45
+ RAutomation::WaitHelper.wait_until {about_box.present?}
46
+ end,
47
+ # Window 1 should have a button with the following text.
48
+ :window1_button_text => "&About",
49
+ # Window 1 should have a text field with the specified class name.
50
+ :window1_text_field_class => "Edit",
51
+ # Adapter internal method invocation for getting title of window2
52
+ :title_proc => lambda {|win| win.WinGetTitle("[TITLE:MainFormWindow]")}
53
+ },
54
+ :win_32 => {
55
+ # Path to some binary, which opens up a window, what can be
56
+ # minimized, maximized, activated, closed and etc.
57
+ :window1 => "ext\\WindowsForms\\Release\\WindowsForms.exe",
58
+ :window2 => "notepad",
59
+ :window2_title => /notepad/i,
60
+ # Window 1 title, has to be a Regexp.
61
+ :window1_title => /FormWindow/i,
62
+ :window1_full_title => 'MainFormWindow',
63
+ # Window 1 should have this text on it.
64
+ :window1_text => "This is a sample text",
65
+ # When sending ENTER on Window 2, then the window OK button should be pressed and Window 2 should be closed.
66
+ # "A" key
67
+ :window1_send_keys => "A",
68
+ :proc_after_send_keys => lambda do
69
+ about_box = RAutomation::Window.new(:title => /About/i)
70
+ RAutomation::WaitHelper.wait_until {about_box.present?}
71
+ end,
72
+ # Window 1 should have a button with the following text.
73
+ :window1_button_text => "&About",
74
+ # Window 1 should have a text field with the specified class name.
75
+ :window1_text_field_class => "Edit",
76
+ # Adapter internal method invocation for getting title of window2
77
+ :title_proc => lambda {|win| win.window_title(win.hwnd)}
78
+ },
79
+ #Just copying :win_ffi data for now
80
+ :ms_uia => {
81
+ # Path to some binary, which opens up a window, what can be
82
+ # minimized, maximized, activated, closed and etc.
83
+ :window1 => "ext\\WindowsForms\\Release\\WindowsForms.exe",
84
+ :window2 => "notepad",
85
+ :window2_title => /notepad/i,
86
+ # Window 1 title, has to be a Regexp.
87
+ :window1_title => /FormWindow/i,
88
+ :window1_full_title => 'MainFormWindow',
89
+ # Window 1 should have this text on it.
90
+ :window1_text => "This is a sample text",
91
+ # When sending ENTER on Window 2, then the window OK button should be pressed and Window 2 should be closed.
92
+ # "A" key
93
+ :window1_send_keys => "A",
94
+ :proc_after_send_keys => lambda do
95
+ about_box = RAutomation::Window.new(:title => /About/i)
96
+ RAutomation::WaitHelper.wait_until {about_box.present?}
97
+ end,
98
+ # Window 1 should have a button with the following text.
99
+ :window1_button_text => "&About",
100
+ # Window 1 should have a text field with the specified class name.
101
+ :window1_text_field_class => "Edit",
102
+ # Adapter internal method invocation for getting title of window2
103
+ :title_proc => lambda {|win| win.window_title(win.hwnd)}
104
+ }
105
+ }[adapter]
106
+ end
107
+
108
+
109
+ RSpec.configure do |config|
110
+ config.before(:each) do
111
+ RAutomation::Window.wait_timeout = 15
112
+
113
+ unless example.metadata[:pure_unit]
114
+ @pid1 = IO.popen(SpecHelper::DATA[:window1]).pid
115
+ RAutomation::WaitHelper.wait_until { RAutomation::Window.new(:pid => @pid1).present? }
116
+ end
117
+ end
118
+
119
+ config.after(:each) do
120
+ Process.kill(9, @pid1) rescue nil
121
+ end
122
+ end