testability-driver 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +2 -2
  2. data/lib/tdriver-devtools/tdriver-devtools.rb +1 -1
  3. data/lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb +3 -3
  4. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +6 -1
  5. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +5 -3
  6. data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +1 -1
  7. data/lib/tdriver/base/behaviour/factory.rb +225 -225
  8. data/lib/tdriver/base/errors.rb +1 -1
  9. data/lib/tdriver/base/state_object.rb +227 -179
  10. data/lib/tdriver/base/sut/controller.rb +2 -2
  11. data/lib/tdriver/base/sut/factory.rb +190 -182
  12. data/lib/tdriver/base/sut/generic/behaviours/application.rb +69 -25
  13. data/lib/tdriver/base/sut/generic/behaviours/controller.rb +1 -1
  14. data/lib/tdriver/base/sut/generic/behaviours/find.rb +4 -4
  15. data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +3 -3
  16. data/lib/tdriver/base/sut/generic/behaviours/sut.rb +350 -165
  17. data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +9 -9
  18. data/lib/tdriver/base/sut/generic/behaviours/verification.rb +191 -103
  19. data/lib/tdriver/base/sut/generic/commands/application.rb +1 -1
  20. data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +1 -1
  21. data/lib/tdriver/base/sut/generic/commands/screen_capture.rb +1 -1
  22. data/lib/tdriver/base/sut/generic/plugin.rb +1 -1
  23. data/lib/tdriver/base/sut/sut.rb +5 -1
  24. data/lib/tdriver/base/test_object/abstract.rb +136 -151
  25. data/lib/tdriver/base/test_object/adapter.rb +293 -82
  26. data/lib/tdriver/base/test_object/behaviours/syncronization.rb +20 -17
  27. data/lib/tdriver/base/test_object/behaviours/test_object.rb +159 -532
  28. data/lib/tdriver/base/test_object/cache.rb +1 -1
  29. data/lib/tdriver/base/test_object/factory.rb +254 -605
  30. data/lib/tdriver/base/test_object/identificator.rb +1 -1
  31. data/lib/tdriver/base/test_object/loader.rb +1 -1
  32. data/lib/tdriver/base/test_object/verification.rb +17 -17
  33. data/lib/tdriver/loader.rb +20 -9
  34. data/lib/tdriver/report/report.rb +5 -0
  35. data/lib/tdriver/report/report_creator.rb +2 -2
  36. data/lib/tdriver/report/report_cucumber_listener.rb +4 -4
  37. data/lib/tdriver/report/report_cucumber_reporter.rb +4 -4
  38. data/lib/tdriver/report/report_execution_statistics.rb +22 -22
  39. data/lib/tdriver/report/report_grouping.rb +2 -2
  40. data/lib/tdriver/report/report_javascript.rb +11 -4
  41. data/lib/tdriver/report/report_test_case_run.rb +2 -2
  42. data/lib/tdriver/report/report_test_run.rb +5 -5
  43. data/lib/tdriver/report/report_test_unit.rb +74 -26
  44. data/lib/tdriver/report/report_writer.rb +70 -13
  45. data/lib/tdriver/tdriver.rb +17 -8
  46. data/lib/tdriver/util/common/array.rb +1 -1
  47. data/lib/tdriver/util/common/crc16.rb +1 -1
  48. data/lib/tdriver/util/common/environment.rb +1 -1
  49. data/lib/tdriver/util/common/file.rb +18 -9
  50. data/lib/tdriver/util/common/gem.rb +1 -1
  51. data/lib/tdriver/util/common/hash.rb +21 -0
  52. data/lib/tdriver/util/common/kernel.rb +1 -1
  53. data/lib/tdriver/util/common/loader.rb +5 -2
  54. data/lib/tdriver/util/common/numeric.rb +54 -3
  55. data/lib/tdriver/util/common/retryable.rb +30 -12
  56. data/lib/tdriver/util/common/stackable.rb +185 -0
  57. data/lib/tdriver/util/common/string.rb +21 -5
  58. data/lib/tdriver/util/{dbaccess/dbaccess.rb → database/access.rb} +4 -1
  59. data/lib/tdriver/util/{dbaccess/dbconnection.rb → database/connection.rb} +3 -0
  60. data/lib/tdriver/util/{dbaccess → database}/error.rb +0 -1
  61. data/lib/tdriver/util/{dbaccess → database}/loader.rb +5 -6
  62. data/lib/tdriver/util/{dynamic_attribute_filter.rb → filters/dynamic_attributes.rb} +1 -1
  63. data/lib/tdriver/util/hooking/hooking.rb +477 -0
  64. data/lib/tdriver/util/loader.rb +35 -29
  65. data/lib/tdriver/util/localisation/error.rb +0 -1
  66. data/lib/tdriver/util/localisation/loader.rb +1 -4
  67. data/lib/tdriver/util/localisation/localisation.rb +30 -27
  68. data/lib/tdriver/util/{common.rb → logger/loader.rb} +2 -4
  69. data/lib/tdriver/util/logger/logger.rb +574 -0
  70. data/lib/tdriver/util/operator_data/loader.rb +4 -3
  71. data/lib/tdriver/util/operator_data/operator_data.rb +5 -5
  72. data/lib/tdriver/util/parameter/parameter.rb +7 -1
  73. data/lib/tdriver/util/parameter/parameter_hash.rb +1 -1
  74. data/lib/tdriver/util/parameter/parameter_template.rb +1 -1
  75. data/lib/tdriver/util/parameter/parameter_user_api.rb +28 -20
  76. data/lib/tdriver/util/parameter/parameter_xml.rb +1 -1
  77. data/lib/tdriver/util/plugin/abstract.rb +1 -1
  78. data/lib/tdriver/util/plugin/service.rb +1 -1
  79. data/lib/tdriver/util/{localisation.rb → recorder/loader.rb} +4 -3
  80. data/lib/tdriver/util/recorder/recorder.rb +66 -0
  81. data/lib/tdriver/util/recorder/scripter.rb +258 -0
  82. data/lib/tdriver/util/{stats.rb → statistics/statistics.rb} +7 -8
  83. data/lib/tdriver/util/user_data/error.rb +0 -1
  84. data/lib/tdriver/util/user_data/loader.rb +1 -2
  85. data/lib/tdriver/util/user_data/user_data.rb +6 -6
  86. data/lib/tdriver/util/video/camera.rb +67 -0
  87. data/lib/tdriver/util/video/camera_linux.rb +139 -0
  88. data/lib/tdriver/util/video/camera_windows.rb +174 -0
  89. data/lib/tdriver/util/video/loader.rb +31 -0
  90. data/lib/tdriver/util/video/video_utils.rb +139 -0
  91. data/lib/tdriver/util/xml/abstraction.rb +56 -5
  92. data/lib/tdriver/util/xml/builder.rb +2 -5
  93. data/lib/tdriver/util/{parameter.rb → xml/comment.rb} +10 -2
  94. data/lib/tdriver/util/xml/loader.rb +32 -22
  95. data/lib/tdriver/util/xml/nil_node.rb +2 -2
  96. data/lib/tdriver/util/xml/parsers/loader.rb +0 -1
  97. data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +18 -44
  98. data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +9 -13
  99. data/lib/tdriver/util/xml/parsers/nokogiri/builder.rb +9 -3
  100. data/lib/tdriver/util/xml/parsers/nokogiri/comment.rb +39 -0
  101. data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +6 -11
  102. data/lib/tdriver/util/xml/parsers/nokogiri/element.rb +2 -122
  103. data/lib/tdriver/util/xml/parsers/nokogiri/loader.rb +26 -16
  104. data/lib/tdriver/util/xml/parsers/nokogiri/node.rb +203 -0
  105. data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +1 -2
  106. data/lib/tdriver/util/xml/parsers/nokogiri/text.rb +2 -20
  107. data/lib/tdriver/util/xml/xml.rb +52 -20
  108. data/lib/tdriver/verify/verify.rb +238 -81
  109. data/xml/behaviours/generic.xml +12 -10
  110. metadata +156 -180
  111. data/lib/tdriver/base/test_object/factory_new.rb +0 -202
  112. data/lib/tdriver/util/hooking.rb +0 -434
  113. data/lib/tdriver/util/logger.rb +0 -506
  114. data/lib/tdriver/util/recorder.rb +0 -297
  115. data/lib/tdriver/util/video_utils.rb +0 -384
  116. data/lib/tdriver/util/xml/nil_element.rb +0 -89
