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
@@ -99,12 +99,12 @@ module MobyBehaviour
99
99
 
100
100
  MobyUtil::Retryable.until( :timeout => 60, :retry_timeout => 5 ) {
101
101
  system(str_commands_after_powerup) if str_commands_after_powerup != nil
102
- if MobyUtil::Parameter[ :ats4_error_recovery_enabled, false ]!='true'
103
- MobyUtil::Logger.instance.log "behaviour" , "PASS;TDriver attempting reconnect"
102
+ if $parameters[ :ats4_error_recovery_enabled, false ]!='true'
103
+ $logger.log "behaviour", "PASS;TDriver attempting reconnect"
104
104
  self.connect(self.id)
105
- MobyUtil::Logger.instance.log "behaviour" , "PASS;TDriver connected"
105
+ $logger.log "behaviour", "PASS;TDriver connected"
106
106
  else
107
- MobyUtil::Logger.instance.log "behaviour" , "PASS;ATS4 handling reconnection"
107
+ $logger.log "behaviour", "PASS;ATS4 handling reconnection"
108
108
  end
109
109
 
110
110
  }
@@ -138,9 +138,9 @@ module MobyBehaviour
138
138
 
139
139
  #execute switchbox command
140
140
  str_command_arr.each do |foobox_command|
141
- MobyUtil::Logger.instance.log "behaviour" , "PASS;Executing powerdown command #{foobox_command}"
141
+ $logger.log "behaviour", "PASS;Executing powerdown command #{foobox_command}"
142
142
  std_out = system(foobox_command)
143
- MobyUtil::Logger.instance.log "behaviour" , "PASS;Powerdown command #{foobox_command} executed"
143
+ $logger.log "behaviour", "PASS;Powerdown command #{foobox_command} executed"
144
144
  sleep switchbox_sequence_timeout.to_i
145
145
  Kernel::raise BehaviourError.new("power_down", "Failed to power down") unless std_out.to_s.downcase.include?(str_result.to_s.downcase)
146
146
  end
@@ -175,9 +175,9 @@ module MobyBehaviour
175
175
 
176
176
  #execute switchbox command
177
177
  str_command_arr.each do |foobox_command|
178
- MobyUtil::Logger.instance.log "behaviour" , "PASS;Executing powerup command #{foobox_command}"
178
+ $logger.log "behaviour", "PASS;Executing powerup command #{foobox_command}"
179
179
  std_out = system(foobox_command)
180
- MobyUtil::Logger.instance.log "behaviour" , "PASS;Ppowerup command #{foobox_command} executed"
180
+ $logger.log "behaviour", "PASS;Ppowerup command #{foobox_command} executed"
181
181
  sleep switchbox_sequence_timeout.to_i
182
182
  Kernel::raise BehaviourError.new("power_up", "Failed to power up") unless std_out.to_s.downcase.include?(str_result.to_s.downcase)
183
183
  end
@@ -200,7 +200,7 @@ module MobyBehaviour
200
200
  end
201
201
 
202
202
  # enable hooking for performance measurement & debug logging
203
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
203
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
204
204
 
205
205
  end
206
206
 
@@ -38,111 +38,199 @@ module MobyBehaviour
38
38
  # *
39
39
  #
40
40
  # == objects
41
- # *
41
+ # *;application;sut
42
42
  #
