win32-autogui 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,63 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ include Autogui::Input
4
+
5
+ describe Autogui::EnumerateDesktopWindows do
6
+
7
+ describe "finding dialogs" do
8
+ before(:all) do
9
+ @calculator = Calculator.new
10
+ end
11
+ before(:each) do
12
+ @calculator.should be_running
13
+ @calculator.set_focus
14
+ end
15
+ after(:all) do
16
+ @calculator.close(:wait_for_close => true) if @calculator.running?
17
+ @calculator.should_not be_running
18
+ end
19
+
20
+ describe "with the default timeout of 0" do
21
+ it "should find a valid dialog" do
22
+ keystroke(VK_MENU, VK_H, VK_A)
23
+ dialog_about = Autogui::EnumerateDesktopWindows.new.find do |w|
24
+ w.title.match(/About Calculator/) && (w.pid == @calculator.pid)
25
+ end
26
+ dialog_about.should_not be_nil
27
+ dialog_about.close
28
+ end
29
+ it "should not find an invalid dialog" do
30
+ dialog_bogus = Autogui::EnumerateDesktopWindows.new.find do |w|
31
+ w.title.match(/Bogus Window that does not exist/) && (w.pid == @calculator.pid)
32
+ end
33
+ dialog_bogus.should be_nil
34
+ end
35
+ end
36
+
37
+ describe "with the timeout of 3 seconds" do
38
+ it "should find a valid dialog in less than 3 seconds" do
39
+ keystroke(VK_MENU, VK_H, VK_A)
40
+ seconds = 3
41
+ dialog_about = nil
42
+ lambda {timeout(seconds) do
43
+ dialog_about = Autogui::EnumerateDesktopWindows.new(:timeout => seconds).find do |w|
44
+ w.title.match(/About Calculator/) && (w.pid == @calculator.pid)
45
+ end
46
+ end}.should_not raise_error
47
+ dialog_about.should_not be_nil
48
+ dialog_about.close
49
+ end
50
+ it "should look for an invalid dialog for 3 seconds" do
51
+ seconds = 3
52
+ dialog_bogus = nil
53
+ lambda {timeout(seconds) do
54
+ dialog_bogus = Autogui::EnumerateDesktopWindows.new(:timeout => seconds).find do |w|
55
+ w.title.match(/Bogus Window that does not exist/) && (w.pid == @calculator.pid)
56
+ end
57
+ end}.should raise_error
58
+ dialog_bogus.should be_nil
59
+ end
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Autogui do
4
+
5
+ before(:each) do
6
+ @filename = 'input.txt'
7
+ create_file(@filename, "the quick brown fox")
8
+ end
9
+
10
+ describe 'Aruba::API.current_dir' do
11
+
12
+ it "should return the current dir as 'tmp/aruba'" do
13
+ current_dir.should match(/^tmp\/aruba$/)
14
+ end
15
+ end
16
+
17
+ describe "aruba_helper fullpath('input.txt')" do
18
+
19
+ it "should return a valid expanded path to 'input.txt'" do
20
+ path = fullpath('input.txt')
21
+ path.should match(/tmp..*aruba/)
22
+ File.exists?(path).should == true
23
+ end
24
+ end
25
+
26
+ describe "aruba_helper get_file_contents('input.txt')" do
27
+
28
+ it "should return the contents of 'input.txt' as a String" do
29
+ get_file_contents('input.txt').should == 'the quick brown fox'
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,68 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Autogui do
4
+
5
+ def load_gemspec
6
+ filename = File.expand_path('../../../win32-autogui.gemspec', __FILE__)
7
+ eval(File.read(filename), nil, filename)
8
+ end
9
+
10
+ describe 'gemspec' do
11
+
12
+ it "should return the gem VERSION" do
13
+ @gemspec = load_gemspec
14
+ Autogui::version.should_not be_nil
15
+ @gemspec.version.to_s.should == Autogui::version
16
+ end
17
+
18
+ describe 'files' do
19
+
20
+ it "should return 'files' array" do
21
+ @gemspec = load_gemspec
22
+ @gemspec.files.is_a?(Array).should == true
23
+ @gemspec.files.include?('VERSION').should == true
24
+ end
25
+ it "should return 'executables' array" do
26
+ @gemspec = load_gemspec
27
+ @gemspec.executables.is_a?(Array).should == true
28
+ end
29
+
30
+ describe 'without a git repo' do
31
+ before(:each) do
32
+ File.stub!('directory?').and_return false
33
+ @gemspec = load_gemspec
34
+ end
35
+
36
+ it "should return 'files' from cache" do
37
+ File.directory?(File.expand_path('../../../.git', __FILE__)).should == false
38
+ @gemspec.files.is_a?(Array).should == true
39
+ @gemspec.files.include?('VERSION').should == true
40
+ end
41
+ it "should return 'executables' from cache" do
42
+ File.directory?(File.expand_path('../../../.git', __FILE__)).should == false
43
+ @gemspec.executables.is_a?(Array).should == true
44
+ end
45
+ end
46
+
47
+ describe 'without git binary' do
48
+
49
+ before(:each) do
50
+ stub!(:system).and_return false
51
+ @gemspec = load_gemspec
52
+ end
53
+
54
+ it "should return 'files' from cache" do
55
+ system('git --version').should == false
56
+ @gemspec.files.is_a?(Array).should == true
57
+ @gemspec.files.include?('VERSION').should == true
58
+ end
59
+ it "should return 'executables' from cache" do
60
+ system('git --version').should == false
61
+ @gemspec.executables.is_a?(Array).should == true
62
+ end
63
+
64
+ end
65
+ end
66
+
67
+ end
68
+ end
data/spec/spec_helper.rb CHANGED
@@ -12,15 +12,22 @@
12
12
  # applications