@@ -86,12 +86,6 @@ module MobyBehaviour
86
86
  #
87
87
  def wait_child( attributes = {}, timeout_secs = 10, retry_interval = 0.5 )
88
88
 
89
- #Kernel::raise ArgumentError.new( "Argument attributes was not a valid. Expected: Hash" ) unless attributes.kind_of?( Hash )
90
- #Kernel::raise ArgumentError.new( "Argument type was not a valid. Expected: String" ) unless attributes[ :type ].kind_of?( String ) && attributes[ :type ].length > 0
91
- #Kernel::raise ArgumentError.new( "Argument timeout_secs was not a valid. Expected: Integer, Fixnum or Float" ) unless [ Integer, Fixnum, Float ].include? timeout_secs.class
92
- #Kernel::raise ArgumentError.new( "Argument retry_interval was not a valid. Expected: Integer, Fixnum or Float" ) unless [ Integer, Fixnum, Float ].include? retry_interval.class
93
-
94
-
95
89
  # verify that attributes is type of Hash
96
90
  attributes.check_type( Hash, "Wrong argument type $1 for attributes (expected $2)" )
97
91
 
@@ -108,20 +102,29 @@ module MobyBehaviour
108
102
  retry_interval.check_type( [ Integer, Fixnum, Float ], "Wrong argument type $1 for retry interval (expected $2)" )
109
103
 
110
104
  begin
105
+
106
+ dynamic_attributes = attributes.strip_dynamic_attributes!
107
+
108
+ # try to identify desired child test object
109
+ @test_object_factory.identify_object(
110
+ :object_attributes_hash => attributes,
111
+ :identification_directives => dynamic_attributes.default_values(
112
+ :__timeout => timeout_secs,
113
+ :__retry_interval => retry_interval,
114
+ :__refresh_arguments => self.kind_of?( MobyBase::SUT ) ? attributes : { :id => self.get_application_id }
115
+ ),
116
+ :parent => self
117
+ )
118
+
119
+ rescue MobyBase::TestObjectNotFoundError
111
120
 
112
- MobyUtil::Retryable.until( :timeout => timeout_secs, :interval => retry_interval ) {
113
-
114
- #self.refresh( attributes )
115
-
116
- self.refresh( self.kind_of?( MobyBase::SUT ) ? attributes : { :id => self.get_application_id } )
121
+ # the child object was not found in the specified timeout
122
+ raise MobyBase::SyncTimeoutError, "Synchronization timed out (#{ timeout_secs }) before the defined child object could be found."
117
123
 
118
- MobyBase::TestObjectIdentificator.new( attributes ).find_object_data( self.xml_data )
124
+ rescue # unexpected errors
119
125
 
120
- }
121
- rescue
126
+ raise RuntimeError, "Synchronization failed due to #{ $!.message } (#{ $!.class })"
122
127
 
