vapir-common 1.9.0 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -90,10 +90,10 @@ module Vapir
90
90
 
91
91
  # does the work of #screen_capture when the WinWindow library is being used for that. see #screen_capture documentation (browser-specific)
92
92
  def screen_capture_win_window(filename, options = {})
93
- options = handle_options(options, :dc => :window, :format => nil)
94
- if options[:format] && !(options[:format].is_a?(String) && options[:format].downcase == 'bmp')
95
- raise ArgumentError, ":format was specified as #{options[:format].inspect} but only 'bmp' is supported when :dc is #{options[:dc].inspect}"
93
+ if filename =~ /\.(\w+)\z/
94
+ extension = $1
96
95
  end
96
+ options = handle_options(options, :dc => :window, :format => extension)
97
97
  if options[:dc] == :desktop
98
98
  win_window.really_set_foreground!
99
99
  screenshot_win=WinWindow.desktop_window
@@ -101,7 +101,18 @@ module Vapir
101
101
  else
102
102
  screenshot_win=win_window
103
103
  end
104
- screenshot_win.capture_to_bmp_file(filename, :dc => options[:dc])
104
+ if !options[:format] || options[:format].downcase == 'bmp'
105
+ screenshot_win.capture_to_bmp_file(filename, :dc => options[:dc])
106
+ else
107
+ begin
108
+ require 'rmagick'
109
+ rescue LoadError
110
+ raise $!.class, "To use :format => #{format.inspect}, please install rmagick: http://rmagick.rubyforge.org/install-faq.html#win\n\n"+$!.message
111
+ end
112
+ bmp_blob = screenshot_win.capture_to_bmp_blob(:dc => options[:dc])
113
+ magick_img = Magick::Image.from_blob(bmp_blob)[0]
114
+ magick_img.write(filename) # magick handles converting based on extension
115
+ end
105
116
  end
106
117
  private :screen_capture_win_window
107
118
  end
@@ -76,6 +76,18 @@ module Vapir
76
76
  @config_hash = {}
77
77
  @recognized_options = {}
78
78
  yield(self) if block_given?
79
+ define_key_methods
80
+ end
81
+ # this is redundant with #method_missing, really, but it makes autocomplete possible in irb
82
+ def define_key_methods
83
+ recognized_keys.each do |recognized_key|
84
+ (class << self; self; end).send(:define_method, recognized_key) do
85
+ read(recognized_key)
86
+ end
87
+ (class << self; self; end).send(:define_method, "#{recognized_key}=") do |value|
88
+ update recognized_key, value
89
+ end
90
+ end
79
91
  end
80
92
  # if the method invoked looks like assignment (ends with an =), calls to #update with
81
93
  # the given method as the key and its argument as the value. otherwise calls #read with
@@ -109,7 +121,7 @@ module Vapir
109
121
  def []=(key, value)
110
122
  update(key, value)
111
123
  end
112
- # returns an array of
124
+ # returns an array of configuration keys which are recognized (either locally or inherited from a parent)
113
125
  def recognized_keys
114
126
  ((@parent ? @parent.recognized_keys : [])+@recognized_options.keys).uniq
115
127
  end
@@ -173,7 +185,7 @@ module Vapir
173
185
  end
174
186
  @recognized_options[key]= Option.new(key, options)
175
187
  end
176
- # reads the value for the given key. if on value is defined, raises NoValueError.
188
+ # reads the value for the given key. if no value is defined, raises NoValueError.
177
189
  def read(key)
178
190
  key = recognize_key! key
179
191
  if @config_hash.key?(key)
@@ -201,7 +213,7 @@ module Vapir
201
213
  update(k,v)
202
214
  end
203
215
  end
204
- # deletes the given value from the hash. this does not affect any ancestor Configurations.
216
+ # deletes the given key from the hash. this does not affect any ancestor Configurations.
205
217
  def delete(key)
206
218
  key = check_key key
207
219
  @config_hash.delete(key)
@@ -305,6 +317,15 @@ module Vapir
305
317
  end
306
318
 