43
- module Verification
44
-
45
- include MobyBehaviour::Behaviour
46
-
47
- # == description
48
- # Checks if a child test object matching the given criteria can be found, under this application object or test object.
49
- #
50
- # == arguments
51
- # type
52
- # String
53
- # description: String defining the type of the object
54
- # example: "Button"
55
- #
56
- # attributes
57
- # Hash
58
- # description: Optional hash containing attributes that the object must have
59
- # example: {}
60
- #
61
- # == returns
62
- # TrueClass
63
- # description: if the object exists on the sut display
64
- # example: true
65
- # FalseClass
66
- # description: if the object exists on the sut display
67
- # example: false
68
- #
69
- # == exceptions
70
- # TypeError
71
- # description: Wrong argument type %s for test object type (expected String)
72
- #
73
- # ArgumentError
74
- # description: The test object type argument must not be empty
75
- #
76
- # TypeError
77
- # description: Wrong argument type %s for test object attributes (expected Hash)
78
- def test_object_exists?(type, attributes = {} )
79
-
80
- # verify type
81
- #Kernel::raise ArgumentError.new "The type argument must be a non empty String." unless (type.kind_of? String and !type.empty?)
82
- type.check_type( String, "Wrong argument type $1 for test object type (expected $2)" )
83
-
84
- # verify that type is not empty string
85
- type.not_empty( "The test object type argument must not be empty" )
86
-
87
- # verify type
88
- #Kernel::raise ArgumentError.new "The attributes argument must be a Hash." unless attributes.kind_of?( Hash )
89
- attributes.check_type( Hash, "Wrong argument type $1 for test object attributes (expected $2)")
90
-
91
- #attributes_with_type = {}.merge attributes
92
-
93
- attributes_with_type = attributes.clone
94
- attributes_with_type[:type] = type
95
- attributes_with_type.delete(:__logging)
96
-
97
- #translate the symbol values into string using sut's localisation setting
98
- translate!( attributes_with_type )
99
-
100
- # JKo: is there some reason for the line below?
101
- #identificator = MobyBase::TestObjectIdentificator.new( attributes_with_type )
102
-
103
- original_logging = MobyUtil::Logger.instance.enabled
104
- desired_logging = (attributes[:__logging] == nil || attributes[:__logging] == 'false') ? false : true
105
- MobyUtil::Logger.instance.enabled = false
106
-
107
-
108
- begin
109
-
110
- self.child( attributes_with_type )
111
-
112
- MobyUtil::Logger.instance.enabled = desired_logging
113
- MobyUtil::Logger.instance.log "behaviour" , "PASS;Test object of type #{type} with attributes #{attributes.inspect} was found.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s : ''};test_object_exist;"
114
-
115
- rescue MobyBase::MultipleTestObjectsIdentifiedError
116
-
117
- MobyUtil::Logger.instance.enabled = desired_logging
118
- MobyUtil::Logger.instance.log "behaviour" , "PASS;Multiple objects of type #{type} with attributes #{attributes.inspect} were found.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s : ''};test_object_exist;"
119
- return true
43
+ module Verification
120
44
 
121
- rescue MobyBase::TestObjectNotFoundError
45
+ include MobyBehaviour::Behaviour
122
46
 
