testability-driver 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/tdriver-devtools +0 -0
- data/ext/native_extensions.c +165 -6
- data/lib/tdriver-devtools/behaviour/old/xml/update +0 -0
- data/lib/tdriver-devtools/behaviour/xml/generate.rb +0 -0
- data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +15 -1
- data/lib/tdriver-devtools/doc/update +0 -0
- data/lib/tdriver-devtools/doc/xslt/template.xsl +24 -14
- data/lib/tdriver-devtools/doc/xslt/update +0 -0
- data/lib/tdriver-devtools/tdriver-devtools.rb +0 -0
- data/lib/tdriver-devtools/tests/feature_tests/update +0 -0
- data/lib/tdriver/base/behaviour/{behaviour.rb → abstract.rb} +3 -6
- data/lib/tdriver/base/behaviour/behaviours/object_abstract.rb +107 -0
- data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +2 -2
- data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +47 -37
- data/lib/tdriver/base/behaviour/factory.rb +260 -382
- data/lib/tdriver/base/behaviour/loader.rb +22 -4
- data/lib/tdriver/base/controller/abstraction.rb +56 -0
- data/lib/tdriver/base/controller/loader.rb +21 -0
- data/lib/tdriver/base/loader.rb +3 -1
- data/lib/tdriver/base/sut/controller.rb +91 -74
- data/lib/tdriver/base/sut/factory.rb +8 -8
- data/lib/tdriver/base/sut/generic/behaviours/agent.rb +77 -0
- data/lib/tdriver/base/sut/generic/behaviours/sut.rb +116 -96
- data/lib/tdriver/base/sut/generic/commands/agent.rb +43 -0
- data/lib/tdriver/base/sut/sut.rb +10 -8
- data/lib/tdriver/base/test_object/abstract.rb +25 -24
- data/lib/tdriver/base/test_object/adapter.rb +67 -44
- data/lib/tdriver/base/test_object/behaviours/test_object.rb +79 -20
- data/lib/tdriver/base/test_object/factory.rb +45 -15
- data/lib/tdriver/base/test_object/xml/adapter.rb +80 -57
- data/lib/tdriver/env.rb +0 -0
- data/lib/tdriver/loader.rb +0 -0
- data/lib/tdriver/matti.rb +0 -0
- data/lib/tdriver/report/error_recovery/tdriver_error_recovery.rb +1 -0
- data/lib/tdriver/report/report.rb +2 -1
- data/lib/tdriver/report/report_crash_file_capture.rb +12 -0
- data/lib/tdriver/report/report_creator.rb +6 -2
- data/lib/tdriver/report/report_execution_statistics.rb +27 -11
- data/lib/tdriver/report/report_graph_generator.rb +59 -0
- data/lib/tdriver/report/report_test_case_run.rb +34 -2
- data/lib/tdriver/report/report_writer.rb +12 -0
- data/lib/tdriver/tdriver.rb +12 -1
- data/lib/tdriver/util/agent/loader.rb +22 -0
- data/lib/tdriver/util/agent/service.rb +107 -0
- data/lib/tdriver/util/common/crc16.rb +17 -10
- data/lib/tdriver/util/common/hash.rb +4 -1
- data/lib/tdriver/util/common/kernel.rb +11 -0
- data/lib/tdriver/util/common/numeric.rb +48 -0
- data/lib/tdriver/util/common/object.rb +5 -2
- data/lib/tdriver/util/common/string.rb +8 -1
- data/lib/tdriver/util/filters/attribute_filter.rb +121 -0
- data/lib/tdriver/util/filters/loader.rb +29 -0
- data/lib/tdriver/util/fixture/loader.rb +22 -0
- data/lib/tdriver/util/fixture/service.rb +157 -0
- data/lib/tdriver/util/loader.rb +8 -2
- data/lib/tdriver/util/logger/logger.rb +12 -6
- data/lib/tdriver/util/other/config.rb +0 -0
- data/lib/tdriver/util/parameter/parameter.rb +221 -152
- data/lib/tdriver/util/plugin/error.rb +0 -0
- data/lib/tdriver/util/video/camera_linux.rb +36 -22
- data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +3 -13
- data/lib/tdriver/util/xml/parsers/nokogiri/node.rb +13 -8
- data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +51 -9
- data/lib/tdriver/util/xml/xml.rb +4 -2
- data/lib/tdriver/verify/verify.rb +280 -621
- data/lib/tdriver/version.rb +1 -1
- data/xml/behaviours/generic.xml +34 -0
- data/xml/templates/generic.xml +20 -3
- metadata +168 -240
- data/lib/tdriver-devtools/tests/feature_tests/output/application_closable_0x3f.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/application_close.feature +0 -15
- data/lib/tdriver-devtools/tests/feature_tests/output/application_environment.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/application_executable_name.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/application_uid.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/created.rid +0 -1
- data/lib/tdriver-devtools/tests/feature_tests/output/find_find.feature +0 -15
- data/lib/tdriver-devtools/tests/feature_tests/output/flash_behaviour_flash.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/flash_behaviour_flash_images.feature +0 -15
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_application.feature +0 -15
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_capture_screen.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_child.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_clear_verify_blocks.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_connect.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_controller_execution_order.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_controller_execution_order_0x3d.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_current_application_id.feature +0 -15
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_disconnect.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_dump_count.feature +0 -15
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_freeze.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_frozen.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_get_application_id.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_get_object.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_get_operator_data.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_get_ui_dump.feature +0 -15
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_get_user_information.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_input.feature +0 -15
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_parameter.feature +0 -15
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_press_key.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_received_data.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_refresh.feature +0 -20
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_refresh_timeout.feature +0 -15
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_refresh_tries.feature +0 -15
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_refresh_ui_dump.feature +0 -20
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_run.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_sent_data.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_state.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_translate.feature +0 -30
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_ui_type.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_ui_version.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_unfreeze.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_update.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_verify_always.feature +0 -20
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_verify_blocks.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_x_path.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_xml_data.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_xml_data_0x3d.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/sut_xml_data_crc.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/switchbox_behaviour_power_down.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/switchbox_behaviour_power_status.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/switchbox_behaviour_power_up.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/switchbox_behaviour_reset.feature +0 -10
- data/lib/tdriver-devtools/tests/feature_tests/output/verification_test_object_exists_0x3f.feature +0 -15
- data/lib/tdriver/base/behaviour/factory_new.rb +0 -409
- data/lib/tdriver/base/test_object/identificator.rb +0 -518
- data/lib/tdriver/util/filters/dynamic_attributes.rb +0 -189
@@ -1,518 +0,0 @@
|
|
1
|
-
############################################################################
|
2
|
-
##
|
3
|
-
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
4
|
-
## All rights reserved.
|
5
|
-
## Contact: Nokia Corporation (testabilitydriver@nokia.com)
|
6
|
-
##
|
7
|
-
## This file is part of Testability Driver.
|
8
|
-
##
|
9
|
-
## If you have questions regarding the use of this file, please contact
|
10
|
-
## Nokia at testabilitydriver@nokia.com .
|
11
|
-
##
|
12
|
-
## This library is free software; you can redistribute it and/or
|
13
|
-
## modify it under the terms of the GNU Lesser General Public
|
14
|
-
## License version 2.1 as published by the Free Software Foundation
|
15
|
-
## and appearing in the file LICENSE.LGPL included in the packaging
|
16
|
-
## of this file.
|
17
|
-
##
|
18
|
-
############################################################################
|
19
|
-
|
20
|
-
module MobyBase
|
21
|
-
|
22
|
-
# Class to represent TestObjectIdentificator
|
23
|
-
# TestObjectIdentificator identifies TestObject representation from a TasMessage xml document.
|
24
|
-
class TestObjectIdentificator
|
25
|
-
|
26
|
-
attr_accessor :dynamic_attributes
|
27
|
-
|
28
|
-
@@required_attributes = [ :type, :id, :name, :parent ]
|
29
|
-
|
30
|
-
# special cases: allow partial match when value of :type and attribute name matches
|
31
|
-
@@partial_match_allowed = [ [ :list_item, :Text ], [ 'list_item', :Text ], [ :application, :FullName ], ['application', :FullName ] ]
|
32
|
-
|
33
|
-
# Creating new TestObjectIdentificator gets one argument as a Hash
|
34
|
-
# The hash contains rules with which xml fragments are identified within the scope.
|
35
|
-
# The scope can be either whole UI dump, or a TestObject containing child objects
|
36
|
-
#
|
37
|
-
# Usage: @test_object_identificator.new (:type => :softkey, :Text => Options)
|
38
|
-
# ==> tries to find 'softkey' TestObject, which has an attribute 'Text' with value 'Options'
|
39
|
-
# Usage: @test_object_identificator.new (:type => :list)
|
40
|
-
# ==> tries to identify the only list currently seen in the scope
|
41
|
-
#
|
42
|
-
# == params
|
43
|
-
# hash_rules:: hash containing rules to identify.
|
44
|
-
# NOTE: the hash_rule MUST contain either mapping from
|
45
|
-
# :type => <some_type> OR
|
46
|
-
# :id => <some id>
|
47
|
-
# == return
|
48
|
-
# TestObjectIdentificator:: set with specific rules
|
49
|
-
# == raises
|
50
|
-
# ArgumentError:: if hash_rules does not contain either :type or :id
|
51
|
-
def initialize( hash_rules = {} )
|
52
|
-
|
53
|
-
# Relaxing conditoins of search, no need for mandatory :name, :type or :id rule
|
54
|
-
#Kernel::raise ArgumentError.new('Cannot create a TestObjectIdentifier without :name, :type or :id rule') unless ( hash_rules.has_key?( :type ) or hash_rules.has_key?( :id ) or hash_rules.has_key?( :name ) )
|
55
|
-
|
56
|
-
# ensure that each attribute keys used for object identification are type of Symbol
|
57
|
-
@_attributes_used_to_identify_object = Hash[ hash_rules.collect{ | key, value | [ key.to_sym, value ] } ]
|
58
|
-
|
59
|
-
@dynamic_attributes = Hash[ hash_rules.select{ | key, value | key.to_s =~ /^__/ } ]
|
60
|
-
|
61
|
-
@insignificant_attributes = @@required_attributes + [ :__index ] + [ :__xy_sorting ] + [ :__fname ] + [ :__plurality ] + [ :__numerus ] + [ :__lengthvariant ]
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
# TODO: Documentation
|
66
|
-
def find_objects( from_xml_element, find_all_children )
|
67
|
-
|
68
|
-
[ from_xml_element.xpath( rule = xpath_to_identify( find_all_children ) ), rule ]
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
# getter to return the rules used in identification
|
73
|
-
# == returns
|
74
|
-
# Hash:: Hash object containing the rules
|
75
|
-
def get_identification_rules
|
76
|
-
|
77
|
-
@_attributes_used_to_identify_object
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
# Sort XML nodeset of test objects with layout direction
|
82
|
-
def sort_elements_by_xy_layout!( nodeset, layout_direction = "LeftToRight" )
|
83
|
-
|
84
|
-
attribute_pattern = "./attributes/attribute[@name='%s']/value/text()"
|
85
|
-
|
86
|
-
# collect only nodes that has x_absolute and y_absolute attributes
|
87
|
-
nodeset.collect!{ | node |
|
88
|
-
|
89
|
-
node unless node.at_xpath( attribute_pattern % 'x_absolute' ).to_s.empty? || node.at_xpath( attribute_pattern % 'y_absolute' ).to_s.empty?
|
90
|
-
|
91
|
-
}.compact!.sort!{ | element_a, element_b |
|
92
|
-
|
93
|
-
element_a_x = element_a.at_xpath( attribute_pattern % 'x_absolute' ).content.to_i
|
94
|
-
element_a_y = element_a.at_xpath( attribute_pattern % 'y_absolute' ).content.to_i
|
95
|
-
|
96
|
-
element_b_x = element_b.at_xpath( attribute_pattern % 'x_absolute' ).content.to_i
|
97
|
-
element_b_y = element_b.at_xpath( attribute_pattern % 'y_absolute' ).content.to_i
|
98
|
-
|
99
|
-
if ( layout_direction =~ /LeftToRight/i )
|
100
|
-
|
101
|
-
( element_a_y == element_b_y ) ? ( element_a_x <=> element_b_x ) : ( element_a_y <=> element_b_y )
|
102
|
-
|
103
|
-
elsif ( layout_direction =~ /RightToLeft/i )
|
104
|
-
|
105
|
-
( element_a_y == element_b_y ) ? ( element_b_x <=> element_a_x ) : ( element_a_y <=> element_b_y )
|
106
|
-
|
107
|
-
else
|
108
|
-
|
109
|
-
Kernel::raise ArgumentError.new( "Unexpected layout direction: %s" % layout_direction )
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
}
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
private
|
118
|
-
|
119
|
-
|
120
|
-
# function create x_path that included required attributes type, id and/or name
|
121
|
-
# == returns
|
122
|
-
# String:: x_path containing required attributes
|
123
|
-
def create_xpath_from_required_attributes
|
124
|
-
|
125
|
-
return "@*" if @_attributes_used_to_identify_object[ :type ].to_s == "any"
|
126
|
-
|
127
|
-
xpath = ""
|
128
|
-
|
129
|
-
pattern = "@%s=%s or attributes/attribute[translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=%s]/value=%s"
|
130
|
-
|
131
|
-
@_attributes_used_to_identify_object.each_pair{ | attribute_name, attribute_value |
|
132
|
-
|
133
|
-
next unless @@required_attributes.include?( attribute_name )
|
134
|
-
|
135
|
-
xpath << ' and ' unless xpath.empty?
|
136
|
-
|
137
|
-
xpath << '('
|
138
|
-
|
139
|
-
if attribute_value.kind_of?( Array )
|
140
|
-
|
141
|
-
# multiple (optional) attributes for object identification
|
142
|
-
attribute_value.each_with_index{ | attribute_value_option, index |
|
143
|
-
|
144
|
-
xpath << ' or ' unless index.zero?
|
145
|
-
|
146
|
-
a_v_o = convertToXPathLiteral( attribute_value_option )
|
147
|
-
|
148
|
-
xpath << pattern % [
|
149
|
-
attribute_name,
|
150
|
-
a_v_o,
|
151
|
-
convertToXPathLiteral( attribute_name.to_s.downcase),
|
152
|
-
a_v_o
|
153
|
-
]
|
154
|
-
|
155
|
-
}
|
156
|
-
|
157
|
-
else
|
158
|
-
|
159
|
-
a_v = convertToXPathLiteral( attribute_value )
|
160
|
-
|
161
|
-
# one attribute used for object identification
|
162
|
-
xpath << "%s" % [
|
163
|
-
pattern % [
|
164
|
-
attribute_name,
|
165
|
-
a_v,
|
166
|
-
convertToXPathLiteral( attribute_name.to_s.downcase),
|
167
|
-
a_v
|
168
|
-
]
|
169
|
-
]
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
|
-
xpath << ')'
|
174
|
-
|
175
|
-
}
|
176
|
-
|
177
|
-
xpath
|
178
|
-
|
179
|
-
end
|
180
|
-
|
181
|
-
# Private function to define rule for a given MobyUtil::XML::Element element.
|
182
|
-
# Uses xml_elements namespace in the rule.
|
183
|
-
# Uses private instance variable to define the actual rule. Instance variable is set in constructor
|
184
|
-
# == params
|
185
|
-
# xml_element:: MobyUtil::XML::Element element frow which objects are being identified
|
186
|
-
# == returns
|
187
|
-
# Array (<String>, Array(<String>) ):: returns array of two element as defined below
|
188
|
-
# String:: Rule to be used in xpath
|
189
|
-
def xpath_to_identify( get_all_children = true )
|
190
|
-
|
191
|
-
xpath = create_xpath_from_required_attributes
|
192
|
-
|
193
|
-
pattern = "attributes/attribute[translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=%s]/"
|
194
|
-
|
195
|
-
@_attributes_used_to_identify_object.each_pair do | attribute_key, attribute_value |
|
196
|
-
|
197
|
-
# Relaxing conditions, no need for mandatory :name, :type, :parent, :id or :__index. See class instance constructor.
|
198
|
-
next if @insignificant_attributes.include?( attribute_key )
|
199
|
-
|
200
|
-
xpath << ' and ' unless xpath.empty?
|
201
|
-
|
202
|
-
xpath << pattern % convertToXPathLiteral( attribute_key.to_s.downcase )
|
203
|
-
|
204
|
-
# convert single value to array, due to value can contain multiple values and no use to have duplicate code for processing
|
205
|
-
attribute_value = [ attribute_value ] unless attribute_value.kind_of?( Array )
|
206
|
-
|
207
|
-
attribute_value.each_with_index do | value, index |
|
208
|
-
|
209
|
-
xpath << " or " unless index.zero?
|
210
|
-
|
211
|
-
# allow partial match when value of :type and attribute name matches. see class instance constructor.
|
212
|
-
if @@partial_match_allowed.include?( [ @_attributes_used_to_identify_object[ :type ], attribute_key ] )
|
213
|
-
|
214
|
-
xpath << "value[contains(.,%s)]" % convertToXPathLiteral( value )
|
215
|
-
|
216
|
-
else
|
217
|
-
|
218
|
-
xpath << "value=%s" % convertToXPathLiteral( value )
|
219
|
-
|
220
|
-
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
end
|
225
|
-
|
226
|
-
( get_all_children ? "*//object[%s]" : "objects[1]/object[%s]" ) % xpath
|
227
|
-
|
228
|
-
end
|
229
|
-
|
230
|
-
# TODO: This method needs to refactored
|
231
|
-
# function to deal with case where string literals in XPath expressions contains single or double quotes
|
232
|
-
# If string literal value contain only one type - double or single, then delimit with the other.
|
233
|
-
# E.g. "'" or '"'
|
234
|
-
# If value contains both then you can not do it directly in a string literal but need to construct the string using
|
235
|
-
# concat("'",'"')
|
236
|
-
def convertToXPathLiteral( value )
|
237
|
-
|
238
|
-
# convert to string if needed
|
239
|
-
value_string = value.kind_of?( String ) ? value : value.to_s
|
240
|
-
|
241
|
-
if !value_string.include?("\'")
|
242
|
-
|
243
|
-
# return value
|
244
|
-
"\'%s\'" % value_string
|
245
|
-
|
246
|
-
elsif !value_string.include?("\"")
|
247
|
-
|
248
|
-
# return value
|
249
|
-
"\"%s\"" % value_string
|
250
|
-
|
251
|
-
else
|
252
|
-
|
253
|
-
result = ""
|
254
|
-
|
255
|
-
substrings = value_string.split( "\"" )
|
256
|
-
|
257
|
-
substrings.each_with_index do | s, i |
|
258
|
-
|
259
|
-
needComma = true if i > 0
|
260
|
-
|
261
|
-
unless s.empty?
|
262
|
-
|
263
|
-
result << ", " if i > 0
|
264
|
-
|
265
|
-
result << "\"%s\"" % s
|
266
|
-
|
267
|
-
needComma = true
|
268
|
-
|
269
|
-
end
|
270
|
-
|
271
|
-
# other than last one
|
272
|
-
if i < substrings.length - 1
|
273
|
-
|
274
|
-
result << ", " if needComma
|
275
|
-
|
276
|
-
result << "'\"'"
|
277
|
-
|
278
|
-
end
|
279
|
-
|
280
|
-
end
|
281
|
-
|
282
|
-
# return value
|
283
|
-
"concat(%s)" % result
|
284
|
-
|
285
|
-
end
|
286
|
-
|
287
|
-
end
|
288
|
-
|
289
|
-
public # deprecated
|
290
|
-
|
291
|
-
# function create x_path that included required attributes type, id and/or name
|
292
|
-
# == returns
|
293
|
-
# String:: x_path containing required attributes
|
294
|
-
def create_x_path_from_required_attributes
|
295
|
-
|
296
|
-
return "@*" if @_attributes_used_to_identify_object[ :type ].to_s == "any"
|
297
|
-
|
298
|
-
xpath = ""
|
299
|
-
|
300
|
-
pattern = "@%s=%s or attributes/attribute[translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=%s]/value=%s"
|
301
|
-
|
302
|
-
@_attributes_used_to_identify_object.each_pair{ | attribute_name, attribute_value |
|
303
|
-
|
304
|
-
next unless @@required_attributes.include?( attribute_name )
|
305
|
-
|
306
|
-
xpath << ' and ' unless xpath.empty?
|
307
|
-
|
308
|
-
xpath << '('
|
309
|
-
|
310
|
-
if attribute_value.kind_of?( Array )
|
311
|
-
|
312
|
-
# multiple (optional) attributes for object identification
|
313
|
-
attribute_value.each_with_index{ | attribute_value_option, index |
|
314
|
-
|
315
|
-
xpath << ' or ' unless index.zero?
|
316
|
-
|
317
|
-
xpath << pattern % [
|
318
|
-
attribute_name,
|
319
|
-
convertToXPathLiteral( attribute_value_option),
|
320
|
-
convertToXPathLiteral( attribute_name.to_s.downcase),
|
321
|
-
convertToXPathLiteral( attribute_value_option)
|
322
|
-
]
|
323
|
-
|
324
|
-
}
|
325
|
-
|
326
|
-
else
|
327
|
-
|
328
|
-
# one attribute used for object identification
|
329
|
-
xpath << "%s" % [
|
330
|
-
pattern % [
|
331
|
-
attribute_name,
|
332
|
-
convertToXPathLiteral( attribute_value),
|
333
|
-
convertToXPathLiteral( attribute_name.to_s.downcase),
|
334
|
-
convertToXPathLiteral( attribute_value)
|
335
|
-
]
|
336
|
-
]
|
337
|
-
|
338
|
-
end
|
339
|
-
|
340
|
-
xpath << ')'
|
341
|
-
|
342
|
-
}
|
343
|
-
|
344
|
-
xpath
|
345
|
-
|
346
|
-
end
|
347
|
-
|
348
|
-
# Private function to define rule for a given MobyUtil::XML::Element element.
|
349
|
-
# Uses xml_elements namespace in the rule.
|
350
|
-
# Uses private instance variable to define the actual rule. Instance variable is set in constructor
|
351
|
-
# == params
|
352
|
-
# xml_element:: MobyUtil::XML::Element element frow which objects are being identified
|
353
|
-
# == returns
|
354
|
-
# Array (<String>, Array(<String>) ):: returns array of two element as defined below
|
355
|
-
# String:: Rule to be used in xpath
|
356
|
-
def get_xpath_to_identify( from_xml_element, namespace = nil, get_all_children= true )
|
357
|
-
|
358
|
-
xpath = create_x_path_from_required_attributes
|
359
|
-
pattern = "attributes/attribute[translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=%s]/"
|
360
|
-
|
361
|
-
@_attributes_used_to_identify_object.each_pair do | attribute_key, attribute_value |
|
362
|
-
|
363
|
-
# Relaxing conditions, no need for mandatory :name, :type, :parent, :id or :__index. See class instance constructor.
|
364
|
-
next if @insignificant_attributes.include?( attribute_key )
|
365
|
-
|
366
|
-
xpath << ' and ' unless xpath.empty?
|
367
|
-
|
368
|
-
xpath << pattern % convertToXPathLiteral( attribute_key.to_s.downcase )
|
369
|
-
|
370
|
-
# convert single value to array, due to value can contain multiple values and no use to have duplicate code for processing
|
371
|
-
attribute_value = [ attribute_value ] unless attribute_value.kind_of?( Array )
|
372
|
-
|
373
|
-
attribute_value.each_with_index do | value, index |
|
374
|
-
|
375
|
-
xpath << " or " unless index.zero?
|
376
|
-
|
377
|
-
# allow partial match when value of :type and attribute name matches. see class instance constructor.
|
378
|
-
if @@partial_match_allowed.include?( [ @_attributes_used_to_identify_object[ :type ], attribute_key ] )
|
379
|
-
|
380
|
-
xpath << "value[contains(.,%s)]" % convertToXPathLiteral( value )
|
381
|
-
|
382
|
-
else
|
383
|
-
|
384
|
-
xpath << "value=%s" % convertToXPathLiteral( value )
|
385
|
-
|
386
|
-
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
end
|
391
|
-
|
392
|
-
( get_all_children ? "*//object[%s]" : "objects[1]/object[%s]" ) % xpath
|
393
|
-
|
394
|
-
end
|
395
|
-
|
396
|
-
=begin
|
397
|
-
## Returns array of element nodes
|
398
|
-
def sort_elements_by_xy_layout( element_set, layout_direction = "LeftToRight" )
|
399
|
-
|
400
|
-
# MobyUtil::XML::NodeSet and Elements
|
401
|
-
# Take out all test_objects with no x_absolute or y_absolute
|
402
|
-
to_delete = []
|
403
|
-
element_set.each do |node|
|
404
|
-
begin
|
405
|
-
node.xpath("./attributes/attribute[@name = 'x_absolute']/value").first.content
|
406
|
-
node.xpath("./attributes/attribute[@name = 'y_absolute']/value").first.content
|
407
|
-
rescue
|
408
|
-
to_delete << node
|
409
|
-
end
|
410
|
-
end
|
411
|
-
to_delete.each do |node|
|
412
|
-
element_set.delete(node)
|
413
|
-
end
|
414
|
-
# Sort remaining by layout direction and up to down
|
415
|
-
# Requires .to_a to return an array of MobyUtil::XML::Elements
|
416
|
-
element_set.to_a.sort!{ |a, b|
|
417
|
-
element_a_x = a.xpath("./attributes/attribute[@name = 'x_absolute']/value").first.content.to_i
|
418
|
-
element_a_y = a.xpath("./attributes/attribute[@name = 'y_absolute']/value").first.content.to_i
|
419
|
-
element_b_x = b.xpath("./attributes/attribute[@name = 'x_absolute']/value").first.content.to_i
|
420
|
-
element_b_y = b.xpath("./attributes/attribute[@name = 'y_absolute']/value").first.content.to_i
|
421
|
-
if ( layout_direction.downcase == "LeftToRight".downcase )
|
422
|
-
( element_a_y == element_b_y ) ? ( element_a_x <=> element_b_x ) : ( element_a_y <=> element_b_y )
|
423
|
-
elsif ( layout_direction.downcase == "RightToLeft".downcase )
|
424
|
-
( element_a_y == element_b_y ) ? ( element_b_x <=> element_a_x ) : ( element_a_y <=> element_b_y )
|
425
|
-
else
|
426
|
-
Kernel::raise ArgumentError.new("Unexpected layout direction: " + layout_direction)
|
427
|
-
end
|
428
|
-
}
|
429
|
-
end
|
430
|
-
=end
|
431
|
-
|
432
|
-
# Function to identify an object from tasMessage xml content
|
433
|
-
#
|
434
|
-
# == params
|
435
|
-
# from_xml_element: MobyUtil::XML::Element XML element for TestObject object containing the information from which a child test object is to be identified
|
436
|
-
# == return
|
437
|
-
# MobyUtil::XML::Element:: found XML fragment, if any
|
438
|
-
# == raise
|
439
|
-
# MultipleTestObjectsIdentifiedError:: if multiple test objects are identified
|
440
|
-
# TestObjectNotFoundError:: if no TestObject can be identified
|
441
|
-
# ArgumentError:: if 'from_xml_element' is not of type MobyUtil::XML::Element
|
442
|
-
def find_object_data( from_xml_element, layout_direction = nil )
|
443
|
-
|
444
|
-
from_xml_element.check_type( MobyUtil::XML::Element, "Wrong argument type $1 for XML element (expected $2)" )
|
445
|
-
|
446
|
-
#Kernel::raise ArgumentError.new( "Wrong argument type %s for argument 'xml_element' (expected MobyUtil::XML::Element)" % from_xml_element.class ) unless from_xml_element.kind_of?( MobyUtil::XML::Element )
|
447
|
-
|
448
|
-
xpath = get_xpath_to_identify( from_xml_element )
|
449
|
-
|
450
|
-
element_set = from_xml_element.xpath( xpath )
|
451
|
-
|
452
|
-
if @_attributes_used_to_identify_object[ :__xy_sorting ] == "true"
|
453
|
-
begin
|
454
|
-
#layout_direction = parent_test_object.sut.application( :id => parent_test_object.get_application_id ).attribute("layoutDirection")
|
455
|
-
element_set = sort_elements_by_xy_layout( element_set, layout_direction )
|
456
|
-
rescue MobyBase::AttributeNotFoundError
|
457
|
-
element_set = sort_elements_by_xy_layout( element_set)
|
458
|
-
end
|
459
|
-
end
|
460
|
-
|
461
|
-
ret, size = ( (size = element_set.size).zero? ) ? [ nil, 0 ] : [ element_set[ ( ( index = @_attributes_used_to_identify_object[ :__index ] ) || 0 ).to_i ], ( index.nil? ? size : 1 ) ]
|
462
|
-
|
463
|
-
Kernel::raise MobyBase::MultipleTestObjectsIdentifiedError.new( "Multiple test objects found with rule:\n#{ xpath }" ) if ( size > 1 )
|
464
|
-
|
465
|
-
Kernel::raise MobyBase::TestObjectNotFoundError.new( "Cannot find object with rule:\n%s" % [ xpath ] ) if ( size.zero? || ret.nil? )
|
466
|
-
|
467
|
-
ret
|
468
|
-
|
469
|
-
end
|
470
|
-
|
471
|
-
# Function to identify all object from tasMessage xml content
|
472
|
-
#
|
473
|
-
# == params
|
474
|
-
# from_xml_element: MobyUtil::XML::Element XML element for TestObject object containing the information from which a children test object is to be identified
|
475
|
-
# find_all_children:: Boolean specifying whether all children under the test node or just immediate children should be retreived.
|
476
|
-
# == return
|
477
|
-
# MobyUtil::XML::Element:: found XML fragment, if any
|
478
|
-
# == raise
|
479
|
-
# TestObjectNotFoundError:: if no TestObject can be identified
|
480
|
-
# ArgumentError:: if 'from_xml_element' is not of type MobyUtil::XML::Element
|
481
|
-
def find_multiple_object_data( from_xml_element, find_all_children, layout_direction = nil )
|
482
|
-
|
483
|
-
from_xml_element.check_type( MobyUtil::XML::Element, "Wrong argument type $1 for XML element (expected $2)" )
|
484
|
-
|
485
|
-
#Kernel::raise ArgumentError.new( "Wrong argument type %s for argument 'xml_element' (expected MobyUtil::XML::Element)" % from_xml_element.class ) unless from_xml_element.kind_of?( MobyUtil::XML::Element )
|
486
|
-
|
487
|
-
element_set = from_xml_element.xpath( xpath = get_xpath_to_identify( from_xml_element ,nil,find_all_children) )
|
488
|
-
ret = Array.new
|
489
|
-
|
490
|
-
if @_attributes_used_to_identify_object[ :__xy_sorting ] == "true"
|
491
|
-
begin
|
492
|
-
#layout_direction = parent_test_object.sut.application( :id => parent_test_object.get_application_id ).attribute("layoutDirection")
|
493
|
-
element_set = sort_elements_by_xy_layout( element_set, layout_direction )
|
494
|
-
rescue MobyBase::AttributeNotFoundError
|
495
|
-
element_set = sort_elements_by_xy_layout( element_set)
|
496
|
-
end
|
497
|
-
end
|
498
|
-
|
499
|
-
if @_attributes_used_to_identify_object.has_key?( :__index ) && element_set.size > 1
|
500
|
-
ret << element_set[ @_attributes_used_to_identify_object[ :__index ].to_i ]
|
501
|
-
size = 1
|
502
|
-
else
|
503
|
-
ret = element_set
|
504
|
-
size = element_set.size
|
505
|
-
end
|
506
|
-
|
507
|
-
Kernel::raise MobyBase::TestObjectNotFoundError.new( "Cannot find object with rule:\n#{ xpath }" ) if ( size == 0 or ret == nil)
|
508
|
-
|
509
|
-
ret
|
510
|
-
|
511
|
-
end
|
512
|
-
|
513
|
-
# enable hooking for performance measurement & debug logging
|
514
|
-
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
515
|
-
|
516
|
-
end # TestObjectIdentificator
|
517
|
-
|
518
|
-
end # MobyBase
|