123
- # the child object was not found in the specified timeout
124
- Kernel::raise MobyBase::SyncTimeoutError.new( "Synchronization timed out (%i) before the defined child object could be found." % timeout_secs )
125
128
  end
126
129
 
127
130
  self
@@ -129,7 +132,7 @@ module MobyBehaviour
129
132
  end
130
133
 
131
134
  # enable hooking for performance measurement & debug logging
132
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
135
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
133
136
 
134
137
  end # TDriverSyncronization
135
138
 
@@ -51,6 +51,16 @@ module MobyBehaviour
51
51
  # example: { :name => 'Triangle1', :type => :Triangle }
52
52
  attr_accessor :creation_attributes
53
53
 
54
+ =begin
55
+ # == nodoc
56
+ # == description
57
+ # attr_reader
58
+ # == returns
59
+ # Hash
60
+ # description: Parent application test object
61
+ # example: <MobyBase::TestObject>
62
+ attr_reader :parent_application
63
+ =end
54
64
 
55
65
  # == nodoc
56
66
  # == description
@@ -89,12 +99,24 @@ module MobyBehaviour
89
99
  # attributes_hash = @test_app.Triangle( :name => 'Triangle1' ).attributes # retrieve all attribute for triangle object
90
100
  def attributes
91
101
 
102
+ # retrieve sut parameters
103
+ sut_parameters = $parameters[ @sut.id ]
104
+
105
+ # retrieve sut attribute filter type
106
+ filter_type = sut_parameters[ :filter_type, 'none' ]
107
+
108
+ # temporarly disable attribute filter to retrieve all test object attributes
109
+ sut_parameters[ :filter_type ] = 'none'
110
+
92
111
  begin
93
112
 
113
+ # raise exception to refresh test object ui state if filter_type was something else than 'none'
114
+ raise MobyBase::TestObjectNotFoundError unless filter_type == 'none'
115
+
94
116
  # retrieve xml data, performs xpath to sut xml_data
95
117
  _xml_data = xml_data
96
118
 
97
- rescue MobyBase::TestObjectNotFoundError
119
+ rescue MobyBase::TestObjectNotFoundError
98
120
 
99
121
  # attributes used to refresh parent application
100
122
  if @creation_attributes[ :type ] == 'application'
@@ -115,6 +137,11 @@ module MobyBehaviour
115
137
  # retrieve updated xml data
116
138
  _xml_data = xml_data
117
139
 
140
+ ensure
141
+
142
+ # restore attributes filter type
143
+ sut_parameters[ :filter_type ] = filter_type
144
+
118
145
  end
119
146
 
120
147
  # return hash of test object attributes
@@ -151,8 +178,8 @@ module MobyBehaviour
151
178
  # TODO: add behaviour logging?
152
179
 
153
180
  # raise exception if attribute name variable type is other than string
154
- name.check_type( [ String, Symbol ], "Wrong argument type %s for attribute (expected $2)" )
155
-
181
+ name.check_type( [ String, Symbol ], "Wrong argument type $1 for attribute (expected $2)" )
182
+
156
183
  # convert name to string if variable type is symbol
157
184
  name = name.to_s if name.kind_of?( Symbol )
158
185
 
@@ -214,90 +241,9 @@ module MobyBehaviour
214
241
  enable_optimizer
215
242
 
216
243
  parent
217
-
218
-
219
- =begin
220
-
221
- # return current test object if it's type of application
222
- return self if application?
223
-
224
- @sut.refresh if disable_optimizer
225
-
226
- # find parent id
227
- element_set = @sut.xml_data.xpath( "//object/objects/object[@id='#{ @id }']/../.." )
228
-
229
- kid = nil
230
-
231
- if( element_set == nil or element_set.size == 0 )
232
-
233
- # return self if there is not parent object available
234
- kid = self
235
-
236
- else
237
-
238
- element = element_set.first
239
-
240
- #if app set look for the item under the app to make sure app id is available
241
-
242
- if self.get_application_id && element.attribute( "type" ) != 'application'
243
-
244
- kid = @sut.child(
245
- :id => get_application_id,
246
- :type => 'application'
247
- ).child(
248
- :id => element.attribute( "id" ),
249
- :name => element.attribute( "name" ),
250
- :type => element.attribute( "type" ),
251
- :__index => 0 # there was a case when the same parent was included twice in the ui dump
252
- )
253
-
254
- else
255
-
256
- kid = @sut.child(
257
- :id => element.attribute( "id" ),
258
- :name => element.attribute( "name" ),
259
- :type => element.attribute( "type" )
260
- )
261
-
262
- end
263
-
264
- end
265
-
266
- enable_optimizer
267
-
268
- kid
269
- =end
270
244
 
271
245
  end
272
246
 
273
- # == nodoc
274
- # Updates this test object to match the data in the provided xml document
275
- # Propagates updating to all child TestObjects
276
- # If TestObject is not identified, then current TO is deactivated, as is all the Child objects, as defined in TestObject#deactivate.
277
- # === params
278
- # xml_document:: LibXML::XML::Node describing the new state of this test object
279
- # === returns
280
- # ?
281
- # === raises
282
- # nothing
283
- def update( xml_document )
284
-
285
- begin
286
-
287
- if !( _xml_data = MobyBase::TestObjectIdentificator.new( :type => @type, :id => @id, :name => @name ).find_object_data( xml_document ) ).eql?( xml_data )
288
-
289
- @_child_objects.each { | test_object | test_object.update( ( xml_data = _xml_data ) ) }
290
-
291
- end
292
-
293
- rescue MobyBase::TestObjectNotFoundError, MobyBase::MultipleTestObjectsIdentifiedError
294
-
295
- deactivate
296
-
297
- end
298
-
299
- end
300
-
301
247
  # == nodoc