123
- MobyUtil::Logger.instance.enabled = desired_logging
124
- MobyUtil::Logger.instance.log "behaviour" , "FAIL;Test object of type #{type} with attributes #{attributes.inspect} was not found.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s : ''};test_object_exist;"
125
- return false
126
-
127
- rescue Exception => e
128
-
129
- MobyUtil::Logger.instance.enabled = desired_logging
130
- MobyUtil::Logger.instance.log "behaviour" , "FAIL;Test object of type #{type} with attributes #{attributes.inspect} was not found.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s : ''};test_object_exist;"
131
- Kernel::raise e
132
-
133
- ensure
134
-
135
- MobyUtil::Logger.instance.enabled = original_logging
136
-
137
- end
138
-
139
- return true
140
-
141
- end
142
-
143
- # enable hooking for performance measurement & debug logging
144
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
145
-
146
- end # module VerificationBehaviour
47
+ # == description
48
+ # Checks if a child test object matching the given criteria can be found, under this application object or test object.
49
+ #
50
+ # == arguments
51
+ # *attributes
52
+ # Hash
53
+ # description: Hash containing attributes that the object must have
54
+ # example: {}
55
+ #
56
+ # == returns
57
+ # TrueClass
58
+ # description: if the object exists on the sut display
59
+ # example: true
60
+ #
61
+ # FalseClass
62
+ # description: if the object exists on the sut display
63
+ # example: false
64
+ #
65
+ # == exceptions
66
+ # TypeError
67
+ # description: Wrong argument type %s for test object type (expected String)
68
+ #
69
+ # ArgumentError
70
+ # description: The test object type argument must not be empty
71
+ #
72
+ # ArgumentError
73
+ # description: Test object attributes hash argument must not be empty
74
+ #
75
+ # TypeError
76
+ # description: Wrong argument type %s for test object attributes (expected Hash)
77
+ def test_object_exists?( *attributes )
78
+
79
+ begin
80
+
81
+ # store original number of arguments
82
+ arguments_count = attributes.count
83
+
84
+ # verify that correct number of arguments were given
85
+ if ( 1..2 ).include?( arguments_count )
86
+
87
+ # retrieve and remove first argument from array
88
+ first = attributes.shift
89
+
90
+ if first.kind_of?( Hash )
91
+
92
+ # wrong number of arguments were given
93
+ raise ArgumentError if attributes.count > 0
94
+
95
+ # store first argument as attributes hash
96
+ attributes = first
97
+
98
+ # verify that attributes hash is not empty
99
+ attributes.not_empty( 'Test object attributes hash argument must not be empty' )
100
+
101
+ elsif first.kind_of?( String )
102
+
103
+ # print deprecated method usage warning
104
+ warn "deprecated method usage; use object#test_object_exists?( Hash ) instead of object#test_object_exists?( String, [ Hash ] )"
105
+
106
+ # verify that type is not empty string
107
+ first.not_empty( 'The test object type argument must not be empty' )
108
+
109
+ # retrieve attributes from argument; optional argument when type is kind of String
110
+ attributes = attributes.shift || {}
111
+
112
+ # verify that attributes argument type is correct (Hash)
113
+ attributes.check_type Hash, 'wrong argument type $1 for test object attributes (expected $2)'
114
+
115
+ # store test object type to attributes hash
116
+ attributes[ :type ] = first
117
+
118
+ else
119
+
120
+ # verify that first argument type is correct (Hash or String)
121
+ first.check_type Hash, 'wrong argument type $1 for test object type (expected $2)'
122
+
123
+ end
124
+
125
+ else
126
+
127
+ # wrong number of arguments were given
128
+ raise ArgumentError
129
+
130
+ end
131
+
132
+ rescue ArgumentError
133
+
134
+ # raise argument error; pass with proper description
135
+ raise ArgumentError, "wrong number of arguments (#{ arguments_count } for 1)"
136
+
137
+ end
138
+
139
+ # make clone of original attributes
140
+ attributes_clone = attributes.clone
141
+
142
+ # If empty or only special attributes then add :type => '*' to search all
143
+ attributes_clone[ :type ] = '*' if attributes_clone.select{ | key, value | key.to_s !~ /^__/ ? true : false }.empty?
144
+
145
+ # translate the symbol values into string using sut's localisation setting
146
+ @sut.translate_values!( attributes_clone )
147
+
148
+ # default result (raises exception)
149
+ result = nil
150
+
151
+ # disable logging temporarly
152
+ $logger.push_enabled( false )
153
+
154
+ begin
155
+
156
+ # raise exception if multiple objects found; call child method, disable logging and allow multiple objects
157
+ raise MobyBase::MultipleTestObjectsIdentifiedError if child( attributes_clone.merge( :__logging => false, :__multiple_objects => true ) ).count > 1
158
+
159
+ # return true as return value
160
+ result = true
161
+
162
+ # result behaviour description
163
+ description = "Test object with attributes #{ attributes.inspect } was found."
164
+
165
+ rescue Exception
166
+
167
+ case $!
168
+
169
+ when MobyBase::MultipleTestObjectsIdentifiedError
170
+
171
+ # return true as return value
172
+ result = true
173
+
174
+ # result behaviour description
175
+ description = "Multiple objects with attributes #{ attributes.inspect } were found."
176
+
177
+ when MobyBase::TestObjectNotFoundError
178
+
179
+ # return false as return value
180
+ result = false
181
+
182
+ # result behaviour description
183
+ description = "Test object with attributes #{ attributes.inspect } was not found."
184
+
185
+ else
186
+
187
+ # store exception to be raised
188
+ result = $!
189
+
190
+ # result behaviour description
191
+ description = "Test object with attributes #{ attributes.inspect } was not found due to unexpected error (#{ $!.class }: #{ $!.message.inspect })"
192
+
193
+ end
194
+
195
+ ensure
196
+
197
+ # determines that will result be logged to behaviour level
198
+ $logger.enabled = ( attributes[ :__logging ] == 'true' ? true : false )
199
+
200
+ # behaviour logging
201
+ $logger.behaviour(
202
+
203
+ "%s;%s;%s;test_object_exists?;" % [
204
+
205
+ # status
206
+ ( result == true ? 'PASS' : 'FAIL' ),
207
+
208
+ # description
209
+ description,
210
+
211
+ # sut id
212
+ ( self.kind_of?( MobyBase::SUT ) ? self.id.to_s : '' )
213
+
214
+ ]
215
+
216
+ )
217
+
218
+ # raise exception if neccessery
219
+ raise result if result.kind_of?( Exception )
220
+
221
+ # restore original logger state
222
+ $logger.pop_enabled
223
+
224
+ end
225
+
226
+ # return value
227
+ result
228
+
229
+ end
230
+
231
+ # enable hooking for performance measurement & debug logging
232
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
233
+
234
+ end # module VerificationBehaviour
147
235
 