307
319
  # :stopdoc:
320
+
321
+ # reopen this module to add stuff that's sort of separate from the Configurable module itself
322
+ module Configurable
323
+ # call the given block with :wait set to false
324
+ def without_waiting(&block)
325
+ with_config(:wait => false, &block)
326
+ end
327
+ end
328
+
308
329
  @configurations = []
309
330
  def (@configurations).update_from_source # :nodoc:
310
331
  self.each do |c|
@@ -267,7 +267,10 @@ module Vapir
267
267
  def locate!
268
268
  locate || begin
269
269
  klass=self.is_a?(Frame) ? Vapir::Exception::UnknownFrameException : Vapir::Exception::UnknownObjectException
270
- message="Unable to locate #{self.class}, using #{@how}"+(@what ? ": "+@what.inspect : '')+(@index ? ", index #{@index}" : "")
270
+ using = []
271
+ using << "#{@how}: #{@what.inspect}" if @how
272
+ using << "index: #{@index}" if @index
273
+ message="Unable to locate #{self.class}" + (using.any? ? ", using #{using.join(", ")}" : "")
271
274
  message+="\non container: #{@container.inspect}" if @container
272
275
  raise(klass, message)
273
276
  end
@@ -304,16 +304,14 @@ module Vapir
304
304
  dom_attr :text, :value, :selected
305
305
 
306
306
  # sets this Option's selected state to the given (true or false).
307
- # if this Option is aware of its select list (this will generally be the case if you
308
- # got this Option from a SelectList container), will fire the onchange event on the
309
- # select list if our state changes.
307
+ # will fire the onchange event on the select list if our state changes.
310
308
  def set_selected(state, method_options={})
311
- method_options={:highlight => true, :wait => true}.merge(method_options)
309
+ method_options={:highlight => true, :wait => config.wait}.merge(method_options)
312
310
  with_highlight(method_options) do
313
311
  state_was=element_object.selected
314
312
  element_object.selected=state # TODO: if state is false and this isn't an option of a multiple select list, should this error?
315
- if @extra[:select_list] && state_was != state
316
- @extra[:select_list].fire_event(:onchange, method_options)
313
+ if state_was != state
314
+ (@extra[:select_list] || parent_select_list).fire_event(:onchange, method_options)
317
315
  end
318
316
  wait if method_options[:wait]
319
317
  end
@@ -433,10 +431,10 @@ module Vapir
433
431
  # any have changed. raises Vapir::Exception::NoValueFoundException if none matched.
434
432
  # breaks after the first match found if this is not a multiple select list.
435
433
  # takes options hash (note, these are flags for the function, not to be confused with the Options of the select list)
436
- # - :wait => true/false default true. controls whether #wait is called and whether fire_event or fire_event_no_wait is
437
- # used for the onchange event.
434
+ # - :wait => true/false - default is the current config.wait value. controls whether #wait is called and whether
435
+ # fire_event or fire_event_no_wait is used for the onchange event.
438
436
  def select_options_if(method_options={})
439
- method_options={:wait => true, :highlight => true}.merge(method_options)
437
+ method_options={:wait => config.wait, :highlight => true}.merge(method_options)
440
438
  raise ArgumentError, "no block given!" unless block_given?
441
439
  assert_enabled
442
440
  any_matched=false
@@ -496,7 +494,7 @@ module Vapir
496
494
  # Fires the onchange event if value changes.
497
495
  # Fires the onclick event the state is true.
498
496
  def set(state=true, options={})
499
- options=handle_options(options, :highlight => true, :wait => true)
497
+ options=handle_options(options, :highlight => true, :wait => config.wait)
500
498
  with_highlight(options) do
501
499
  assert_enabled
502
500
  if checked!=state
@@ -527,9 +525,9 @@ module Vapir
527
525
  #
528
526
  # takes options:
529
527
  # * :highlight => true/false (defaults to true)
530
- # * :wait => true/false (defaults to false)
528
+ # * :wait => true/false (defaults to true)
531
529
  def set(state=true, options={})