302
248
  # Function refreshes test objects to correspond with the current state of the device.
303
249
  #
@@ -309,13 +255,7 @@ module MobyBehaviour
309
255
  # TestObjectNotFoundError:: if TestObject is not identified within synch timeout.
310
256
  def refresh( refresh_args = {} )
311
257
 
312
- @sut.refresh(
313
-
314
- refresh_args,
315
-
316
- @test_object_factory.get_parent_params( parent ) << @test_object_factory.make_object_search_params( @creation_attributes )
317
-
318
- )
258
+ @sut.refresh( refresh_args, @test_object_factory.make_object_search_params( parent, @creation_attributes ) )
319
259
 
320
260
  end
321
261
 
@@ -331,7 +271,7 @@ module MobyBehaviour
331
271
  # TestObjectNotFoundError:: if TestObject is not identified within synch timeout.
332
272
  def force_refresh( refresh_args = {} )
333
273
 
334
- refresh(refresh_args)
274
+ refresh( refresh_args )
335
275
 
336
276
  end
337
277
 
@@ -345,6 +285,10 @@ module MobyBehaviour
345
285
  # parent_app = @app.Node( :name => 'Node1' ).get_application() #get application for some test object, this should return @app.
346
286
  def get_application
347
287
 
288
+ # test object should have @parent_application always
289
+ return @parent_application if @parent_application
290
+
291
+ # workaround: fetch application from sut, this part of code should not be executed ever
348
292
  return self if application?
349
293
 
350
294
  test_object = @parent
@@ -359,7 +303,6 @@ module MobyBehaviour
359
303
 
360
304
  # return application object or nil if no parent found
361
305
  # Does is make sense to return nil - should n't all test objects belong to an application? Maybe throw exception if application not found
362
-
363
306
  return @sut.child( :type => 'application' ) rescue nil
364
307
 
365
308
  end
@@ -373,8 +316,10 @@ module MobyBehaviour
373
316
  # puts @app.Node( :name => 'Node1' ).get_application_id() #print the application id, this should print @app.id
374
317
  def get_application_id
375
318
 
376
- return @_application_id if @_application_id
377
- #What about the case when get_application returns nil? This line will throw an exception in that case.
319
+ return @parent_application.id if @parent_application
320
+
321
+ # workaround
322
+ # What about the case when get_application returns nil? This line will throw an exception in that case.
378
323
  get_application.id
379
324
 
380
325
  end
@@ -406,174 +351,6 @@ module MobyBehaviour
406
351
 
407
352
  end
408
353
 
409
- # == nodoc
410
- # == description
411
- # Translates all symbol values in hash using SUT's translate method.
412
- #
413
- # == arguments
414
- # hash
415
- # Hash
416
- # description: containing key and value pairs. The hash will get modified if symbols are found from values
417
- # example: {:text=>:translate_me}
418
- #
419
- # == returns
420
- # Hash
421
- # description: Translated hash
422
- # example: {:text=>'translated_text'}
423
- # == exceptions
424
- # LanguageNotFoundError
425
- # description: In case of language is not found
426
- #
427
- # LogicalNameNotFoundError
428
- # description: In case of logical name is not found for current language
429
- #
430
- # MySqlConnectError
431
- # description: In case problems with the db connectivity
432
- #
433
- def translate!( hash, file_name = nil, plurality = nil, numerus = nil, lengthvariant = nil )
434
-
435
- hash.each_pair do | _key, _value |
436
-
437
- next if [ :name, :type, :id ].include?( _key )
438
-
439
- hash[ _key ] = sut.translate( _value, file_name, plurality, numerus, lengthvariant ) if _value.kind_of?( Symbol )
440
-
441
- end if !hash.nil?
442
-
443
- end
444
-
445
- =begin
446
- # == description
447
- # Creates a child test object of this test object. Caller object will be associated as child test objects parent.\n
448
- # \n
449
- # [b]NOTE:[/b] Subsequent calls to TestObject#child( rule ) always returns reference to same Testobject:\n
450
- # [code]a = to.child( :type => 'Button', :text => '1' )
451
- # b = to.child( :type => 'Button', :text => '1' )
452
- # a.eql?( b ) # => true[/code]
453
- # == arguments
454
- # attributes
455
- # Hash
456
- # description: Hash object holding information for identifying which child to create
457
- # example: { :type => :slider }
458
- #
459
- # == returns
460
- # MobyBase::TestObject
461
- # description: new child test object or reference to existing child
462
- # example: -
463
- #
464
- # == exceptions
465
- # TypeError
466
- # description: Wrong argument type %s for attributes (expected Hash)
467
- #
468
- # MultipleTestObjectsIdentifiedError
469
- # description: raised if multiple objects found that match the given attributes
470
- #
471
- # TestObjectNotFoundError
472
- # description: raised if the child object could not be found
473
- #
474
- # TestObjectNotVisibleError
475
- # description: rasied if the parent test object is no longer visible
476
- def child( attributes )
477
-
478
- # verify attributes argument format
479
- #raise TypeError.new( 'Unexpected argument type (%s) for attributes, expecting %s' % [ attributes.class, "Hash" ] ) unless attributes.kind_of?( Hash )
480
- attributes.check_type( Hash, "Wrong argument type $1 for attributes (expected $2)" )
481
-
482
-
483
- # retrieve child object
484
- get_child_objects( attributes )
485
-
486
- end
487
-
488
- def child( attributes )
489
-
490
- ###############################################################################################################
491
- #
492
- # NOTICE: Please do not add anything unnessecery to this method, it might cause a major performance impact
493
- #
494
-
495
- # verify attributes argument format
496
- attributes.check_type( Hash, "Wrong argument type $1 for attributes (expected $2)" )
497
-
498
- # store original hash
499
- creation_hash = attributes.clone
500
-
501
- dynamic_attributes = creation_hash.strip_dynamic_attributes!
502
-
503
- # raise exception if wrong value type given for ;__logging
504
- dynamic_attributes[ :__logging ].check_type(
505
-
506
- [ TrueClass, FalseClass ],
507
-
508
- "Wrong value type $1 for :__logging test object creation directive (expected $2)"
509
-
510
- ) if dynamic_attributes.has_key?( :__logging )
511
-
512
- # disable logging if requested, remove pair from creation_hash
513
- MobyUtil::Logger.instance.push_enabled( dynamic_attributes[ :__logging ] || TDriver.logger.enabled )
514
-
515
- # check if the hash contains symbols as values and translate those into strings
516
- translate!( creation_hash, attributes[ :__fname ], attributes[ :__plurality ], attributes[ :__numerus ], attributes[ :__lengthvariant ] )
517
-
518
- begin
519
-
520
- # TODO: refactor me
521
- child_test_object = @test_object_factory.make_object(
522
-
523
- # current object as parent, can be either TestObject or SUT
524
- :parent => self,
525
-
526
- # test object identification hash
527
- :object_attributes_hash => creation_hash,
528
-
529
- :identification_directives => dynamic_attributes
530
-
531
- )
532
-
533
-
534
- rescue Exception => exception
535
-
536
- if exception.kind_of?( MobyBase::MultipleTestObjectsIdentifiedError )
537
-
538
- description = "Multiple child objects matched criteria."
539
-
540
- elsif exception.kind_of?( MobyBase::TestObjectNotFoundError )
541
-
542
- description = "The child object(s) could not be found."
543
-
544
- elsif exception.kind_of?( MobyBase::TestObjectNotVisibleError )
545
-
546
- description = "Parent test object no longer visible."
547
-
548
- else
549
-
550
- description = "Failed when trying to find child object(s)."
551
-
552
- end
553
-
554
- TDriver.logger.behaviour(
555
-
556
- "%s;%s;%s;%s;%s" % [ "FAIL", description, identity, dynamic_attributes[ :__multiple_objects ] ? "children" : "child", attributes.inspect ]
557
-
558
- )
559
-
560
- Kernel::raise exception
561
-
562
-
563
- ensure
564
-
565
- # restore original logger state
566
- MobyUtil::Logger.instance.pop_enabled
567
-
568
- end
569
-
570
- # return child test object
571
- child_test_object
572
-
573
- end
574
-
575
- =end
576
-
577
354
  # == description