148
236
  end # module MobyBase
@@ -212,7 +212,7 @@ module MobyCommand
212
212
  end
213
213
 
214
214
  # enable hooking for performance measurement & debug logging
215
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
215
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
216
216
 
217
217
  end # Application
218
218
 
@@ -87,7 +87,7 @@ module MobyCommand
87
87
  end
88
88
 
89
89
  # enable hooking for performance measurement & debug logging
90
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
90
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
91
91
 
92
92
  end # KeySequence
93
93
 
@@ -57,7 +57,7 @@ module MobyCommand
57
57
  end
58
58
 
59
59
  # enable hooking for performance measurement & debug logging
60
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
60
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
61
61
 
62
62
  end # ScreenCapture
63
63
 
@@ -90,7 +90,7 @@ module MobyPlugin
90
90
  end
91
91
 
92
92
  # enable hooking for performance measurement & debug logging
93
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
93
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
94
94
 
95
95
  # register plugin
96
96
  MobyUtil::PluginService.instance.register_plugin( self ) # Note: self is MobyPlugin::Generic::SUT
@@ -50,6 +50,10 @@ module MobyBase
50
50
  @input = :key
51
51
  @type = "sut"
52
52
 
53
+ @object_behaviours = []
54
+
55
+ @forced_xml = false
56
+
53
57
  end
54
58
 
55
59
  # Interface to forward command execution to sut specific controller (SutController#execute_command)
@@ -73,7 +77,7 @@ module MobyBase
73
77
  end
74
78
 
75
79
  # enable hooking for performance measurement & debug logging
76
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
80
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
77
81
 
78
82
  end # SUT
79
83
 
@@ -19,184 +19,169 @@
19
19
 
20
20
  module MobyBase
21
21
 