13
13
  require File.expand_path(File.dirname(__FILE__) + '/applications/calculator')
14
14
 
15
- # aruba helper, returns full path to files in the aruba tmp folder
15
+ # aruba helpers
16
+ #
17
+ # @return full path to files in the aruba tmp folder
16
18
  def fullpath(filename)
17
19
  path = File.expand_path(File.join(current_dir, filename))
18
- path = `cygpath -w #{path}`.chomp if path.match(/^\/cygdrive/) # cygwin?
20
+ if path.match(/^\/cygdrive/)
21
+ # match /cygdrive/c/path/to and return c:\\path\\to
22
+ path = `cygpath -w #{path}`.chomp
23
+ elsif path.match(/.\:/)
24
+ # match c:/path/to and return c:\\path\\to
25
+ path = path.gsub(/\//, '\\')
26
+ end
19
27
  path
20
28
  end
21
-
22
- # return the contents of "filename" in the aruba tmp folder
23
- def get_file_content(filename)
29
+ # @return the contents of "filename" in the aruba tmp folder
30
+ def get_file_contents(filename)
24
31
  in_current_dir do
25
32
  IO.read(filename)
26
33
  end
data/spec/watchr.rb CHANGED
@@ -7,8 +7,19 @@
7
7
  # $ watchr spec/watchr.rb
8
8
 
9
9
  require 'term/ansicolor'
10
+ require 'rbconfig'
10
11
 
11
- $c = Term::ANSIColor
12
+ WINDOWS = Config::CONFIG['host_os'] =~ /mswin|mingw/i unless defined?(WINDOWS)
13
+ require 'win32/process' if WINDOWS
14
+
15
+ if WINDOWS
16
+ begin
17
+ require 'Win32/Console/ANSI'
18
+ $c = Term::ANSIColor
19
+ rescue LoadError
20
+ STDERR.puts 'WARNING: You must "gem install win32console" (1.2.0 or higher) to get coloured output on MRI/Windows'
21
+ end
22
+ end
12
23
 
13
24
  def getch
14
25
  state = `stty -g`
@@ -34,15 +45,21 @@ def all_spec_files
34
45
  def run(cmd)
35
46
 
36
47
  pid = fork do
48
+
37
49
  puts "\n"
38
- print $c.cyan, cmd, $c.clear, "\n"
50
+ if $c
51
+ print $c.cyan, cmd, $c.clear, "\n"
52
+ else
53
+ puts cmd
54
+ end
55
+
39
56
  exec(cmd)
40
57
  end
41
58
  Signal.trap('INT') do
42
59
  puts "sending KILL to pid: #{pid}"
43
60
  Process.kill("KILL", pid)
44
61
  end
45
- Process.waitpid(pid)
62
+ Process.waitpid(pid) if (pid > 0)
46
63
 
47
64
  prompt
48
65
  end
@@ -95,7 +112,10 @@ def run_last_spec
95
112
  end
96
113
 
97
114
  def prompt
98
- puts "Ctrl-\\ for menu, Ctrl-C to quit"
115
+ menu = "Ctrl-C to quit"
116
+ menu = menu + ", Ctrl-\\ for menu" if Signal.list.include?('QUIT')
117
+
118
+ puts menu
99
119
  end
100
120
 
101
121
  # init
@@ -120,25 +140,26 @@ def prompt
120
140
  watch( '^spec/applications/(.*)' ) { run_default_spec }
121
141
 
122
142
  # --------------------------------------------------
123
- # Signal Handling
143
+ # Signal Handling (May not be supported on Windows)
124
144
  # --------------------------------------------------
145
+ if Signal.list.include?('QUIT')
146
+ # Ctrl-\
147
+ Signal.trap('QUIT') do
148
+
149
+ puts "\n\nMENU: a = all , f = features s = specs, l = last feature (#{$last_feature ? $last_feature : 'none'}), q = quit\n\n"
150
+ c = getch
151
+ puts c.chr
152
+ if c.chr == "a"
153
+ run_all
154
+ elsif c.chr == "f"
155
+ run_default_cucumber
156
+ elsif c.chr == "s"
157
+ run_all_specs
158
+ elsif c.chr == "q"
159
+ abort("exiting\n")
160
+ elsif c.chr == "l"
161
+ run_last_feature
162
+ end
125
163
 
126
- # Ctrl-\
127
- Signal.trap('QUIT') do
128
-
129
- puts "\n\nMENU: a = all , f = features s = specs, l = last feature (#{$last_feature ? $last_feature : 'none'}), q = quit\n\n"
130
- c = getch
131
- puts c.chr
132
- if c.chr == "a"
133
- run_all
134
- elsif c.chr == "f"
135
- run_default_cucumber
136
- elsif c.chr == "s"
137
- run_all_specs
138
- elsif c.chr == "q"
139
- abort("exiting\n")
140
- elsif c.chr == "l"
141
- run_last_feature
142
164
  end
143
-
144
165
  end
@@ -2,9 +2,32 @@
2
2
  #
3
3
  #
4
4
 
5
+ require 'rbconfig'
6
+ WINDOWS = Config::CONFIG['host_os'] =~ /mswin|mingw/i unless defined?(WINDOWS)
7
+
5
8
  Gem::Specification.new do |s|
9
+ # wrap 'git' so we can get gem files even on systems without 'git'
10
+ #
11
+ # @see spec/gemspec_spec.rb
12
+ #
13
+ @gemfiles ||= begin
14
+ filename = File.join(File.dirname(__FILE__), '.gemfiles')
15
+ # backticks blows up on Windows w/o valid binary, use system instead
16
+ if File.directory?('.git') && system('git ls-files bogus-filename')
17
+ files = `git ls-files`
18
+ cached_files = File.exists?(filename) ? File.open(filename, "r") {|f| f.read} : nil
19
+ # maintain EOL
20
+ files.gsub!(/\n/, "\r\n") if cached_files.match("\r\n")
21
+ File.open(filename, 'wb') {|f| f.write(files)} if cached_files != files
22
+ else
23
+ files = File.open(filename, "r") {|f| f.read}
24
+ end
25
+ raise "unable to process gemfiles" unless files
26
+ files.gsub(/\r\n/, "\n")
27
+ end
28
+
6
29
  s.name = "win32-autogui"
7
- s.version = File.open(File.join(File.dirname(__FILE__), *%w[VERSION]), "r") { |f| f.read }
30
+ s.version = File.open(File.join(File.dirname(__FILE__), 'VERSION'), "r") { |f| f.read }
8
31
  s.platform = Gem::Platform::RUBY
9
32
  s.authors = ["Robert Wahler"]
10
33
  s.email = ["robert@gearheadforhire.com"]
@@ -16,22 +39,29 @@ Gem::Specification.new do |s|
16
39
  s.rubyforge_project = "win32-autogui"
17
40
 
18
41
  s.add_dependency "windows-api", ">= 0.4.0"
19
- s.add_dependency "windows-pr", ">= 1.0.9"
20
- s.add_dependency "win32-process", ">= 0.6.2"
42
+ s.add_dependency "windows-pr", ">= 1.1.2"
43
+ s.add_dependency "win32-process", ">= 0.6.4"
21
44
  s.add_dependency "win32-clipboard", ">= 0.5.2"
22
45
  s.add_dependency "log4r", ">= 1.1.9"
23
46
 
24
- s.add_development_dependency "bundler", ">= 1.0.3"
47
+ s.add_development_dependency "bundler", ">= 1.0.7"
25
48
  s.add_development_dependency "rspec", "= 1.3.1"
26
- s.add_development_dependency "cucumber", ">= 0.9.2"
27
- s.add_development_dependency "aruba", ">= 0.2.3"
49
+ s.add_development_dependency "cucumber", ">= 0.9.4"
50
+ s.add_development_dependency "aruba", "= 0.2.2"
28
51
  s.add_development_dependency "rake", ">= 0.8.7"
29
- s.add_development_dependency "yard", ">= 0.6.1"
30
- s.add_development_dependency "rdiscount", ">= 1.6.5"
52
+ s.add_development_dependency "yard", ">= 0.6.2"
53
+
54
+ # Specify a markdown gem for rake doc:generate
55
+ #
56
+ # Without the development dependency, running yard rake
57
+ # tasks will fail. Kramdown chosen to provide a pure Ruby solution.
58
+ s.add_development_dependency "kramdown", ">= 0.12.0"
59
+
60
+ s.add_development_dependency "win32console", ">= 1.2.0" if WINDOWS
61
+
62
+ s.files = @gemfiles.split("\n")
63
+ s.executables = @gemfiles.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
31
64
 
32
- s.files = `git ls-files`.split("\n")
33
- s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
34
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
35
65
  s.require_path = 'lib'
36
66
 
37
67
  s.has_rdoc = 'yard'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-autogui
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Robert Wahler
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-08 00:00:00 -05:00
18
+ date: 2010-11-22 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -40,12 +40,12 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- hash: 5
43
+ hash: 23
44
44
  segments:
45
45
  - 1
46
- - 0
47
- - 9
48
- version: 1.0.9
46
+ - 1
47
+ - 2
48
+ version: 1.1.2
49
49
  requirement: *id002
50
50
  type: :runtime
51
51
  name: windows-pr
@@ -56,12 +56,12 @@ dependencies:
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- hash: 3
59
+ hash: 15
60
60
  segments:
61
61
  - 0
62
62
  - 6
63
- - 2
64
- version: 0.6.2
63
+ - 4
64
+ version: 0.6.4
65
65
  requirement: *id003
66
66
  type: :runtime
67
67
  name: win32-process
@@ -104,12 +104,12 @@ dependencies:
104
104
  requirements:
105
105
  - - ">="
106
106
  - !ruby/object:Gem::Version
107
- hash: 17
107
+ hash: 25
108
108
  segments:
109
109
  - 1
110
110
  - 0
111
- - 3
112
- version: 1.0.3
111
+ - 7
112
+ version: 1.0.7
113
113
  requirement: *id006
114
114
  type: :development
115
115
  name: bundler
@@ -136,12 +136,12 @@ dependencies:
136
136
  requirements:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
- hash: 63
139
+ hash: 51
140
140
  segments:
141
141
  - 0
142
142
  - 9
143
- - 2
144
- version: 0.9.2
143
+ - 4
144
+ version: 0.9.4
145
145
  requirement: *id008
146
146
  type: :development
147
147
  name: cucumber
@@ -150,14 +150,14 @@ dependencies:
150
150
  version_requirements: &id009 !ruby/object:Gem::Requirement
151
151
  none: false
152
152
  requirements:
153
- - - ">="
153
+ - - "="
154
154
  - !ruby/object:Gem::Version
155
- hash: 17
155
+ hash: 19
156
156
  segments:
157
157
  - 0
158
158
  - 2
159
- - 3
160
- version: 0.2.3
159
+ - 2
160
+ version: 0.2.2
161
161
  requirement: *id009
162
162
  type: :development
163
163
  name: aruba
@@ -184,12 +184,12 @@ dependencies:
184
184
  requirements:
185
185
  - - ">="
186
186
  - !ruby/object:Gem::Version
187
- hash: 5
187
+ hash: 3
188
188
  segments:
189
189
  - 0
190
190
  - 6
191
- - 1
192
- version: 0.6.1
191
+ - 2
192
+ version: 0.6.2
193
193
  requirement: *id011
194
194
  type: :development
195
195
  name: yard
@@ -200,15 +200,15 @@ dependencies:
200
200
  requirements:
201
201
  - - ">="
202
202
  - !ruby/object:Gem::Version
203
- hash: 5
203
+ hash: 47
204
204
  segments:
205
- - 1
206
- - 6
207
- - 5
208
- version: 1.6.5
205
+ - 0
206
+ - 12
207
+ - 0
208
+ version: 0.12.0
209
209
  requirement: *id012
210
210
  type: :development
211
- name: rdiscount
211
+ name: kramdown
212
212
  prerelease: false
213
213
  description: Win32 GUI testing framework
214
214
  email:
@@ -220,6 +220,7 @@ extensions: []
220
220
  extra_rdoc_files: []
221
221
 
222
222
  files:
223
+ - .gemfiles
223
224
  - .gitattributes
224
225
  - .gitignore
225
226
  - .yardopts
@@ -258,6 +259,7 @@ files:
258
259
  - examples/quicknote/spec/spec_helper.rb
259
260
  - examples/quicknote/spec/watchr.rb
260
261
  - examples/skeleton/.gitignore
262
+ - examples/skeleton/HISTORY.markdown
261
263
  - examples/skeleton/LICENSE
262
264
  - examples/skeleton/README.markdown
263
265
  - examples/skeleton/Rakefile
@@ -288,7 +290,10 @@ files:
288
290
  - spec/applications/calculator.rb
289
291
  - spec/auto_gui/application_spec.rb
290
292
  - spec/auto_gui/logging_spec.rb
293
+ - spec/auto_gui/window_spec.rb
294
+ - spec/basic_gem/aruba_helper_spec.rb
291
295
  - spec/basic_gem/basic_gem_spec.rb
296
+ - spec/basic_gem/gemspec_spec.rb
292
297
  - spec/spec.opts
293
298
  - spec/spec_helper.rb
294
299
  - spec/watchr.rb
@@ -334,15 +339,5 @@ rubygems_version: 1.3.7
334
339
  signing_key:
335
340
  specification_version: 3
336
341
  summary: Win32 GUI testing framework
337
- test_files:
338
- - features/automating_an_application.feature
339
- - features/step_definitions/.gitignore
340
- - features/step_definitions/calculator_steps.rb
341
- - features/support/env.rb
342
- - spec/applications/calculator.rb
343
- - spec/auto_gui/application_spec.rb
344
- - spec/auto_gui/logging_spec.rb
345
- - spec/basic_gem/basic_gem_spec.rb
346
- - spec/spec.opts
347
- - spec/spec_helper.rb
348
- - spec/watchr.rb
342
+ test_files: []
343
+