578
355
  # Creates a child test object of this test object. Caller object will be associated as child test objects parent.\n
579
356
  # \n
@@ -652,150 +429,166 @@ module MobyBehaviour
652
429
  # verify find_all_children argument format
653
430
  find_all_children.check_type( [ TrueClass, FalseClass ], "Wrong argument type $1 for find_all_children (expected $2)" )
654
431
 
655
- # If empty or only special attributes then add :type => "any" to search all
656
- attributes.merge!( :type => "any" ) if attributes.select{ | key, value | key.to_s !~ /^__/ ? true : false }.empty?
432
+ # If empty or only special attributes then add :type => '*' to search all
433
+ attributes[ :type ] = '*' if attributes.select{ | key, value | key.to_s !~ /^__/ ? true : false }.empty?
657
434
 
658
435
  # children method specific settings
659
436
  attributes.merge!( :__multiple_objects => true, :__find_all_children => find_all_children )
660
437
 
661
438
  # disable optimizer state if enabled
662
- disable_optimizer
439
+ disable_optimizer
663
440
 
664
441
  # retrieve child objects
665
442
  result = get_child_objects( attributes )
666
443
 
667
444
  # restore optimizer state if it was enabled
668
- enable_optimizer
445
+ enable_optimizer
669
446
 
670
447
  # return results
671
448
  result
672
449
 
673
450
  end
674
451
 
675
-
676
-
677
-
678
-
679
-
680
-
681
-
682
-
683
-
684
- =begin
685
- # == description
686
- # Function similar to child, but returns an array of children test objects that meet the given criteria
687
- #
688
- # == arguments
689
- # attributes
690
- # Hash
691
- # description: object holding information for identifying which child to create
692
- # example: { :type => :slider }
693
- #
694
- # find_all_children
695
- # TrueClass
696
- # description: Boolean specifying whether all children under the test node or just immediate children should be retreived
697
- # example: true
698
- # FalseClass
699
- # description: Boolean specifying whether all children under the test node or just immediate children should be retreived
700
- # example: false
701
- #
702
- # == returns
703
- # Array
704
- # description: An array of test objects
705
- # example: [ MobyBase::TestObject, MobyBase::TestObject, MobyBase::TestObject, ... ]
706
- #
707
- # == exceptions
708
- # TypeError
709
- # description: raised if agument is not a Hash
710
- #
711
- # TestObjectNotFoundError
712
- # description: raised if the child object could not be found
713
- #
714
- # TestObjectNotVisibleError
715
- # description: rasied if the parent test object is no longer visible
716
- def children( attributes, find_all_children = true )
452
+ private
717
453
 
718
- # verify attributes argument format
719
- #raise TypeError.new( 'Unexpected argument type (%s) for attributes, expecting %s' % [ attributes.class, "Hash" ] ) unless attributes.kind_of?( Hash )
720
- attributes.check_type( Hash, "Wrong argument type $1 for attributes (expected $2)" )
454
+ # == nodoc
455
+ # Updates this test object to match the data in the provided xml document
456
+ # Propagates updating to all child TestObjects
457
+ # If TestObject is not identified, then current TO is deactivated, as is all the Child objects, as defined in TestObject#deactivate.
458
+ # === params
459
+ # xml_document:: MobyUtil::XML::Node describing the new state of this test object
460
+ # === returns
461
+ # ?
462
+ # === raises
463
+ # nothing
464
+ def update( xml_document )
721
465
 