22
- class TestObject
23
-
24
- attr_reader(
25
- :sut, # SUT associated to test object
26
- :type, # test object type (from xml)
27
- :id, # test object id (from xml)
28
- :parent, # parent test object
29
- :name, # test object name (from xml)
30
- :x_path # xpath for test object, used when updating self with fresh ui dump
31
- )
32
-
33
- # Creation of a new TestObject requires a data object to be given to constructor
34
- # === params
35
- # factory:: TestObjectFactory used for creating test object for the sut this object is associated with
36
- # sut:: SUT object that this test object is associated with
37
- # xml_object:: REXML::Document object describing this test object
38
- # === returns
39
- # TestObject:: new TestObject instance
40
- # === raises
41
- def initialize( test_object_factory, sut, parent = nil, xml_object = nil )
42
-
43
- # Initializes a test object by assigning it a test object factory and a sut and storing xml data
44
- # describing the object.
45
- @test_object_factory = test_object_factory
46
- @parent = parent
47
- @sut = sut
48
-
49
- #self.xml_data = xml_object if xml_object
50
- method( :xml_data= ).call( xml_object ) if xml_object
51
-
52
- end
53
-
54
- # Function to verify is DATA of two TestObjects are the same,
55
- # Defined in TestObject#== other_test_object
56
- # === param
57
- # other_test_object:: TestObject other, could be null
58
- # === returns
59
- # true:: if TestObjects have same DATA
60
- # false:: if TestObjects have different DATA
61
- # === raises
62
- # nothing
63
- def eql?( other_test_object )
64
-
65
- self == other_test_object
66
-
67
- end
68
-
69
- # Function to verify is DATA of two TestObjects are the same,
70
- # return TRUE if other_test_object:
71
- # instance of MobyBase::TestObject
72
- # type's are equal
73
- # id's are equal
74
- # name's are equal
75
- # == param
76
- # other_test_object:: TestObject other, could be null
77
- # == returns
78
- # true:: if TestObjects have same DATA
79
- # false:: if TestObjects have different DATA
80
- # == raises
81
- # nothing
82
- def ==( other_test_object )
83
-
84
- #return false unless other_test_object.instance_of?( MobyBase::TestObject )
85
- #return false unless self.type == other_test_object.type
86
- #return false unless self.id == other_test_object.id
87
- #return false unless self.name == other_test_object.name
88
- #return true
89
-
90
- # optimized version
91
- other_test_object.instance_of?( MobyBase::TestObject ) &&
92
- ( @type == other_test_object.type ) &&
93
- ( @id == other_test_object.id ) &&
94
- ( @name == other_test_object.name )
95
-
96
- end
97
-
98
- # Function to calculate HASH value for a TestObject
99
- # as required by, e.g. Set
100
- #
101
- # This is required, as eql? method is being overwritten.
102
- # === returns
103
- # Fixnum:: hash number representing current TestObject
104
- def hash
105
-
106
-
107
- #result = 17
108
- #result = result * 37 + self.id.to_i
109
- #result = result * 37 + type.hash
110
- #result = result * 37 + name.hash
111
- #return result
112
-
113
- # optimized version
114
- #( ( ( 17 * 37 + @id.to_i ) * 37 + @type.hash ) * 37 + @name.hash )
22
+ class TestObject
23
+
24
+ attr_reader(
25
+ :sut, # SUT associated to test object
26
+ :type, # test object type (from xml)
27
+ :id, # test object id (from xml)
28
+ :parent, # parent test object
29
+ :name, # test object name (from xml)
30
+ :x_path # xpath for test object, used when updating self with fresh ui dump
31
+ )
32
+
33
+ # Creation of a new TestObject requires a data object to be given to constructor
34
+ # === params
35
+ # factory:: TestObjectFactory used for creating test object for the sut this object is associated with
36
+ # sut:: SUT object that this test object is associated with
37
+ # xml_object:: REXML::Document object describing this test object
38
+ # === returns
39
+ # TestObject:: new TestObject instance
40
+ # === raises
41
+ def initialize( test_object_factory, sut, parent = nil, xml_object = nil )
42
+
43
+ # Initializes a test object by assigning it a test object factory and a sut and storing xml data
44
+ # describing the object.
45
+ @test_object_factory = test_object_factory
46
+ @parent = parent
47
+ @sut = sut
48
+ @object_behaviours = []
49
+
50
+ #self.xml_data = xml_object if xml_object
51
+ method( :xml_data= ).call( xml_object ) if xml_object
52
+
53
+ end
115
54
 
116
- TDriver::TestObjectAdapter.test_object_hash( @id.to_i, @type, @name )
55
+ # Function to verify is DATA of two TestObjects are the same,
56
+ # Defined in TestObject#== test_object
57
+ # === param
58
+ # test_object:: TestObject other, could be null
59
+ # === returns
60
+ # true:: if TestObjects have same DATA
61
+ # false:: if TestObjects have different DATA
62
+ # === raises
63
+ # nothing
64
+ def eql?( test_object )
117
65
 
118
- end
66
+ self == test_object
119
67
 