532
- options=handle_options(options, :highlight => true, :wait => true)
530
+ options=handle_options(options, :highlight => true, :wait => config.wait)
533
531
  with_highlight(options) do
534
532
  assert_enabled
535
533
  if checked!=state
@@ -1,5 +1,6 @@
1
1
  require 'vapir-common/external/core_extensions'
2
2
  module Vapir
3
+ # Hash of all known key codes. hash keys are symbols representing the key. hash values are integers.
3
4
  KeyCodes = (('0'..'9').to_a+('a'..'z').to_a).inject({}){|hash, char| hash.merge(char.to_sym => char.vapir_ord) }.merge(
4
5
  {
5
6
  :cancel => 3,
@@ -83,6 +84,8 @@ module Vapir
83
84
  :quote => 222,
84
85
  :meta => 224,
85
86
  })
87
+ # Hash of key codes for characters that get printed when you hit the key (in a text field for example).
88
+ # hash keys are single-character strings; values are integers.
86
89
  PrintKeyCodes = (('0'..'9').to_a+('a'..'z').to_a).inject({}){|hash, char| hash.merge(char => char.to_sym) }.merge(
87
90
  {
88
91
  "\t" => :tab,
@@ -100,6 +103,9 @@ module Vapir
100
103
  ']' => :close_bracket,
101
104
  "'" => :quote,
102
105
  }).inject({}){|hash, (key, key_codes_key)| hash.merge(key => KeyCodes[key_codes_key]) }
106
+ # Hash of key codes for characters that get printed when you hit the key combined with the shift key
107
+ # (in a text field for example).
108
+ # hash keys are single-character strings; values are integers.
103
109
  ShiftPrintKeyCodes = ('A'..'Z').to_a.inject({}){|hash, char| hash.merge(char => char.downcase.to_sym) }.merge(
104
110
  {
105
111
  ')' => :'0',
@@ -123,6 +129,8 @@ module Vapir
123
129
  '}' => :close_bracket,
124
130
  '"' => :quote,
125
131
  }).inject({}){|hash, (key, key_codes_key)| hash.merge(key => KeyCodes[key_codes_key]) }
132
+ # Hash of key codes for characters on the number pad.
133
+ # hash keys are single-character strings; values are integers.
126
134
  NumpadKeyCodes = ('0'..'9').inject({}){|hash, char| hash.merge(char => "numpad#{char}".to_sym) }.merge(
127
135
  {
128
136
  '*' => :multiply,
@@ -1,5 +1,5 @@
1
1
  module Vapir
2
2
  module Common
3
- VERSION = '1.9.0'
3
+ VERSION = '1.10.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vapir-common
3
3
  version: !ruby/object:Gem::Version
4
- hash: 51
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
8
- - 9
7
+ - 10
9
8
  - 0
10
- version: 1.9.0
9
+ version: 1.10.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Ethan
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-08-04 00:00:00 -04:00
17
+ date: 2011-09-28 00:00:00 -04:00
19
18
  default_executable:
20
19
  dependencies: []
21
20
 
@@ -68,27 +67,23 @@ rdoc_options:
68
67
  require_paths:
69
68
  - lib
70
69
  required_ruby_version: !ruby/object:Gem::Requirement
71
- none: false
72
70
  requirements:
73
71
  - - ">="
74
72
  - !ruby/object:Gem::Version
75
- hash: 3
76
73
  segments:
77
74
  - 0
78
75
  version: "0"
79
76
  required_rubygems_version: !ruby/object:Gem::Requirement
80
- none: false
81
77
  requirements:
82
78
  - - ">="
83
79
  - !ruby/object:Gem::Version
84
- hash: 3
85
80
  segments:
86
81
  - 0
87
82
  version: "0"
88
83
  requirements: []
89
84
 
90
85
  rubyforge_project:
91
- rubygems_version: 1.3.7
86
+ rubygems_version: 1.3.6
92
87
  signing_key:
93
88
  specification_version: 3
94
89
  summary: Common basis for Vapir libraries for automating web browsers in Ruby