722
- # verify attributes argument format
466
+ begin
723
467
 
724
- # respect the original attributes variable value
725
- creation_attributes = attributes.clone
468
+ # find object from new xml data
469
+ _xml_data, unused_rule = TDriver::TestObjectAdapter.get_objects( xml_document, { :type => @type, :id => @id, :name => @name }, true )
470
+
471
+ # deactivate if test object not found or multiple matches found
472
+ raise unless _xml_data.count == 1
726
473
 
727
- # If empty or only special attributes then add :type => "any" to search all
728
- creation_attributes.merge!( :type => "any" ) if creation_attributes.select{ | key, value | key.to_s !~ /^__/ ? true : false }.empty?
474
+ # get first matching element
475
+ _xml_data = _xml_data.first
729
476
 
730
- # children method specific settings
731
- creation_attributes.merge!( :__multiple_objects => true, :__find_all_children => find_all_children )
477
+ #unless _xml_data.eql?( xml_data )
732
478
 
733
- disable_optimizer
479
+ # store previous object environment value
480
+ previous_environment = @env
734
481
 
735
- # retrieve child objects
736
- kids = get_child_objects( creation_attributes )
482
+ # update current test objects xml_data
483
+ __send__( :xml_data=, _xml_data )
737
484
 
738
- enable_optimizer
485
+ # compare new environment value with previous
486
+ if @env != previous_environment
739
487
 
740
- kids
488
+ # reapply behaviours to test object if environment value has changed
489
+ MobyBase::BehaviourFactory.instance.apply_behaviour!(
741
490
 
742
- end
743
- =end
491
+ :object => self,
492
+ :object_type => [ '*', @type ],
493
+ :input_type => [ '*', @sut.input.to_s ],
494
+ :env => [ '*', *@env.to_s.split(";") ],
495
+ :version => [ '*', @sut.ui_version.to_s ]
744
496
 
745
- private
497
+ )
498
+
499
+ end
500
+
501
+ # update child objects
502
+ @child_object_cache.each_object{ | test_object |
503
+
504
+ # update test object with new xml_data
505
+ #test_object.update( _xml_data )
506
+ test_object.send( :update, _xml_data )
507
+
508
+ }
509
+
510
+ #end
511
+
512
+ rescue
513
+
514
+ # deactivate test object
515
+ deactivate
516
+
517
+ end
518
+
519
+ end
746
520
 
747
521
  # TODO: document me
748
- def disable_optimizer
522
+ def disable_optimizer
749
523
 
750
- sut_parameters = MobyUtil::Parameter[ @sut.id ]
524
+ sut_parameters = $parameters[ @sut.id ]
751
525
 
752
- # disable optimizer for this call since it will not work
753
- @_enable_optimizer = false
526
+ # disable optimizer for this call since it will not work
527
+ @_enable_optimizer = false
754
528
 
755
- if sut_parameters[ :use_find_object, 'false' ] == 'true' and @sut.respond_to?( 'find_object' )
529
+ if sut_parameters[ :use_find_object, 'false' ] == 'true' and @sut.respond_to?( 'find_object' )
756
530
 
757
- sut_parameters[ :use_find_object ] = 'false'
531
+ sut_parameters[ :use_find_object ] = 'false'
758
532
 
759
- @_enable_optimizer = true
533
+ @_enable_optimizer = true
760
534
 
761
- end
535
+ end
762
536
 
763
- @_enable_optimizer
537
+ @_enable_optimizer
764
538
 
765
- end
539
+ end
766
540
 
767
541
  # TODO: document me
768
- def enable_optimizer
542
+ def enable_optimizer
769
543
 
770
- MobyUtil::Parameter[ @sut.id ][ :use_find_object ] = 'true' if @_enable_optimizer
544
+ $parameters[ @sut.id ][ :use_find_object ] = 'true' if @_enable_optimizer
771
545
 
772
- @_enable_optimizer = false
546
+ @_enable_optimizer = false
773
547
 
774
- end
548
+ end
775
549
 
776
550
  # TODO: document me
777
551
  # Tries to use the missing method id as a child object type and find an object based on it
778
552
  def method_missing( method_id, *method_arguments )
779
553
 
780
- # method mapping/aliases - this should be configured in xml file
781
- #case method_id
782
- # when :Button; method_id = [ :Button, :QToolButton, :DuiButton, :HbPushButton, :softkey ]
783
- # when :List; method_id = [ :QList, :HbListWidgetView, :DuiList ]
784
- #end
554
+ # create rules hash
555
+ rules_hash = method_arguments.first
785
556
 
786
- hash_rule = ( method_arguments.first.kind_of?( Hash ) ? method_arguments.first : {} ).merge( :type => method_id )
557
+ # set rules hash to empty Hash if rules hash is not type of Hash
558
+ rules_hash = {} unless rules_hash.kind_of?( Hash )
787
559
 
560
+ # set test object type
561
+ rules_hash[ :type ] = method_id #.to_s
562
+
788
563
  begin
789
564
 
790
- child( hash_rule )
565
+ # return created child object
566
+ child( rules_hash )
791
567
 
792
568
  rescue MobyBase::TestObjectNotFoundError, MobyBase::TestObjectNotVisibleError
793
569
 
794
- #hash_rule.delete( :type )
570
+ rules_hash_clone = rules_hash.clone
571
+
572
+ rules_hash_clone.delete(:type)
795
573
 