120
- # Function to support sorting TestObjects within an array.
121
- # Mostly for unit testing purposes, as Set is not ordered.
122
- # should not be used normally. Thus, not documented.
123
- def <=>( other )
68
+ end
124
69
 
125
- #self_type = self.type
126
- #other_type = other.type
127
- #return -1 if self_type < other_type
128
- #return 1 if self_type > other_type
70
+ # Function to verify is DATA of two TestObjects are the same,
71
+ # return TRUE if test_object:
72
+ # instance of MobyBase::TestObject
73
+ # type's are equal
74
+ # id's are equal
75
+ # name's are equal
76
+ # == param
77
+ # test_object:: TestObject other, could be null
78
+ # == returns
79
+ # true:: if TestObjects have same DATA
80
+ # false:: if TestObjects have different DATA
81
+ # == raises
82
+ # nothing
83
+ def ==( test_object )
84
+
85
+ #return false unless test_object.instance_of?( MobyBase::TestObject )
86
+ #return false unless self.type == test_object.type
87
+ #return false unless self.id == test_object.id
88
+ #return false unless self.name == test_object.name
89
+ #return true
90
+
91
+ # optimized version
92
+ test_object.instance_of?( MobyBase::TestObject ) && ( @type == test_object.type ) && ( @id == test_object.id ) && ( @name == test_object.name )
129
93
 
130
- #self_name = self.name
131
- #other_name = other.name
132
- #return -1 if self_name < other_name
133
- #return 1 if self_name > other_name
94
+ end
134
95
 
135
- #self_id = self.id
136
- #other_id = other.id
137
- #return -1 if self_id < other_id
138
- #return 1 if self_id > other_id
96
+ # Function to calculate HASH value for a TestObject
97
+ #
98
+ # This is required, as eql? method is being overwritten.
99
+ # === returns
100
+ # Fixnum:: hash number representing current TestObject
101
+ def hash
139
102
 
140
- #0
141
103
 
142
- # optimized version
143
- ( ( result = ( @type <=> other.type ) ) == 0 ? ( ( result = ( @name <=> other.name ) ) == 0 ? @id <=> other.id : result ) : result )
104
+ #result = 17
105
+ #result = result * 37 + self.id.to_i
106
+ #result = result * 37 + type.hash
107
+ #result = result * 37 + name.hash
108
+ #return result
144
109
 
145
- end
110
+ # optimized version
111
+ #( ( ( 17 * 37 + @id.to_i ) * 37 + @type.hash ) * 37 + @name.hash )
146
112
 
147
- # Function to be renamed, possibly refactored
148
- def xml_data=( xml_object )
113
+ TDriver::TestObjectAdapter.test_object_hash( @id.to_i, @type, @name )
149
114
 
150
- =begin
151
- @name,
152
- @x_path =
153
- xml_object.attribute( 'name' ),
154
- "%s/*//object[@type='%s' and @id='%s']" % [
155
- @parent.x_path,
156
- @type = xml_object.attribute( 'type' ),
157
- @id = xml_object.attribute( 'id' )
158
- ]
159
- =end
115
+ end
160
116
 
161
- @name, @x_path = xml_object.attribute( 'name' ), "#{ @parent.x_path }/*//object[@type='#{ @type = xml_object.attribute( 'type' ) }' and @id='#{ @id = xml_object.attribute( 'id' ) }']"
117
+ # Function to support sorting TestObjects within an array.
118
+ # Mostly for unit testing purposes, as Set is not ordered.
119
+ # should not be used normally. Thus, not documented.
120
+ def <=>( test_object )
162
121
 
163
- end
122
+ #self_type = self.type
123
+ #other_type = test_object.type
124
+ #return -1 if self_type < other_type
125
+ #return 1 if self_type > other_type
164
126
 
165
- # TODO: document me
166
- def inspect
127
+ #self_name = self.name
128
+ #other_name = test_object.name
129
+ #return -1 if self_name < other_name
130
+ #return 1 if self_name > other_name
167
131
 
