cutedriver-driver 2.0.0.20210120164037

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +16 -0
  3. data/bin/start_app_perf +200 -0
  4. data/bin/tdriver-devtools +3 -0
  5. data/config/sut_parameters.rb +52 -0
  6. data/config/sut_setup.rb +32 -0
  7. data/config/sut_teardown.rb +32 -0
  8. data/config/tdriver_custom_error_recovery.rb +83 -0
  9. data/ext/extconf.rb +70 -0
  10. data/ext/native_extensions.c +315 -0
  11. data/lib/matti.rb +25 -0
  12. data/lib/tdriver-devtools/behaviour/old/xml/example/flick-example.rb +120 -0
  13. data/lib/tdriver-devtools/behaviour/old/xml/example/impl.rb_invalid +194 -0
  14. data/lib/tdriver-devtools/behaviour/old/xml/generate_behaviour_xml.rb +95 -0
  15. data/lib/tdriver-devtools/behaviour/old/xml/lib/tdriver_generator.rb +722 -0
  16. data/lib/tdriver-devtools/behaviour/old/xml/qdoc_generator.rb +321 -0
  17. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.method.template +43 -0
  18. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.module.template +54 -0
  19. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.argument.template +7 -0
  20. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.argument_type.template +7 -0
  21. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.exception.template +5 -0
  22. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.howto.line.template +2 -0
  23. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.howto.template +5 -0
  24. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.method.template +23 -0
  25. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.template +14 -0
  26. data/lib/tdriver-devtools/behaviour/old/xml/update +3 -0
  27. data/lib/tdriver-devtools/behaviour/xml/generate.rb +88 -0
  28. data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +1945 -0
  29. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument.default.template +1 -0
  30. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument.template +3 -0
  31. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument_type.template +4 -0
  32. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.exception.template +4 -0
  33. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.arguments.template +4 -0
  34. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.deprecated.template +3 -0
  35. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.exceptions.template +3 -0
  36. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.info.template +1 -0
  37. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.returns.template +3 -0
  38. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.tables.template +3 -0
  39. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.template +12 -0
  40. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.returns.template +5 -0
  41. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.item.template +1 -0
  42. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.row.template +2 -0
  43. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.template +8 -0
  44. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.template +14 -0
  45. data/lib/tdriver-devtools/doc/behaviour_xml/QtExampleGestureBehaviour.xml +138 -0
  46. data/lib/tdriver-devtools/doc/behaviour_xml/created.rid +1 -0
  47. data/lib/tdriver-devtools/doc/behaviour_xml/tdriver.hash +1 -0
  48. data/lib/tdriver-devtools/doc/feature_xml/qt_widget_hold.feature.xml +9 -0
  49. data/lib/tdriver-devtools/doc/feature_xml/qt_widget_tap.feature.xml +9 -0
  50. data/lib/tdriver-devtools/doc/generate.rb +917 -0
  51. data/lib/tdriver-devtools/doc/update +1 -0
  52. data/lib/tdriver-devtools/doc/xslt/html.rb +7 -0
  53. data/lib/tdriver-devtools/doc/xslt/template.xsl +2170 -0
  54. data/lib/tdriver-devtools/doc/xslt/update +3 -0
  55. data/lib/tdriver-devtools/plugin/placeholder.txt +1 -0
  56. data/lib/tdriver-devtools/tdriver-devtools.rb +404 -0
  57. data/lib/tdriver-devtools/tests/feature_tests/example/behaviour_example.rb +100 -0
  58. data/lib/tdriver-devtools/tests/feature_tests/generate.rb +82 -0
  59. data/lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb +468 -0
  60. data/lib/tdriver-devtools/tests/feature_tests/templates/feature_attribute.template +5 -0
  61. data/lib/tdriver-devtools/tests/feature_tests/templates/feature_method.template +5 -0
  62. data/lib/tdriver-devtools/tests/feature_tests/templates/scenario_attribute.template +5 -0
  63. data/lib/tdriver-devtools/tests/feature_tests/templates/scenario_method.template +5 -0
  64. data/lib/tdriver-devtools/tests/feature_tests/update +3 -0
  65. data/lib/tdriver.rb +23 -0
  66. data/lib/tdriver/base/behaviour/abstract.rb +29 -0
  67. data/lib/tdriver/base/behaviour/behaviours/object_abstract.rb +107 -0
  68. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +99 -0
  69. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +278 -0
  70. data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +119 -0
  71. data/lib/tdriver/base/behaviour/factory.rb +495 -0
  72. data/lib/tdriver/base/behaviour/loader.rb +46 -0
  73. data/lib/tdriver/base/command_data/command_data.rb +51 -0
  74. data/lib/tdriver/base/command_data/loader.rb +29 -0
  75. data/lib/tdriver/base/controller/abstraction.rb +56 -0
  76. data/lib/tdriver/base/controller/loader.rb +21 -0
  77. data/lib/tdriver/base/errors.rb +134 -0
  78. data/lib/tdriver/base/loader.rb +47 -0
  79. data/lib/tdriver/base/state_object.rb +373 -0
  80. data/lib/tdriver/base/sut/adapter.rb +54 -0
  81. data/lib/tdriver/base/sut/controller.rb +151 -0
  82. data/lib/tdriver/base/sut/factory.rb +339 -0
  83. data/lib/tdriver/base/sut/generic/behaviours/agent.rb +77 -0
  84. data/lib/tdriver/base/sut/generic/behaviours/application.rb +427 -0
  85. data/lib/tdriver/base/sut/generic/behaviours/controller.rb +67 -0
  86. data/lib/tdriver/base/sut/generic/behaviours/find.rb +107 -0
  87. data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +337 -0
  88. data/lib/tdriver/base/sut/generic/behaviours/sut.rb +1888 -0
  89. data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +210 -0
  90. data/lib/tdriver/base/sut/generic/behaviours/verification.rb +222 -0
  91. data/lib/tdriver/base/sut/generic/commands/agent.rb +43 -0
  92. data/lib/tdriver/base/sut/generic/commands/application.rb +274 -0
  93. data/lib/tdriver/base/sut/generic/commands/fixture.rb +47 -0
  94. data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +94 -0
  95. data/lib/tdriver/base/sut/generic/commands/screen_capture.rb +64 -0
  96. data/lib/tdriver/base/sut/generic/plugin.rb +97 -0
  97. data/lib/tdriver/base/sut/loader.rb +35 -0
  98. data/lib/tdriver/base/sut/sut.rb +98 -0
  99. data/lib/tdriver/base/test_object/abstract.rb +208 -0
  100. data/lib/tdriver/base/test_object/adapter.rb +740 -0
  101. data/lib/tdriver/base/test_object/behaviours/syncronization.rb +144 -0
  102. data/lib/tdriver/base/test_object/behaviours/test_object.rb +1047 -0
  103. data/lib/tdriver/base/test_object/cache.rb +134 -0
  104. data/lib/tdriver/base/test_object/factory.rb +684 -0
  105. data/lib/tdriver/base/test_object/loader.rb +51 -0
  106. data/lib/tdriver/base/test_object/verification.rb +178 -0
  107. data/lib/tdriver/base/test_object/xml/abstraction.rb +63 -0
  108. data/lib/tdriver/base/test_object/xml/adapter.rb +773 -0
  109. data/lib/tdriver/env.rb +21 -0
  110. data/lib/tdriver/loader.rb +57 -0
  111. data/lib/tdriver/matti.rb +35 -0
  112. data/lib/tdriver/report/error_recovery/tdriver_custom_error_recovery.rb +83 -0
  113. data/lib/tdriver/report/error_recovery/tdriver_error_recovery.rb +168 -0
  114. data/lib/tdriver/report/error_recovery/tdriver_error_recovery_settings.rb +106 -0
  115. data/lib/tdriver/report/report.rb +61 -0
  116. data/lib/tdriver/report/report_api.rb +348 -0
  117. data/lib/tdriver/report/report_combine.rb +86 -0
  118. data/lib/tdriver/report/report_crash_file_capture.rb +178 -0
  119. data/lib/tdriver/report/report_creator.rb +665 -0
  120. data/lib/tdriver/report/report_cucumber.rb +158 -0
  121. data/lib/tdriver/report/report_cucumber_listener.rb +184 -0
  122. data/lib/tdriver/report/report_cucumber_reporter.rb +181 -0
  123. data/lib/tdriver/report/report_data_presentation.rb +156 -0
  124. data/lib/tdriver/report/report_data_table.rb +64 -0
  125. data/lib/tdriver/report/report_execution_statistics.rb +400 -0
  126. data/lib/tdriver/report/report_file_capture.rb +159 -0
  127. data/lib/tdriver/report/report_graph_generator.rb +59 -0
  128. data/lib/tdriver/report/report_grouping.rb +541 -0
  129. data/lib/tdriver/report/report_javascript.rb +199 -0
  130. data/lib/tdriver/report/report_junit_xml.rb +147 -0
  131. data/lib/tdriver/report/report_rspec.rb +108 -0
  132. data/lib/tdriver/report/report_test_case_run.rb +725 -0
  133. data/lib/tdriver/report/report_test_run.rb +1476 -0
  134. data/lib/tdriver/report/report_test_unit.rb +223 -0
  135. data/lib/tdriver/report/report_writer.rb +1621 -0
  136. data/lib/tdriver/tdriver.rb +209 -0
  137. data/lib/tdriver/util/agent/loader.rb +22 -0
  138. data/lib/tdriver/util/agent/service.rb +107 -0
  139. data/lib/tdriver/util/common/array.rb +39 -0
  140. data/lib/tdriver/util/common/boolean.rb +48 -0
  141. data/lib/tdriver/util/common/crc16.rb +149 -0
  142. data/lib/tdriver/util/common/environment.rb +154 -0
  143. data/lib/tdriver/util/common/error.rb +40 -0
  144. data/lib/tdriver/util/common/exception.rb +53 -0
  145. data/lib/tdriver/util/common/exceptions.rb +12 -0
  146. data/lib/tdriver/util/common/file.rb +328 -0
  147. data/lib/tdriver/util/common/gem.rb +109 -0
  148. data/lib/tdriver/util/common/hash.rb +288 -0
  149. data/lib/tdriver/util/common/kernel.rb +253 -0
  150. data/lib/tdriver/util/common/loader.rb +47 -0
  151. data/lib/tdriver/util/common/numeric.rb +159 -0
  152. data/lib/tdriver/util/common/object.rb +159 -0
  153. data/lib/tdriver/util/common/retryable.rb +179 -0
  154. data/lib/tdriver/util/common/stackable.rb +185 -0
  155. data/lib/tdriver/util/common/string.rb +174 -0
  156. data/lib/tdriver/util/database/access.rb +240 -0
  157. data/lib/tdriver/util/database/connection.rb +44 -0
  158. data/lib/tdriver/util/database/error.rb +34 -0
  159. data/lib/tdriver/util/database/loader.rb +28 -0
  160. data/lib/tdriver/util/filters/attribute_filter.rb +121 -0
  161. data/lib/tdriver/util/filters/loader.rb +29 -0
  162. data/lib/tdriver/util/fixture/loader.rb +22 -0
  163. data/lib/tdriver/util/fixture/service.rb +211 -0
  164. data/lib/tdriver/util/hooking/hooking.rb +477 -0
  165. data/lib/tdriver/util/keymap/keymap.rb +81 -0
  166. data/lib/tdriver/util/loader.rb +80 -0
  167. data/lib/tdriver/util/localisation/error.rb +31 -0
  168. data/lib/tdriver/util/localisation/loader.rb +25 -0
  169. data/lib/tdriver/util/localisation/localisation.rb +762 -0
  170. data/lib/tdriver/util/logger/loader.rb +22 -0
  171. data/lib/tdriver/util/logger/logger.rb +591 -0
  172. data/lib/tdriver/util/operator_data/error.rb +29 -0
  173. data/lib/tdriver/util/operator_data/loader.rb +27 -0
  174. data/lib/tdriver/util/operator_data/operator_data.rb +93 -0
  175. data/lib/tdriver/util/other/config.rb +221 -0
  176. data/lib/tdriver/util/parameter/error.rb +48 -0
  177. data/lib/tdriver/util/parameter/loader.rb +25 -0
  178. data/lib/tdriver/util/parameter/parameter.rb +1161 -0
  179. data/lib/tdriver/util/plugin/abstract.rb +61 -0
  180. data/lib/tdriver/util/plugin/error.rb +0 -0
  181. data/lib/tdriver/util/plugin/loader.rb +28 -0
  182. data/lib/tdriver/util/plugin/service.rb +319 -0
  183. data/lib/tdriver/util/recorder/loader.rb +25 -0
  184. data/lib/tdriver/util/recorder/recorder.rb +72 -0
  185. data/lib/tdriver/util/recorder/scripter.rb +294 -0
  186. data/lib/tdriver/util/statistics/statistics.rb +89 -0
  187. data/lib/tdriver/util/user_data/error.rb +28 -0
  188. data/lib/tdriver/util/user_data/loader.rb +25 -0
  189. data/lib/tdriver/util/user_data/user_data.rb +104 -0
  190. data/lib/tdriver/util/video/camera.rb +67 -0
  191. data/lib/tdriver/util/video/camera_linux.rb +153 -0
  192. data/lib/tdriver/util/video/camera_windows.rb +174 -0
  193. data/lib/tdriver/util/video/loader.rb +31 -0
  194. data/lib/tdriver/util/video/video_utils.rb +139 -0
  195. data/lib/tdriver/util/xml/abstraction.rb +117 -0
  196. data/lib/tdriver/util/xml/attribute.rb +32 -0
  197. data/lib/tdriver/util/xml/builder.rb +53 -0
  198. data/lib/tdriver/util/xml/comment.rb +32 -0
  199. data/lib/tdriver/util/xml/document.rb +32 -0
  200. data/lib/tdriver/util/xml/element.rb +32 -0
  201. data/lib/tdriver/util/xml/error.rb +46 -0
  202. data/lib/tdriver/util/xml/loader.rb +62 -0
  203. data/lib/tdriver/util/xml/nil_node.rb +95 -0
  204. data/lib/tdriver/util/xml/nodeset.rb +32 -0
  205. data/lib/tdriver/util/xml/parsers/libxml/libxml.rb +140 -0
  206. data/lib/tdriver/util/xml/parsers/loader.rb +21 -0
  207. data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +167 -0
  208. data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +66 -0
  209. data/lib/tdriver/util/xml/parsers/nokogiri/builder.rb +64 -0
  210. data/lib/tdriver/util/xml/parsers/nokogiri/comment.rb +39 -0
  211. data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +66 -0
  212. data/lib/tdriver/util/xml/parsers/nokogiri/element.rb +39 -0
  213. data/lib/tdriver/util/xml/parsers/nokogiri/loader.rb +58 -0
  214. data/lib/tdriver/util/xml/parsers/nokogiri/node.rb +212 -0
  215. data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +237 -0
  216. data/lib/tdriver/util/xml/parsers/nokogiri/text.rb +39 -0
  217. data/lib/tdriver/util/xml/text.rb +32 -0
  218. data/lib/tdriver/util/xml/xml.rb +332 -0
  219. data/lib/tdriver/verify/verify.rb +2398 -0
  220. data/lib/tdriver/version.rb +21 -0
  221. data/xml/behaviours/generic.xml +530 -0
  222. data/xml/defaults/generic.xml +11 -0
  223. data/xml/defaults/sut_generic.xml +8 -0
  224. data/xml/parameters/tdriver_parameters.xml +23 -0
  225. data/xml/templates/generic.xml +292 -0
  226. metadata +324 -0