574
+ # string representation of used rule hash, remove curly braces
575
+ attributes_string = rules_hash_clone.inspect[ 1 .. -2 ]
576
+
577
+ if attributes_string.empty?
578
+
579
+ # do not show any attribute details if none given
580
+ attributes_string = ""
581
+
582
+ else
583
+
584
+ # show used attributes
585
+ attributes_string = " (attributes #{ attributes_string })"
586
+
587
+ end
588
+
589
+ # raise exception
796
590
  Kernel::raise MobyBase::TestObjectNotFoundError.new(
797
- 'The test object (id: "%s", type: "%s", name: "%s") has no child object with type or behaviour method with name "%s" (%s) on sut "%s".' %
798
- [ @id, @type, @name, method_id.inspect, ( hash_rule.empty? ? "" : "attributes: #{ hash_rule.inspect }" ), @sut.id ]
591
+ "The test object (id: #{ @id }, type: #{ @type.inspect }, name: #{ @name.inspect }) has no child object with type or behaviour method with name #{ method_id.to_s.inspect }#{ attributes_string } on #{ @sut.id.inspect }"
799
592
  )
800
593
 
801
594
  end
@@ -825,22 +618,26 @@ module MobyBehaviour
825
618
  ) if dynamic_attributes.has_key?( :__logging )
826
619
 
827
620
  # disable logging if requested, remove pair from creation_hash
828
- MobyUtil::Logger.instance.push_enabled( dynamic_attributes[ :__logging ] || TDriver.logger.enabled )
621
+ $logger.push_enabled( dynamic_attributes[ :__logging ] || TDriver.logger.enabled )
829
622
 
830
- # check if the hash contains symbols as values and translate those into strings
831
- translate!( creation_hash, attributes[ :__fname ], attributes[ :__plurality ], attributes[ :__numerus ], attributes[ :__lengthvariant ] )
623
+ # check if the hash contains symbols as values and translate those into strings
624
+ @sut.translate_values!( creation_hash, attributes[ :__fname ], attributes[ :__plurality ], attributes[ :__numerus ], attributes[ :__lengthvariant ] )
832
625
 
833
626
  begin
834
627
 
835
628
  # TODO: refactor me
836
629
  child_test_object = @test_object_factory.get_test_objects(
837
630
 
838
- # current object as parent, can be either TestObject or SUT
631
+ # current objec t as parent, can be either TestObject or SUT
839
632
  :parent => self,
840
633
 
634
+ # pass parent application
635
+ :parent_application => @parent_application,
636
+
841
637
  # test object identification hash
842
638
  :object_attributes_hash => creation_hash,
843
-
639
+
640
+ # pass test object identification directives, e.g. :__index
844
641
  :identification_directives => dynamic_attributes
845
642
 
846
643
  )
@@ -865,7 +662,7 @@ module MobyBehaviour
865
662
 
866
663
  end
867
664
 