168
- "#<#{ self.class }:0x#{ ( "%x" % ( self.object_id.to_i << 1 ) )[ 3 .. -1 ] } @id=\"#{ @id }\" @name=\"#{ @name }\" @parent=#{ @parent.inspect } @sut=#{ @sut.inspect } @type=\"#{ @type }\" @x_path=\"#{ @x_path }\">"
132
+ #self_id = self.id
133
+ #other_id = test_object.id
134
+ #return -1 if self_id < other_id
135
+ #return 1 if self_id > other_id
136
+
137
+ #0
138
+
139
+ # optimized version
140
+ ( ( result = ( @type <=> test_object.type ) ) == 0 ? ( ( result = ( @name <=> test_object.name ) ) == 0 ? @id <=> test_object.id : result ) : result )
169
141
 
170
142
  end
171
143
 
172
- # Returns a XML node representing this test object.
173
- #
174
- # === returns
175
- # LibXML::XML::Node:: XML representation of this test object
176
- # === raises
177
- # TestObjectNotFoundError:: The test object does not exist on the SUT any longer.
178
- def xml_data()
144
+ # Function to be renamed, possibly refactored
145
+ def xml_data=( xml_object )
179
146
 
180
- #Kernel::raise MobyBase::TestObjectNotFoundError.new( 'The test object does not exist on the sut anymore.' ) if ( elements = @sut.xml_data.xpath( @x_path ) ).size.zero?
147
+ @x_path, @name, @type, @id, @env = TDriver::TestObjectAdapter.get_test_object_identifiers( xml_object, self )
181
148
 
182
- #Kernel::raise MobyBase::TestObjectNotFoundError.new( "The test object with id: \"#{ @id.to_s }\", type: \"#{ @type.to_s }\" and name: \"#{ @name.to_s }\" does not exist on sut \"#{ @sut.id.to_s }\" anymore" ) if ( elements = @sut.xml_data.xpath( @x_path ) ).size.zero?
149
+ end
183
150
 
184
- elements = @sut.xml_data.xpath( @x_path )
151
+ # Returns a XML node representing this test object.
152
+ #
153
+ # === returns
154
+ # MobyUtil::XML::Element:: XML representation of this test object
155
+ # === raises
156
+ # TestObjectNotFoundError:: The test object does not exist on the SUT any longer.
157
+ def xml_data
185
158
 
186
- Kernel::raise MobyBase::TestObjectNotFoundError.new(
159
+ begin
160
+
161
+ TDriver::TestObjectAdapter.get_xml_element_for_test_object( self )
187
162
 
188
- #'The test object (id: "%s", type: "%s", name: "%s") does not exist on sut (%s) anymore' % [ @id, @type, @name, @sut.id ]
189
- "The test object (id: #{ @id.inspect }, type: #{ @type.inspect }, name: #{ @name.inspect }) does not exist on sut (#{ @sut.id.inspect }) anymore"
163
+ rescue MobyBase::TestObjectNotFoundError
164
+
165
+ Kernel::raise MobyBase::TestObjectNotFoundError.new(
190
166
 
191
- ) if elements.size.zero?
167
+ "The test object (id: #{ @id.inspect }, type: #{ @type.inspect }, name: #{ @name.inspect }) does not exist on #{ @sut.id.inspect } anymore"
168
+
169
+ )
170
+
171
+ end
192
172
 
193
- elements.first
173
+ end
194
174
 
195
- end
175
+ # TODO: document me
176
+ def inspect
177
+
178
+ "#<#{ self.class }:0x#{ ( "%x" % ( self.object_id.to_i << 1 ) )[ 3 .. -1 ] } @id=\"#{ @id }\" @name=\"#{ @name }\" @parent=#{ @parent.inspect } @sut=#{ @sut.inspect } @type=\"#{ @type }\" @x_path=\"#{ @x_path }\">"
196
179
 
197
- # enable hooking for performance measurement & debug logging
198
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
180
+ end
181
+
182
+ # enable hooking for performance measurement & debug logging
183
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
199
184
 
200
- end # TestObject
185
+ end # TestObject
201
186
 
202
187
  end # MobyBase