@@ -0,0 +1,51 @@
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
+ [
21
+
22
+ # load test object abstract class
23
+ 'abstract',
24
+
25
+ # load test object factory
26
+ 'factory',
27
+
28
+ # load test object cache
29
+ 'cache',
30
+
31
+ # load test object adapter abstraction
32
+ 'xml/abstraction',
33
+
34
+ # load test object adapter
35
+ 'xml/adapter',
36
+
37
+ # load test object adapter
38
+ 'adapter',
39
+
40
+ # load verify ui module
41
+ 'verification'
42
+
43
+ ].each{ | filename |
44
+
45
+ require File.expand_path( File.join( File.dirname( __FILE__ ), filename ) )
46
+
47
+ }
48
+
49
+ # load test object behaviours
50
+ MobyUtil::FileHelper.load_modules( File.expand_path( File.join( File.dirname( __FILE__ ), 'behaviours' ) ) )
51
+
@@ -0,0 +1,178 @@
1
+
2
+ module TDriver
3
+
4
+ module TestObjectVerification
5
+
6
+ # private variables and methods
7
+ class << self
8
+
9
+ # TODO: Document me (TestObjectFactory::check_verify_always_reporting_settings)
10
+ def check_verify_always_reporting_settings
11
+
12
+ @@reporter_attached = $parameters[ :report_attach_continuous_verification_to_reporter, 'false' ]
13
+
14
+ @@rcv_raise_errors = $parameters[ :report_continuous_verification_raise_errors, 'true' ]
15
+
16
+ @@rcv_fail_test_case = $parameters[ :report_continuous_verification_fail_test_case_on_error, 'true' ]
17
+
18
+ @@rvc_capture_screen = $parameters[ :report_continuous_verification_capture_screen_on_error, 'true' ]
19
+
20
+ end
21
+
22
+ # TODO: Document me (TestObjectFactory::restore_verify_always_reporting_settings)
23
+ def restore_global_verify_always_reporting_settings
24
+
25
+ @@reporter_attached = @@global_reporter_attached
26
+
27
+ @@rcv_raise_errors = @@rcv_global_raise_errors
28
+
29
+ @@rcv_fail_test_case = @@rcv_global_fail_test_case
30
+
31
+ @@rvc_capture_screen = @@rvc_global_capture_screen
32
+
33
+ end
34
+
35
+ def initialize_settings
36
+
37
+ # defaults
38
+ @@global_reporter_attached = $parameters[ :report_attach_continuous_verification_to_reporter, 'false' ]
39
+
40
+ @@rcv_global_raise_errors = $parameters[ :report_continuous_verification_raise_errors, 'true' ]
41
+
42
+ @@rcv_global_fail_test_case = $parameters[ :report_continuous_verification_fail_test_case_on_error, 'true' ]
43
+
44
+ @@rvc_global_capture_screen = $parameters[ :report_continuous_verification_capture_screen_on_error, 'true' ]
45
+
46
+ @@inside_verify = false
47
+
48
+ @@initialized = true
49
+
50
+ end
51
+
52
+ # defaults
53
+ @@initialized = false
54
+
55
+ end
56
+
57
+ def self.verify_ui_dump( sut )
58
+
59
+ initialize_settings unless @@initialized
60
+
61
+ return if @@inside_verify
62
+
63
+ begin
64
+
65
+ @@inside_verify = true
66
+
67
+ logging_enabled = $logger.enabled
68
+
69
+ sut.verify_blocks.each do | verify |
70
+
71
+ check_verify_always_reporting_settings()
72
+
73
+ begin
74
+
75
+ $logger.enabled = false
76
+
77
+ begin
78
+
79
+ result = verify.block.call( sut )
80
+
81
+ rescue Exception => e
82
+
83
+ if @@rcv_raise_errors == 'true' || @@reporter_attached == 'false'
84
+
85
+ raise MobyBase::ContinuousVerificationError.new(
86
+ "Verification failed as an exception was thrown when the verification block was executed. #{ verify.source }\nDetails: #{ ( verify.message || "none" ) }\nNested exception:\n#{ e.inspect }"
87
+ )
88
+
89
+ elsif @@reporter_attached == 'true' && @@rcv_raise_errors == 'false'
90
+
91
+ TDriverReportAPI::tdriver_report_set_test_case_status('failed') if @@rcv_fail_test_case == 'true'
92
+
93
+ if @@rvc_capture_screen == 'true'
94
+
95
+ TDriverReportAPI::tdriver_capture_state
96
+
97
+ else
98
+
99
+ TDriverReportAPI::tdriver_capture_state( false )
100
+
101
+ end
102
+
103
+ TDriverReportAPI::tdriver_report_log("Verification failed as an exception was thrown when the verification block was executed. #{ verify.source }\nDetails: #{( verify.message || "none" ) }\nNested exception:\n#{ e.inspect }")
104
+
105
+ TDriverReportAPI::tdriver_report_log("<hr />")
106
+
107
+ $logger.enabled = logging_enabled
108
+ $logger.behaviour "FAIL;Verification #{verify.message.nil? ? '' : '\"' << verify.message << '\" '}failed:#{e.to_s}.\n#{verify.timeout.nil? ? '' : ' using timeout ' + verify.timeout.to_s}.;#{sut.id.to_s+';sut'};{};verify_always;" << verify.expected.to_s
109
+
110
+ end
111
+
112
+ end
113
+
114
+ unless result == verify.expected
115
+
116
+ if @@rcv_raise_errors == 'true' || @@reporter_attached == 'false'
117
+
118
+ raise MobyBase::ContinuousVerificationError.new(
119
+ "Verification failed. #{ verify.source }\nDetails: #{ ( verify.message || "none" ) }\nThe block did not return #{ verify.expected.inspect }. It returned: #{ result.inspect }"
120
+ )
121
+
122
+ elsif @@reporter_attached == 'true' && @@rcv_raise_errors == 'false'
123
+
124
+ TDriverReportAPI::tdriver_report_set_test_case_status('failed') if @@rcv_fail_test_case == 'true'
125
+
126
+ if @@rvc_capture_screen == 'true'
127
+
128
+ TDriverReportAPI::tdriver_capture_state
129
+
130
+ else
131
+
132
+ TDriverReportAPI::tdriver_capture_state( false )
133
+
134
+ end
135
+
136
+ TDriverReportAPI::tdriver_report_log(
137
+ "Verification failed. #{ verify.source }\nDetails: #{ ( verify.message || "none" ) }\nThe block did not return #{ verify.expected.inspect }. It returned: #{ result.inspect } "
138
+ )
139
+
140
+ TDriverReportAPI::tdriver_report_log("<hr />")
141
+
142
+ $logger.enabled = logging_enabled
143
+
144
+ $logger.behaviour "FAIL;Verification #{verify.message.nil? ? '' : '\"' << verify.message << '\" '}failed:#{e.to_s}.\n#{verify.timeout.nil? ? '' : ' using timeout ' + verify.timeout.to_s}.;#{sut.id.to_s+';sut'};{};verify_always;" << verify.expected.to_s
145
+
146
+ end
147
+
148
+ end
149
+
150
+ rescue Exception => e
151
+
152
+ $logger.enabled = logging_enabled
153
+
154
+ $logger.behaviour "FAIL;Verification #{verify.message.nil? ? '' : '\"' << verify.message << '\" '}failed:#{e.to_s}.\n#{verify.timeout.nil? ? '' : ' using timeout ' + verify.timeout.to_s}.;#{sut.id.to_s+';sut'};{};verify_always;" << verify.expected.to_s
155
+
156
+ @@inside_verify = false
157
+
158
+ raise e
159
+
160
+ end
161
+
162
+ # Do NOT report PASS cases, like other verify blocks do. This would clog the log with useless info.
163
+ restore_global_verify_always_reporting_settings
164
+
165
+ end
166
+
167
+ ensure
168
+
169
+ $logger.enabled = logging_enabled
170
+ @@inside_verify = false
171
+
172
+ end
173
+
174
+ end # verify_ui
175
+
176
+ end # TestObjectVerification
177
+
178
+ end # TDriver
@@ -0,0 +1,63 @@
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 TDriver
21
+
22
+ module Abstraction
23
+
24
+ module TestObjectAdapter
25
+
26
+ # TODO: document me
27
+ def identify_test_object_adapter_from_data( source )
28
+
29
+ # verify check that source data is given in correct format
30
+ source.check_type [ String, MobyUtil::XML::Element ], 'wrong argument type $1 for XML data source (expected $2)'
31
+
32
+ # parse if given source is type of string
33
+ source = MobyUtil::XML.parse_string( source ).root if source.kind_of?( String )
34
+
35
+ # determine xml format
36
+ if source.kind_of?( MobyUtil::XML::Element )
37
+
38
+ # detect optimized xml format
39
+ if source.xpath('.//obj[1]').count > 0
40
+
41
+ TDriver::OptimizedXML::TestObjectAdapter
42
+
43
+ # or deprecated xml format
44
+ elsif source.xpath('.//object[1]').count > 0
45
+
46
+ TDriver::TestObjectAdapter
47
+
48
+ # or raise exception if format was not detected
49
+ else
50
+
51
+ raise RuntimeError, 'Unsupported XML data format'
52
+
53
+ end
54
+
55
+ end # if
56
+
57
+ end # identify_test_object_adapter
58
+
59
+ end # TestObjectAdapter
60
+
61
+ end # Abstraction
62
+
63
+ end # TDriver
@@ -0,0 +1,773 @@
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 TDriver
21
+
22
+ module OptimizedXML
23
+
24
+ class TestObjectAdapter
25
+
26
+ # private methods and variables
27
+ class << self
28
+
29
+ # include abstraction module
30
+ include TDriver::Abstraction::TestObjectAdapter
31
+
32
+ private
33
+
34
+ # TODO: document me
35
+ def xpath_attributes( attributes, element_attributes, object_type )
36
+
37
+ # collect attributes
38
+ attributes = attributes.collect{ | key, values |
39
+
40
+ # allow multiple values options for attribute, e.g. object which 'text' attribute value is either '1' or '2'
41
+ ( values.kind_of?( Array ) ? values : [ values ] ).collect{ | value |
42
+
43
+ # concatenate string if it contains single and double quotes, otherwise return as is
44
+ value = xpath_literal_string( value )
45
+
46
+ prefix_key = "@#{ key }"
47
+
48
+ if @partial_match_allowed.include?( [ object_type, key ] )
49
+
50
+ # regexp support is needed also here
51
+ if value.kind_of?( Regexp )
52
+
53
+ prefix_value = "regexp_compare(#{ prefix_key },'#{ value.source }',#{ value.options })"
54
+ attribute_value = "regexp_compare(.,'#{ value.source }',#{ value.options })"
55
+
56
+ prefix_key = ""
57
+
58
+ else
59
+
60
+ prefix_value = "[contains(.,#{ value })]"
61
+ attribute_value = "contains(.,#{ value })"
62
+
63
+ end
64
+ else
65
+
66
+ if value.kind_of?( Regexp )
67
+
68
+ prefix_value = "regexp_compare(#{ prefix_key },'#{ value.source }',#{ value.options })"
69
+ attribute_value = "regexp_compare(.,'#{ value.source }',#{ value.options })"
70
+
71
+ prefix_key = ""
72
+
73
+ else
74
+
75
+ #prefix_value = "=#{ value }"
76
+ #attribute_value = "text()=#{ value }"
77
+
78
+ prefix_value = "=#{ value }"
79
+ attribute_value = ".=#{ value }"
80
+
81
+ end
82
+
83
+ end
84
+
85
+ # construct xpath
86
+ #"(#{ element_attributes ? "#{ prefix_key }#{ prefix_value } or " : "" }attr[translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='#{ key }' and #{ attribute_value }])"
87
+ "(#{ element_attributes ? "#{ prefix_key }#{ prefix_value } or " : "" }attr[translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='#{ key }' and #{ attribute_value }])"
88
+
89
+ }.join( ' or ' ) # join attribute alternative values
90
+
91
+ }.join( ' and ' ) # join all required attributes
92
+
93
+ #p attributes
94
+
95
+ # return created xpath or nil if no attributes given
96
+ if attributes.empty?
97
+
98
+ # no attributes given
99
+ nil
100
+
101
+ else
102
+
103
+ # return result
104
+ attributes
105
+
106
+ end
107
+
108
+ end # xpath_attributes
109
+
110
+ #merges elements from the nodeset, used in hybrid app situations
111
+ def create_merged_element(nodeset, environments, close_element=true)
112
+ merged_element_set = false
113
+
114
+ merged_xml = ""
115
+
116
+ nodeset.each{ | object |
117
+
118
+ # only one top element
119
+ unless merged_element_set
120
+
121
+ # retrieve object attributes
122
+ attributes = object.attributes
123
+
124
+ # merge env to attributes hash
125
+ attributes['env'] = environments.join(';')
126
+
127
+ # add application object xml element to new xml string
128
+ merged_xml << "<obj #{ hash_to_element_attributes( attributes ) }>"
129
+
130
+ # merged element is now set, no need to do it again
131
+ merged_element_set = true
132
+
133
+ end
134
+
135
+ # append all found elements
136
+ object.xpath('./*').each{ | object | merged_xml << object.to_s }
137
+ }
138
+ merged_xml << "</obj>" if close_element and merged_element_set
139
+ merged_xml
140
+ end
141
+
142
+ # TODO: document me
143
+ def initialize_class
144
+
145
+ # special cases: allow partial match when value of type and attribute name matches
146
+ @partial_match_allowed = [ 'list_item', 'text' ], [ 'application', 'fullname' ]
147
+
148
+ end
149
+
150
+ end # static
151
+
152
+ # TODO: document me
153
+ def self.regexp_compare( nodeset, source, options )
154
+
155
+ # rebuild defined regexp, used while matching element content
156
+ regexp_object = Regexp.new( source.to_s, options.to_i )
157
+
158
+ # collect all nodes matching with regexp
159
+ nodeset.find_all{ | node | node.content =~ regexp_object }
160
+
161
+ end
162
+
163
+ # TODO: document me
164
+ def self.xpath_to_object( rules, find_all_children )
165
+
166
+ # convert hash keys to downcased string
167
+ rules = Hash[
168
+
169
+ rules.collect{ | key, value |
170
+
171
+ case value
172
+
173
+ # pass the value as is if type of regexp or array; array is used in localisation cases e.g. [ 'one', 'yksi', 'uno' ] # etc
174
+ when Regexp, Array
175
+
176
+ [ key.to_s.downcase, value ]
177
+
178
+ else
179
+
180
+ [ key.to_s.downcase, value.to_s ]
181
+
182
+ end
183
+
184
+ }
185
+
186
+ ]
187
+
188
+ # xpath container array
189
+ test_object_xpath_array = []
190
+
191
+ # store and remove object element attributes from hash
192
+ object_element_attributes = rules.delete_keys!( 'name', 'type', 'parent', 'id' )
193
+
194
+ # children method may request test objects of any type
195
+ if object_element_attributes[ 'type' ] == '*'
196
+
197
+ # test object with any name, type, parent and id is allowed
198
+ test_object_xpath_array << '@*'
199
+
200
+ else
201
+
202
+ # required attributes
203
+ test_object_xpath_array << xpath_attributes( object_element_attributes, true, object_element_attributes[ 'type' ] )
204
+
205
+ end
206
+
207
+ # additional attributes, eg. :text, :x, :y etc.
208
+ test_object_xpath_array << xpath_attributes( rules, false, object_element_attributes[ 'type' ] )
209
+
210
+ # join required and additional attribute strings
211
+ test_object_xpath_string = test_object_xpath_array.compact.join( ' and ' )
212
+
213
+ # return any child element under current node or only immediate child element
214
+ #find_all_children ? "*//obj[#{ test_object_xpath_string }]" : "obj[1]/obj[#{ test_object_xpath_string }]"
215
+
216
+ find_all_children ? ".//obj[#{ test_object_xpath_string }]" : "obj[#{ test_object_xpath_string }]"
217
+
218
+ #"*//obj[#{ test_object_xpath_string }]"
219
+
220
+ end
221
+
222
+ # TODO: document me
223
+ def self.xpath_literal_string( string )
224
+
225
+ return string if string.kind_of?( Regexp )
226
+
227
+ # make sure that argument is type of string
228
+ string = string.to_s
229
+
230
+ # does not contain no single quotes
231
+ if not string.include?("'")
232
+
233
+ result = "'#{ string }'"
234
+
235
+ # does not contain no double quotes
236
+ elsif not string.include?('"')
237
+
238
+ result = "\"#{ string }\""
239
+
240
+ # contains single and double quotes
241
+ else
242
+
243
+ # open new item
244
+ result = ["'"]
245
+
246
+ # iterate through each character
247
+ string.each_char{ | char |
248
+
249
+ case char
250
+
251
+ # encapsulate single quotes with double quotes
252
+ when "'"
253
+
254
+ # close current item
255
+ result.last << char
256
+
257
+ # add encapsulated single quote
258
+ result << "\"'\""
259
+
260
+ # open new item
261
+ result << char
262
+
263
+ else
264
+
265
+ # any other character will appended as is
266
+ result.last << char
267
+
268
+ end
269
+
270
+ }
271
+
272
+ # close last sentence
273
+ result.last << "'"
274
+
275
+ # create concat clause for xpath
276
+ result = "concat(#{ result.join(',') })"
277
+
278
+ end
279
+
280
+ result
281
+
282
+ end
283
+
284
+ # TODO: document me
285
+ def self.get_objects( source_data, rules, find_all_children )
286
+
287
+ rule = xpath_to_object( rules, find_all_children )
288
+
289
+ [
290
+
291
+ # perform xpath to source xml data
292
+ source_data.xpath( rule, self ),
293
+
294
+ # return also created xpath
295
+ rule
296
+
297
+ ]
298
+
299
+ end
300
+
301
+ # TODO: document me
302
+ def self.test_object_hash( object_id, object_type, object_name )
303
+
304
+ # calculate test object hash
305
+ ( ( ( 17 * 37 + object_id ) * 37 + object_type.hash ) * 37 + object_name.hash )
306
+
307
+ end
308
+
309
+ # Sort XML nodeset of test objects with layout direction
310
+ def self.sort_elements( nodeset, layout_direction = 'LeftToRight' )
311
+
312
+ # cache for x_absolute and y_absolute values; reduces dramatically number of xpath calls
313
+ cache = {}
314
+
315
+ # xpath pattern to be used for x_absolute attribute value
316
+ x_absolute_pattern = './attr[@name="x_absolute"]/text()'
317
+
318
+ # xpath pattern to be used for x_absolute attribute value
319
+ y_absolute_pattern = './attr[@name="y_absolute"]/text()'
320
+
321
+ # collect only nodes that has x_absolute and y_absolute attributes
322
+ nodeset.collect!{ | node |
323
+
324
+ # retrieve x_absolute attribute
325
+ x_absolute = node.at_xpath( x_absolute_pattern )
326
+
327
+ # retrieve y_absolute attribute
328
+ y_absolute = node.at_xpath( y_absolute_pattern )
329
+
330
+ # return unmodified nodeset if both attributes was not found
331
+ if x_absolute.nil? || y_absolute.nil?
332
+
333
+ #warn("Warning: Unable to sort object set due to object type of #{ node.attribute( 'type' ).inspect } does not have \"x_absolute\" or \"y_absolute\" attribute")
334
+
335
+ return nodeset
336
+
337
+ else
338
+
339
+ # store attributes to cache for further processing
340
+ cache[ node ] = [ x_absolute.content.to_i, y_absolute.content.to_i ]
341
+
342
+ # return node as result
343
+ node
344
+
345
+ end
346
+
347
+ }.compact!.sort!{ | element_a, element_b |
348
+
349
+ # retrieve element a's attributes x and y
350
+ element_a_x, element_a_y = cache[ element_a ]
351
+
352
+ # retrieve element b's attributes x and y
353
+ element_b_x, element_b_y = cache[ element_b ]
354
+
355
+ case layout_direction
356
+
357
+ when 'LeftToRight'
358
+
359
+ # compare elements
360
+ ( element_a_y == element_b_y ) ? ( element_a_x <=> element_b_x ) : ( element_a_y <=> element_b_y )
361
+
362
+ when 'RightToLeft'
363
+
364
+ # compare elements
365
+ ( element_a_y == element_b_y ) ? ( element_b_x <=> element_a_x ) : ( element_a_y <=> element_b_y )
366
+
367
+ else
368
+
369
+ # raise exception if layout direction it not supported
370
+ raise ArgumentError, "Unsupported layout direction #{ layout_direction.inspect }"
371
+
372
+ end
373
+
374
+ }
375
+
376
+ end
377
+
378
+ def self.parent_test_object_element( test_object )
379
+
380
+ # retrieve parent of current xml element; obj/..
381
+ test_object.refresh #Refresh the test object for identification
382
+ test_object.xml_data.parent #.parent
383
+
384
+ end
385
+
386
+ # TODO: document me
387
+ def self.test_object_element_attributes( source_data )
388
+
389
+ #Hash[
390
+ # source_data.attributes.collect{ | key, value |
391
+ # [ key.to_s, value.to_s ]
392
+ # }
393
+ #]
394
+
395
+ source_data.attributes
396
+
397
+ end
398
+
399
+ # TODO: document me
400
+ def self.test_object_element_attribute( source_data, attribute_name, *default, &block )
401
+
402
+ result = source_data.attribute( attribute_name )
403
+
404
+ # if no attribute found call optional code block or raise exception
405
+ unless result
406
+
407
+ if block_given?
408
+
409
+ # pass return value of block as result
410
+ yield( attribute_name )
411
+
412
+ else
413
+
414
+ # raise exception if no default value given
415
+ if default.empty?
416
+
417
+ # raise exception if no such attribute found
418
+ raise MobyBase::AttributeNotFoundError, "Could not find test object element attribute #{ attribute_name.inspect }"
419
+
420
+ else
421
+
422
+ # pass default value as result
423
+ default.first
424
+
425
+ end
426
+
427
+ end
428
+
429
+ else
430
+
431
+ result
432
+
433
+ end
434
+
435
+ end
436
+
437
+ # TODO: document me
438
+ def self.test_object_attribute( source_data, attribute_name, *default, &block )
439
+
440
+ # TODO: consider using at_xpath and adding text() to query string; however "downside" is that if multiple matches found only first value will be returned as result
441
+
442
+ # retrieve attribute(s) from xml
443
+ nodeset = source_data.xpath(
444
+
445
+ "attr[translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='#{ attribute_name.downcase }']"
446
+
447
+ )
448
+
449
+ # if no attributes found call optional code block or raise exception
450
+ if nodeset.empty?
451
+
452
+ if block_given?
453
+
454
+ # pass return value of block as result
455
+ yield( attribute_name )
456
+
457
+ else
458
+
459
+ # raise exception if no default value given
460
+ if default.empty?
461
+
462
+ # raise exception if no such attribute found
463
+ raise MobyBase::AttributeNotFoundError, "Could not find attribute #{ attribute_name.inspect }" # for test object of type #{ type.to_s }"
464
+
465
+ else
466
+
467
+ # pass default value as result
468
+ default.first
469
+
470
+ end
471
+
472
+ end # block_given?
473
+
474
+ else # not nodeset.empty?
475
+
476
+ # attribute(s) found
477
+ # Need to disable this for now
478
+ # raise MobyBase::MultipleAttributesFoundError.new( "Multiple attributes found with name '#{ name }'" ) if nodeset.count > 1
479
+
480
+ # return found attribute
481
+ nodeset.first.content
482
+
483
+ end
484
+
485
+ end
486
+
487
+ # TODO: document me
488
+ def self.test_object_attributes( source_data, inclusive_filter = [] )
489
+
490
+ # convert all keys to lowercase
491
+ inclusive_filter.collect!{ | key | key.to_s.downcase } unless inclusive_filter.empty?
492
+
493
+ # return hash of test object attributes
494
+ object_attributes = {}
495
+
496
+ # iterate each attribute and collect name and value
497
+ source_data.xpath( 'attr' ).collect{ | value |
498
+
499
+ # retrieve attribute name
500
+ name = value.attribute('name').to_s
501
+
502
+ # collect attribute elements name and content
503
+ unless inclusive_filter.empty?
504
+
505
+ object_attributes[name]=value.content if inclusive_filter.include?( name.downcase )
506
+
507
+ else
508
+ # pass the attribute pair - no filtering done
509
+ if object_attributes[name]
510
+ object_attributes[name]="#{object_attributes[name]},#{value.content}"
511
+ else
512
+ object_attributes[name]=value.content
513
+ end
514
+ end
515
+
516
+ }
517
+
518
+ object_attributes
519
+
520
+ end
521
+
522
+ # TODO: document me
523
+ def self.application_layout_direction( sut )
524
+
525
+ # temporary fix until testobject will be associated to parent application object; add 'layoutDirection' to dynamic attributes filtering whitelist...
526
+ TDriver::AttributeFilter.add_attribute( 'layoutDirection' ){
527
+
528
+ # this block will be executed if attribute was not in filter list
529
+
530
+ # temporary fix: ... and refresh sut to retrieve updated xml data
531
+ sut.refresh
532
+
533
+ }
534
+
535
+ # TODO: parent application test object should be passed to get_test_objects; TestObjectAdapter#test_object_attribute( @app.xml_data, 'layoutDirection')
536
+ #( sut.xml_data.at_xpath('*//obj[@type="application"]/attr[@name="layoutDirection"]/text()').content || 'LeftToRight' ).to_s
537
+
538
+ ( sut.xml_data.at_xpath('.//obj[@type="application"]/attr[@name="layoutDirection"]/text()').content || 'LeftToRight' ).to_s
539
+
540
+ end
541
+
542
+ # TODO: document me
543
+ def self.create_child_accessors!( source_data, test_object )
544
+
545
+ # iterate through each child object type attribute and create accessor method
546
+ source_data.xpath( 'obj/@type' ).each{ | object_type |
547
+
548
+ # skip if object type value is nil or empty due to child accessor cannot be created
549
+ next if object_type.nil? || object_type.to_s.empty?
550
+
551
+ # convert attribute node value to string
552
+ object_type = object_type.content
553
+
554
+ # skip if child accessor is already created
555
+ next if test_object.respond_to?( object_type )
556
+
557
+ begin
558
+
559
+ # create child accessor method to test object unless already exists
560
+ test_object.instance_eval(
561
+
562
+ "def #{ object_type }( rules = {} ); raise TypeError,'parameter <rules> should be hash' unless rules.kind_of?( Hash ); rules[ :type ]=:#{ object_type }; child( rules ); end;"
563
+
564
+ ) unless object_type.empty?
565
+
566
+ # in case if object type has some invalid characters, e.g. type is "ns:object"
567
+ rescue SyntaxError
568
+
569
+ warn "warning: unable to create accessor to child test object whose type is #{ object_type.inspect }"
570
+
571
+ end
572
+
573
+ }
574
+
575
+ end
576
+
577
+ # TODO: document me
578
+ def self.state_object_xml( source_data, id )
579
+
580
+ # collect each object from source xml
581
+ #objects = source_data.xpath( 'tasInfo/obj' ).collect{ | element | element.to_s }.join
582
+
583
+ # return xml root element
584
+ #MobyUtil::XML.parse_string(
585
+ # "<sut name='sut' type='sut' id='#{ id }'>#{ objects }</sut>"
586
+ #).root
587
+
588
+ # return xml root element
589
+ MobyUtil::XML.parse_string( "<sut name='sut' type='sut' id='#{ id }'>#{ source_data.xpath('tasInfo/obj').inject(""){ | result, element | result << element.to_s; } }</sut>" ).root
590
+
591
+ end
592
+
593
+ def self.retrieve_parent_application( xml_source )
594
+
595
+ xml_source_iterator = xml_source.clone
596
+
597
+ while xml_source_iterator.kind_of?( MobyUtil::XML::Element )
598
+
599
+ if ( test_object_element_attribute( xml_source_iterator, 'type' ) == 'application' )
600
+
601
+ return xml_source_iterator
602
+
603
+ end
604
+
605
+ if xml_source_iterator.kind_of?( MobyUtil::XML::Element )
606
+
607
+ xml_source_iterator = xml_source_iterator.parent
608
+
609
+ else
610
+
611
+ # not found from xml tree
612
+ break
613
+
614
+ end
615
+
616
+ end
617
+
618
+ #warn("warning: unable to retrieve parent application")
619
+
620
+ raise MobyBase::TestObjectNotFoundError, "Unable to retrieve parent application"
621
+
622
+ # return application object or nil if no parent found
623
+ # Does is make sense to return nil - shouldn't all test objects belong to an application? Maybe throw exception if application not found
624
+
625
+ #nil
626
+
627
+ #return @sut.child( :type => 'application' ) rescue nil
628
+
629
+ end
630
+
631
+ # TODO: document me
632
+ def self.get_xml_element_for_test_object( test_object )
633
+
634
+ # retrieve nodeset from sut xml_data
635
+ nodeset = test_object.instance_variable_get( :@sut ).xml_data.xpath( test_object.instance_variable_get( :@x_path ) )
636
+
637
+ # raise exception if no test objects found
638
+ raise MobyBase::TestObjectNotFoundError if nodeset.empty?
639
+
640
+ # return first test object from the nodeset
641
+ nodeset.first
642
+
643
+ end
644
+
645
+ # TODO: document me
646
+ def self.get_test_object_identifiers( xml_source, test_object = nil )
647
+
648
+ # retrieve parent xpath if test_object given
649
+ parent_xpath = test_object ? test_object.instance_variable_get( :@parent ).x_path : ""
650
+
651
+ # retrieve type attribute
652
+ type = xml_source.attribute( 'type' )
653
+
654
+ # retrieve id attribute
655
+ id = xml_source.attribute( 'id' )
656
+
657
+ # retrieve env attribute
658
+ env = xml_source.attribute( 'env' )
659
+
660
+ # retrieve test object element attributes and return array containting xpath to test object, name, type and id elements
661
+ [
662
+ # x_path to test object
663
+ #test_object ? "#{ parent_xpath }/*//obj[@type='#{ type }' and @id='#{ id }']" : nil,
664
+
665
+ test_object ? "#{ parent_xpath }/.//obj[@type='#{ type }' and @id='#{ id }']" : nil,
666
+
667
+ # test object name
668
+ xml_source.attribute( 'name' ),
669
+
670
+ # test object type
671
+ type,
672
+
673
+ # test object id
674
+ id,
675
+
676
+ env
677
+
678
+ ]
679
+
680
+ end
681
+
682
+ # TODO: document me
683
+ def self.hash_to_element_attributes( hash )
684
+
685
+ hash.collect{ | key, value |
686
+
687
+ "#{ key.to_s }=\"#{ value.to_s }\""
688
+
689
+ }.join(' ')
690
+
691
+ end
692
+
693
+ # TODO: document me
694
+ def self.merge_application_elements( xml_string )
695
+
696
+ # parse the ui state xml
697
+ document_root = MobyUtil::XML.parse_string( xml_string ).root
698
+
699
+ # retrieve application objects as nodeset
700
+ nodeset = document_root.xpath('/tasMessage/tasInfo/obj')
701
+
702
+ # check if multiple application objects found
703
+ if nodeset.count > 1
704
+
705
+ # new header, apply original element attributes
706
+ new_xml = "<tasMessage #{ hash_to_element_attributes( document_root.attributes ) }><tasInfo #{ hash_to_element_attributes( nodeset.first.parent.attributes ) }>"
707
+
708
+ # flag defining that is application element already created
709
+ application_element_set = false
710
+
711
+ # keep error element
712
+ new_xml << document_root.xpath('/tasMessage/tasInfo/obj[@type="Error"]').to_s
713
+
714
+ # collect environment values
715
+ environments = document_root.xpath('/tasMessage/tasInfo/obj[@type="application"]/@env').collect{ | attribute | attribute.to_s }
716
+
717
+ #limit to apps
718
+ nodeset = document_root.xpath('/tasMessage/tasInfo/obj[@type="application"]')
719
+ close_vkb = false
720
+ if nodeset.count > 0
721
+ new_xml << create_merged_element(nodeset, environments, false)
722
+ close_vkb = true
723
+ end
724
+ # do the same to the vkbs
725
+ environments = document_root.xpath('/tasMessage/tasInfo/obj[@type="vkb_app"]/@env').collect{ | attribute | attribute.to_s }
726
+ nodeset = document_root.xpath('/tasMessage/tasInfo/obj[@type="vkb_app"]')
727
+ new_xml << create_merged_element(nodeset, environments, close_vkb)
728
+
729
+ # multiple applications found, return merged application xml
730
+ new_xml << "</obj></tasInfo></tasMessage>"
731
+
732
+ else
733
+
734
+ # only one application found, return data as is
735
+ xml_string
736
+
737
+ end
738
+
739
+ end
740
+
741
+ # TODO: document me
742
+ def self.list_test_objects_as_string( source_data )
743
+
744
+ source_data.collect{ | object |
745
+
746
+ path = [ object.attribute( 'type' ) ]
747
+
748
+ while object.attribute( 'type' ) != 'application' do
749
+
750
+ # object/objects/object/../..
751
+ object = object.parent
752
+
753
+ path << object.attribute( 'type' )
754
+
755
+ end
756
+
757
+ path.reverse.join( '.' )
758
+
759
+ }.sort
760
+
761
+ end
762
+
763
+ # enable hooking for performance measurement & debug logging
764
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
765
+
766
+ # initialize TDriver::TestObjectAdapter
767
+ initialize_class
768
+
769
+ end # TestObjectAdapter
770
+
771
+ end # OptimizedXML
772
+
773
+ end # TDriver