868
- TDriver.logger.behaviour(
665
+ $logger.behaviour(
869
666
 
870
667
  "%s;%s;%s;%s;%s" % [
871
668
  "FAIL",
@@ -882,7 +679,7 @@ module MobyBehaviour
882
679
  ensure
883
680
 
884
681
  # restore original logger state
885
- MobyUtil::Logger.instance.pop_enabled
682
+ $logger.pop_enabled
886
683
 
887
684
  end
888
685
 
@@ -923,7 +720,6 @@ module MobyBehaviour
923
720
 
924
721
  end
925
722
 
926
-
927
723
  # TODO: refactor logging_enabled
928
724
  # try to reactivate test object if currently not active
929
725
  def reactivate_test_object( attributes )
@@ -944,181 +740,12 @@ module MobyBehaviour
944
740
 
945
741
  end
946
742
 
947
- =begin
948
- # Strip dynamic attributes (such as :__timeout, :__logging) from hash and return those as hash
949
- # == returns
950
- # Hash:: Hash of dynamic attributes
951
- def strip_dynamic_attributes!( attributes, exceptions = [] )
952
-
953
- Hash[ attributes.select{ | key, value |
954
-
955
- if /^__/.match( key.to_s ) and !exceptions.include?( key )
956
-
957
- attributes.delete( key )
958
-
959
- true
960
-
961
- else
962
-
963
- false
964
-
965
- end
966
-
967
- }]
968
-
969
- end
970
-
971
- def get_cached_test_object!( object )
972
-
973
- if @child_object_cache.has_object?( object )
974
-
975
- object = @child_object_cache[ object ]
976
-
977
- true
978
-
979
- else
980
-
981
- false
982
-
983
- end
984
-
985
- end
986
- =end
987
-
988
-
989
- =begin
990
- def get_child_objects( attributes )
991
-
992
- # create copy of attributes hash
993
- creation_data = attributes.clone
994
-
995
- # strip all dynamic attributes such as :__timeout, :__logging etc.
996
- dynamic_attributes = strip_dynamic_attributes!( creation_data )
997
-
998
- # store and set logger state if given, use default value if none given
999
- TDriver.logger.push_enabled( MobyUtil::KernelHelper.to_boolean( dynamic_attributes[ :__logging ], TDriver.logger.enabled ) )
1000
-
1001
- # determine if multiple matches is allowed, default value is false
1002
- multiple_objects = MobyUtil::KernelHelper.to_boolean( dynamic_attributes[ :__multiple_objects ], false )
1003
-
1004
- find_all_children = MobyUtil::KernelHelper.to_boolean( dynamic_attributes[ :__find_all_children ], true )
1005
-
1006
- # check if the hash contains symbols as values and translate those into strings
1007
- file_name = dynamic_attributes[ :__fname ]
1008
- plurality = dynamic_attributes[ :__plurality ]
1009
- numerus = dynamic_attributes[ :__numerus ]
1010
- lengthvariant = dynamic_attributes[ :__lengthvariant ]
1011
-
1012
- translate!( creation_data, file_name, plurality, numerus, lengthvariant )
1013
-
1014
- # use custom timeout if defined
1015
- timeout = ( dynamic_attributes[ :__timeout ] || @test_object_factory.timeout ).to_i
1016
-
1017
- # determine which application to refresh
1018
- #application_id_hash = ( creation_data[ :type ] == 'application' ? { :name => creation_data[ :name ], :id => creation_data[ :id ] } : { :id => get_application_id } )
1019
-
1020
- if creation_data[ :type ] == 'application'
1021
-
1022
- application_id_hash = { :name => creation_data[ :name ], :id => creation_data[ :id ] }
1023
-
1024
- else
1025
-
1026
- application_id_hash = { :id => get_application_id }
1027
-
1028
- end
1029
-
1030
- # add symbols to dynamic attributes list -- to avoid IRB bug
1031
- MobyUtil::DynamicAttributeFilter.instance.add_attributes( creation_data.keys )
1032
-
1033
- begin
1034
-
1035
- # try to reactivate test object if currently not active
1036
- #reactivate_test_object( creation_data ) unless @_active
1037
-
1038
- # retrieve test objects from xml
1039
- child_objects = @test_object_factory.make_child_objects(
1040
-
1041
- :attributes => creation_data,
1042
- :dynamic_attributes => dynamic_attributes,
1043
-
1044
- :parent => self,
1045
- :sut => @sut,
1046
- :application => application_id_hash,
1047
-
1048
- :timeout => timeout,
1049
- :multiple_objects => multiple_objects,
1050
- :find_all_children => find_all_children
1051
-
1052
- )
1053
-
1054
- # Type information is stored in a separate member, not in the Hash
1055
- #creation_data.delete( :type )
1056
-
1057
- child_objects.each do | child_object |
1058
-
1059
- # use cached test object if once already retrieved
1060
- get_cached_test_object!( child_object ).tap{ | found_in_cache |
1061
-
1062
- # Store/update the attributes that were used to create the child object.
1063
- child_object.creation_attributes = creation_data
1064
-
1065
- # add child to objects cache
1066
- #add_child( child_object ) unless found_in_cache
1067
-
1068
- @child_object_cache.add_object( child_object ) unless found_in_cache
1069
-
1070
- }
1071
-
1072
- end
1073
-
1074
- # return test object(s)
1075
- multiple_objects ? child_objects : child_objects.first
1076
-
1077
- rescue Exception => exception
1078
-
1079
- if exception.kind_of?( MobyBase::MultipleTestObjectsIdentifiedError )
1080
-
1081
- description = "Multiple child objects matched criteria."
1082
-
1083
- elsif exception.kind_of?( MobyBase::TestObjectNotFoundError )
1084
-
1085
- description = "The child object(s) could not be found."
1086
-
1087
- elsif exception.kind_of?( MobyBase::TestObjectNotVisibleError )
1088
-
1089
- description = "Parent test object no longer visible."
1090
-
1091
- else
1092
-
1093
- description = "Failed when trying to find child object(s)."
1094
-
1095
- end
1096
-
1097
- TDriver.logger.behaviour(
1098
-
1099
- "%s;%s;%s;%s;%s" % [ "FAIL", description, identity, multiple_objects ? "children" : "child", creation_data.inspect ]
1100
-
1101
- )
1102
-
1103
- Kernel::raise exception
1104
-
1105
- ensure
1106
-
1107
- # restore logger state
1108
- MobyUtil::Logger.instance.pop_enabled
1109
-
1110
- end
1111
-
1112
- end
1113
- =end
1114
-
1115
743
  # Creates a string identifying this test object: sut, type, attributes used when created
1116
744
  #
1117
745
  # === returns
1118
746
  # String:: String identifying this test object
1119
747
  def identity
1120
748
 
1121
- #"%s;%s;%s" % [ @sut.id, @type, @creation_attributes.inspect ]
1122
749
  "#{ @sut.id };#{ @type };#{ @creation_attributes.inspect }"
1123
750
 
1124
751
  end
@@ -1140,7 +767,7 @@ module MobyBehaviour
1140
767
  # retrieve xml data, performs xpath to sut xml_data
1141
768
  _xml_data = xml_data
1142
769
 
1143
- rescue MobyBase::TestObjectNotFoundError
770
+ rescue MobyBase::TestObjectNotFoundError
1144
771
 
1145
772
  # attributes used to refresh parent application
1146
773
  if @creation_attributes[ :type ] == 'application'
@@ -1174,9 +801,7 @@ module MobyBehaviour
1174
801
  rescue MobyBase::AttributeNotFoundError
1175
802
 
1176
803
  Kernel::raise MobyBase::AttributeNotFoundError.new(
1177
-
1178
804
  "Could not find attribute #{ name.inspect } for test object of type #{ @type.to_s }"
1179
-
1180
805
  )
1181
806
 
1182
807
  end
@@ -1211,6 +836,8 @@ module MobyBehaviour
1211
836
  # initialize cache object
1212
837
  @child_object_cache = TDriver::TestObjectCache.new
1213
838
 
839
+ @parent_application = nil
840
+
1214
841
  # defaults
1215
842
  @_application_id = nil
1216
843
  @creation_attributes = nil
@@ -1246,7 +873,7 @@ module MobyBehaviour
1246
873
  end
1247
874
 
1248
875
  # enable hooking for performance measurement & debug logging
1249
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
876
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
1250
877
 
1251
878
  end # TestObject
1252
879