testability-driver-qt-sut-plugin 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/env.rb +26 -0
  2. data/installer/extconf.rb +62 -0
  3. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin.rb +23 -0
  4. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/action.rb +156 -0
  5. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/application.rb +318 -0
  6. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/attribute.rb +227 -0
  7. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/behaviour.rb +140 -0
  8. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/configure_behaviour.rb +317 -0
  9. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/events.rb +165 -0
  10. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/file_transfer.rb +333 -0
  11. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/find.rb +80 -0
  12. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/fixture.rb +178 -0
  13. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/gesture.rb +906 -0
  14. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/infologger.rb +604 -0
  15. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/key_press.rb +152 -0
  16. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/locale_db.rb +151 -0
  17. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/method.rb +85 -0
  18. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/multitouch.rb +455 -0
  19. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/os.rb +100 -0
  20. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/qt_api_method.rb +148 -0
  21. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/record.rb +124 -0
  22. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/screen_capture.rb +283 -0
  23. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/sut.rb +492 -0
  24. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/synchronization.rb +113 -0
  25. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/treewidgetitemcolumn.rb +93 -0
  26. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/type_text.rb +97 -0
  27. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/view_item.rb +97 -0
  28. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/webkit.rb +230 -0
  29. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/widget.rb +663 -0
  30. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/action.rb +30 -0
  31. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/configure_command.rb +38 -0
  32. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/drag.rb +44 -0
  33. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/find_object.rb +50 -0
  34. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/fixture.rb +45 -0
  35. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/group.rb +48 -0
  36. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/infologger_command.rb +38 -0
  37. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/qt.rb +170 -0
  38. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/tap.rb +54 -0
  39. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/widget.rb +226 -0
  40. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/application.rb +264 -0
  41. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/configure_command.rb +60 -0
  42. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/find_object.rb +114 -0
  43. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/fixture.rb +67 -0
  44. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/group.rb +52 -0
  45. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/infologger_command.rb +62 -0
  46. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/key_sequence.rb +99 -0
  47. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/screen_capture.rb +54 -0
  48. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/tap.rb +51 -0
  49. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/widget.rb +72 -0
  50. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/plugin.rb +119 -0
  51. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/adapter.rb +225 -0
  52. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/communication.rb +154 -0
  53. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/controller.rb +58 -0
  54. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/util/fixture_parameter.rb +77 -0
  55. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/util/widget.rb +82 -0
  56. data/lib/testability-driver-qt-sut-plugin.rb +24 -0
  57. data/xml/behaviour/qt.xml +717 -0
  58. data/xml/defaults/sut_qt.xml +9 -0
  59. data/xml/keymap/qt.xml +321 -0
  60. data/xml/template/qt.xml +124 -0
  61. metadata +141 -0
@@ -0,0 +1,100 @@
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 TDriver.
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 MobyBehaviour
21
+
22
+ module QT
23
+
24
+ # == description
25
+ # OS specific behaviours
26
+ #
27
+ # == behaviour
28
+ # QtOs
29
+ #
30
+ # == requires
31
+ # testability-driver-qt-sut-plugin
32
+ #
33
+ # == input_type
34
+ # *
35
+ #
36
+ # == sut_type
37
+ # QT
38
+ #
39
+ # == sut_version
40
+ # *
41
+ #
42
+ # == objects
43
+ # sut
44
+ #
45
+ module Os
46
+
47
+ include MobyBehaviour::QT::Behaviour
48
+
49
+ # This method is now deprecated as the latest version of QTTas server never loards PlatformService
50
+ # Select and open a file from an active open file dialog
51
+ # == params
52
+ # == returns
53
+ # == raises
54
+ # def open_file(path, dialog_name, button)
55
+ # begin
56
+ # command = command_params #in qt_behaviour
57
+ # command.command_name('OpenFile')
58
+ # command.command_params('dialogName' => dialog_name, 'filePath' => path, 'dialogButton' => button)
59
+ # command.service('platformOperation')
60
+ ##open file is done without ui state update so wait for the dialog to open
61
+ # sleep 0.2
62
+ # @sut.execute_command(command)
63
+ # self.force_refresh
64
+ # rescue Exception => e
65
+ # MobyUtil::Logger.instance.log "behaviour" , "FAIL;Failed open_file with path \"#{path}\", dialog_name \"#{dialog_name}\", button \"#{button.to_s}\".;#{identity};open_file;"
66
+ # Kernel::raise e
67
+ # end
68
+ # MobyUtil::Logger.instance.log "behaviour" , "PASS;Operation file executed successfully with path \"#{path}\", dialog_name \"#{dialog_name}\", button \"#{button.to_s}\".;#{identity};open_file;"
69
+ # nil
70
+ # end
71
+ # Press Enter on the keyboard. Useful to accept crash warnings on windows
72
+ # == params
73
+ # == returns
74
+ # == raises
75
+
76
+ # == deprecated
77
+ # 0.x.x
78
+ # == description
79
+ # This method is now deprecated as recent version of Agent Qt server never loads PlatformService
80
+ def press_enter(interval = nil)
81
+ begin
82
+ if interval
83
+ interval = (interval*1000).to_i
84
+ params = {:interval => interval}
85
+ end
86
+ self.execute_command( MobyCommand::WidgetCommand.new( nil, nil, nil, 'PressEnter', params, nil, 'uiCommand') )
87
+ rescue Exception => e
88
+ MobyUtil::Logger.instance.log "behaviour" , "FAIL;Failed to send an Enter keystroke request to the qttas server;press_enter;"
89
+ Kernel::raise e
90
+ end
91
+ MobyUtil::Logger.instance.log "behaviour" , "PASS;Successfuly sent an Enter keystroke request to the qttas server;press_enter;"
92
+ nil
93
+ end
94
+
95
+ # enable hooking for performance measurement & debug logging
96
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
97
+
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,148 @@
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 TDriver.
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 MobyBehaviour
21
+
22
+ module QT
23
+
24
+ module ApiMethod
25
+
26
+ class MethodReturnValue
27
+
28
+ attr_reader :value, :type
29
+
30
+ def initialize( type, value )
31
+ Kernel::raise ArgumentError.new("Invalid argument type for type. (Actual: %s, Expected: String)" % [ type.class.to_s ] ) unless type.kind_of?( String )
32
+ Kernel::raise ArgumentError.new("Invalid argument type for value. (Actual: %s, Expected: String)" % [ value.class.to_s ] ) unless value.kind_of?( String )
33
+ @type, @value = type, value
34
+ end
35
+
36
+ def to_s
37
+ @value
38
+ end
39
+
40
+ def ==( value )
41
+ value == @value
42
+ end
43
+
44
+ # enable hooking for performance measurement & debug logging
45
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
46
+
47
+ end
48
+
49
+ class Method
50
+
51
+ RETURN_RESULT_VALUE = 0x01
52
+ RETURN_RESULT_AS_LIST = 0x02
53
+ RETURN_RESULT_AS_XML = 0x03
54
+
55
+ def initialize( parent, fixture_name )
56
+ Kernel::raise ArgumentError.new("Invalid argument type for fixture name. (Actual: %s, Expected: String)" % [ fixture_name.class.to_s ] ) unless fixture_name.kind_of?( String )
57
+ @parent, @fixture_name = parent, fixture_name
58
+ end
59
+
60
+ def list_methods
61
+ execute( RETURN_RESULT_AS_LIST, 'list_methods' )
62
+ end
63
+
64
+ def list_class_methods( class_name )
65
+ Kernel::raise ArgumentError.new("Invalid argument type for class name. (Actual: %s, Expected: String)" % [ class_name.class.to_s ]) unless class_name.kind_of?( String )
66
+ execute( RETURN_RESULT_AS_LIST, 'list_class methods', { :class => class_name } )
67
+ end
68
+
69
+ def method_missing( method_name, *args, &block )
70
+ execute( RETURN_RESULT_VALUE, 'invoke_method', { :method => "#{ method_name }", :args => MobyUtil::FixtureParameter.new( *args ).to_s } )
71
+ end
72
+
73
+ def debug_invoke_method( method_name, *args )
74
+ # call methods normally
75
+ execute( RETURN_RESULT_AS_XML, 'invoke_method', { :method => "#{ method_name }", :args => MobyUtil::FixtureParameter.new( *args ).to_s } )
76
+ end
77
+
78
+ private
79
+
80
+ def execute( return_result_as_mode, command, *args )
81
+
82
+ result = nil
83
+
84
+ @parent.fixture( @fixture_name, command, *args ).tap{ | result_xml |
85
+
86
+ case return_result_as_mode
87
+
88
+ when RETURN_RESULT_VALUE
89
+
90
+ # return value as QtMethodReturnValue
91
+ MobyUtil::XML.parse_string( result_xml ).tap{ | xml_data |
92
+ xml_data.xpath( "*//object[@type='QtMethod']/attributes" ).first.tap{ | element |
93
+ result = QtMethodReturnValue.new(
94
+ element.xpath( "attribute[@name='returnValueType']/value" ).first.content,
95
+ element.xpath( "attribute[@name='returnValue']/value" ).first.content
96
+ ) unless element.nil?
97
+ }
98
+ }
99
+
100
+ Kernel::raise RuntimeError.new("Unable to parse fixture result xml (QtApiAccessor)") if result.nil?
101
+
102
+ when RETURN_RESULT_AS_LIST
103
+
104
+ # return result as Array
105
+ result = []
106
+
107
+ # TODO: This branch needs to be refactored --> method needed that retrieves ALL TestObjects of given type without MultipleTestObjectsFound exception
108
+ MobyUtil::XML.parse_string( result_xml ).tap{ | xml_data |
109
+ xml_data.xpath( "*//object[@type='QtMethod']" ).each{ | element |
110
+ result << { :method => "#{ element.attribute("name") }" }
111
+ element.xpath( "attributes/*" ).each{ | attributes |
112
+ result.last.merge!( { attributes.attribute( "name" ).to_sym => attributes.xpath( "value" ).first.content } )
113
+ }
114
+ }
115
+ }
116
+
117
+ when RETURN_RESULT_AS_XML
118
+ # return result as is (xml string)
119
+ result = result_xml
120
+
121
+ end
122
+
123
+ }
124
+
125
+ result
126
+
127
+ end
128
+
129
+ # enable hooking for performance measurement & debug logging
130
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
131
+
132
+ end
133
+
134
+ # == nodoc
135
+ def QtMethod
136
+
137
+ MobyBehaviour::QT::ApiMethodBehaviour::Method.new( self, "tasqtapiaccessor" )
138
+
139
+ end
140
+
141
+ # enable hooking for performance measurement & debug logging
142
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
143
+
144
+ end
145
+
146
+ end
147
+
148
+ end
@@ -0,0 +1,124 @@
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 TDriver.
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 MobyBehaviour
21
+
22
+ module QT
23
+
24
+ # == description
25
+ # Record specific behaviours
26
+ #
27
+ # == behaviour
28
+ # QtRecord
29
+ #
30
+ # == requires
31
+ # testability-driver-qt-sut-plugin
32
+ #
33
+ # == input_type
34
+ # *
35
+ #
36
+ # == sut_type
37
+ # QT
38
+ #
39
+ # == sut_version
40
+ # *
41
+ #
42
+ # == objects
43
+ # application
44
+ #
45
+ module Record
46
+
47
+ include MobyBehaviour::QT::Behaviour
48
+
49
+ def start_recording
50
+
51
+ begin
52
+
53
+ command = plugin_command() #in qt_behaviour
54
+ command.command_name( 'Start' )
55
+ command.service( 'recordEvents' )
56
+ @sut.execute_command( command)
57
+
58
+ rescue Exception => e
59
+
60
+ MobyUtil::Logger.instance.log "behaviour" , "FAIL;Failed start_recording.;#{ identity };start_recording;"
61
+ Kernel::raise e
62
+
63
+ end
64
+
65
+ MobyUtil::Logger.instance.log "behaviour" , "PASS;Operation start_recording executed successfully.;#{ identity };start_recording;"
66
+
67
+ nil
68
+ end
69
+
70
+ def stop_recording
71
+
72
+ begin
73
+
74
+ command = plugin_command() #in qt_behaviour
75
+ command.command_name( 'Stop' )
76
+ command.service( 'recordEvents' )
77
+ @sut.execute_command( command)
78
+
79
+ rescue Exception => e
80
+
81
+ MobyUtil::Logger.instance.log "behaviour" , "FAIL;Failed stop_recording.;#{ identity };stop_recording;"
82
+ Kernel::raise e
83
+
84
+ end
85
+
86
+ MobyUtil::Logger.instance.log "behaviour" , "PASS;Operation stop_recording executed successfully.;#{ identity };stop_recording;"
87
+
88
+ nil
89
+
90
+ end
91
+
92
+ def print_recordings
93
+
94
+ ret = nil
95
+
96
+ begin
97
+
98
+ command = plugin_command(true) #in qt_behaviour
99
+ command.command_name( 'Print' )
100
+ command.service( 'recordEvents' )
101
+ ret = @sut.execute_command( command )
102
+
103
+ rescue Exception => e
104
+
105
+ MobyUtil::Logger.instance.log "behaviour" , "FAIL;Failed print_recordings.;#{ identity };print_recordings;"
106
+ Kernel::raise e
107
+
108
+ end
109
+
110
+ MobyUtil::Logger.instance.log "behaviour" , "PASS;Operation print_recordings executed successfully.;#{ identity };print_recordings;"
111
+
112
+ return ret
113
+
114
+ end
115
+
116
+ # enable hooking for performance measurement & debug logging
117
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
118
+
119
+
120
+ end # Record
121
+
122
+ end
123
+
124
+ end # MobyBase
@@ -0,0 +1,283 @@
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 TDriver.
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 MobyBehaviour
21
+
22
+ module QT
23
+
24
+ # == description
25
+ # ScreenCapture specific behaviours
26
+ #
27
+ # == behaviour
28
+ # QtScreenCapture
29
+ #
30
+ # == requires
31
+ # testability-driver-qt-sut-plugin
32
+ #
33
+ # == input_type
34
+ # *
35
+ #
36
+ # == sut_type
37
+ # QT
38
+ #
39
+ # == sut_version
40
+ # *
41
+ #
42
+ # == objects
43
+ # *
44
+ #
45
+ module ScreenCapture
46
+
47
+ include MobyBehaviour::QT::Behaviour
48
+
49
+ # == description
50
+ # Captures an object to a file. This can be used on widget or the whole application
51
+ # == arguments
52
+ # format
53
+ # String
54
+ # description: Image format for output file (currently only PNG supported)
55
+ # example: "PNG"
56
+ # default: "PNG"
57
+ #
58
+ # file_name
59
+ # String
60
+ # description: Filename of output image with/without absolute or relative path.
61
+ # example: output_image.png
62
+ # example: my_relative_folder/output_image.png
63
+ # example: c:/my_windows_folder/output_image.png
64
+ # example: ~/my_linux_folder/output_image.png
65
+ # default: nil
66
+ #
67
+ # draw
68
+ # Boolean
69
+ # description: When set to true repaint signal is sent to object before capturing the bitmap.
70
+ # example: true
71
+ # default: false
72
+ #
73
+ # == returns
74
+ # String
75
+ # description: Image binary
76
+ # example: File.open("image.PNG", 'wb:binary') { |f2| f2.puts @screen_capture_data }
77
+ #
78
+ # == exceptions
79
+ # TestObjectNotFoundError
80
+ # description: If a graphics item is not visible on screen
81
+ # ArgumentError
82
+ # description: If the text is not a string.
83
+ #
84
+ def capture_screen( format = "PNG", file_name = nil, draw = false )
85
+
86
+ ret = nil
87
+
88
+ begin
89
+
90
+ # convert string representation of draw value to boolean
91
+ draw = ( draw.downcase == 'true' ? true : false ) if draw.kind_of?( String )
92
+
93
+ # verify that image format is type of string
94
+ Kernel::raise ArgumentError.new( "Unexpected argument type (%s) for image format, expected %s" % [ format.class, "String" ] ) unless format.kind_of?( String )
95
+
96
+ # verify that filename is type of string
97
+ Kernel::raise ArgumentError.new( "Unexpected argument type (%s) for filename, expected %s" % [ file_name.class, "String" ] ) unless file_name.nil? || file_name.kind_of?( String )
98
+
99
+ # verify that draw flag is type of boolean
100
+ Kernel::raise ArgumentError.new( "Unexpected argument type (%s) for draw flag, expected %s" % [ draw.class, "boolean (TrueClass or FalseClass)" ] ) unless [ TrueClass, FalseClass ].include?( draw.class )
101
+
102
+ command = command_params #in qt_behaviour
103
+ command.command_name( 'Screenshot' )
104
+ command.command_params( 'format'=>format, 'draw' => draw.to_s )
105
+ command.set_require_response( true )
106
+ command.transitions_off
107
+ command.service( 'screenShot' )
108
+
109
+ image_binary = @sut.execute_command( command )
110
+
111
+ File.open(file_name, 'wb:binary'){ | image_file | image_file << image_binary } if ( file_name )
112
+
113
+ rescue Exception => e
114
+
115
+ #MobyUtil::Logger.instance.log "behaviour" , "FAIL;Failed capture_screen with format \"#{format}\", file_name \"#{file_name}\".;#{ identity };capture_screen;"
116
+
117
+ MobyUtil::Logger.instance.log "behaviour" , "FAIL;Failed capture_screen with format \"%s\", file_name \"%s\".;%s;capture_screen;" % [ format, file_name, identity ]
118
+
119
+ Kernel::raise e
120
+
121
+ end
122
+
123
+ #MobyUtil::Logger.instance.log "behaviour" , "PASS;Operation capture_screen executed successfully with format \"#{format}\", file_name \"#{file_name}\".;#{ identity };capture_screen;"
124
+ MobyUtil::Logger.instance.log "behaviour" , "PASS;Operation capture_screen executed successfully with format \"%s\", file_name \"%s\".;%s;capture_screen;" % [ format, file_name, identity ]
125
+
126
+ image_binary
127
+
128
+ end
129
+
130
+
131
+ # == description
132
+ # Searches the SUT screen for the given image and returns top left coordinates if a match is found. Alternatively the search can be limited to only parts of the display by calling this method for a widget.
133
+ #
134
+ # == arguments
135
+ # image_or_path
136
+ # String
137
+ # description: Path to image being searched for. Must not be empty.
138
+ # example: 'image_data/icon_help.png'
139
+ # Magick::Image
140
+ # description: RMagick Image object to be searched for. You must 'require RMagick' in your script prior to using this.
141
+ # example: Magick::Image.read('image_data/icon_help.png').first
142
+ # Magick::ImageList
143
+ # description: RMagick ImageList object where the current image is the one to be searched for. You must 'require RMagick' in your script prior to using this.
144
+ # example: Magick::ImageList.new('image_data/icon_help.png')
145
+ #
146
+ # tolerance
147
+ # Integer
148
+ # description: Integer defining the maximum percentage difference in RGB value when compared to maximum values where two pixels are still considered to be equal.
149
+ # example: 20
150
+ # default: 0
151
+ # == returns
152
+ # Array
153
+ # description: Array containing x and y coordinates as Integers, or nil if the image cannot be found on the screen.
154
+ # example: [24,50]
155
+ # Nil
156
+ # description: The image could not be found
157
+ # example: -
158
+ #
159
+ # == exceptions
160
+ # ArgumentError
161
+ # description: image_or_path was not of one of the allowed image types or a non empty String, or tolerance was not an Integer in the [0,100] range.
162
+ # RuntimeError
163
+ # description: No image could be loaded from the path given in image_or_path
164
+ #
165
+ def find_on_screen( image_or_path, tolerance = 0 )
166
+
167
+ # RuntimeError:: No image could be loaded from the path given in image_or_path
168
+ begin
169
+
170
+ require 'RMagick'
171
+
172
+ Kernel::raise ArgumentError.new("The tolerance argument was not an Integer in the [0,100] range.") unless tolerance.kind_of? Integer and tolerance >= 0 and tolerance <= 100
173
+
174
+ target = nil
175
+
176
+ if image_or_path.kind_of? Magick::Image
177
+
178
+ target = image_or_path
179
+
180
+ elsif image_or_path.kind_of? Magick::ImageList
181
+
182
+ Kernel::raise ArgumentError.new("The supplied ImageList argument did not contain any images.") unless image_or_path.length > 0
183
+ target = image_or_path
184
+
185
+ elsif image_or_path.kind_of? String and !image_or_path.empty?
186
+
187
+ begin
188
+ target = Magick::ImageList.new(image_or_path)
189
+ rescue
190
+ Kernel::raise RuntimeError.new("Could not load target for image comparison from path: \"#{image_or_path.to_s}\".")
191
+ end
192
+
193
+ else
194
+ Kernel::raise ArgumentError.new("The image_or_path argument was not of one of the allowed image types or a non empty String.")
195
+ end
196
+
197
+ begin
198
+ screen = Magick::Image.from_blob(capture_screen){ self.format = "PNG" }.first
199
+ screen.fuzz = tolerance.to_s + "%"
200
+ rescue
201
+ Kernel::raise RuntimeError.new("Failed to capture SUT screen for comparison. Details:\n" << $!.message)
202
+ end
203
+
204
+ result = screen.find_similar_region( target )
205
+
206
+ rescue Exception => e
207
+
208
+ MobyUtil::Logger.instance.log "behaviour",
209
+ "FAIL;Failed when searching for image on the screen.;#{ identity };find_on_screen;#{(image_or_path.respond_to?(:filename) ? image_or_path.filename : image_or_path.to_s)},#{tolerance.to_s}"
210
+
211
+ Kernel::raise e
212
+
213
+ end
214
+
215
+ MobyUtil::Logger.instance.log "behaviour",
216
+ "PASS;Image search completed successfully.;#{ identity };find_on_screen;#{(image_or_path.respond_to?(:filename) ? image_or_path.filename : image_or_path.to_s)},#{tolerance.to_s}"
217
+
218
+ result
219
+
220
+ end
221
+
222
+ # == description
223
+ # Verifies if the given image is found on the device screen. Alternatively the verification can be limited to only parts of the display by calling this method for a widget.
224
+ #
225
+ # == arguments
226
+ # image_or_path
227
+ # String
228
+ # description: Path to image being searched for. Must not be empty.
229
+ # example: 'image_data/icon_help.png'
230
+ # Magick::Image
231
+ # description: RMagick Image object to be searched for. You must 'require RMagick' in your script prior to using this.
232
+ # example: Magick::Image.read('image_data/icon_help.png').first
233
+ # Magick::ImageList
234
+ # description: RMagick ImageList object where the current image is the one to be searched for. You must 'require RMagick' in your script prior to using this.
235
+ # example: Magick::ImageList.new('image_data/icon_help.png')
236
+ #
237
+ # tolerance
238
+ # Integer
239
+ # description: Integer defining the maximum percentage difference in RGB value when compared to maximum values where two pixels are still considered to be equal.
240
+ # example: 20
241
+ # default: 0
242
+ #
243
+ # == returns
244
+ # Boolean
245
+ # description: true if the given image is found on the device screen.
246
+ # description: false if the image was not found on the screen.
247
+ # example: true
248
+ #
249
+ # == exceptions
250
+ # ArgumentError
251
+ # description: image_or_path was not of one of the allowed image types or a non empty String, or tolerance was not an Integer in the [0,100] range.
252
+ # RuntimeError
253
+ # description: No image could be loaded from the path given in image_or_path
254
+ def screen_contains?( image_or_path, tolerance = 0 )
255
+
256
+ begin
257
+ # find_on_screen returns nil if the image is not found on the device screen
258
+ result = !find_on_screen(image_or_path, tolerance).nil?
259
+ rescue Exception => exc
260
+
261
+ MobyUtil::Logger.instance.log "behaviour",
262
+ "FAIL;Failed when searching for image on the screen.;#{ identity };screen_contains?;#{(image_or_path.respond_to?(:filename) ? image_or_path.filename : image_or_path.to_s)},#{tolerance.to_s}"
263
+
264
+ Kernel::raise exc
265
+
266
+
267
+ end
268
+
269
+ MobyUtil::Logger.instance.log "behaviour",
270
+ "PASS;Image search completed successfully.;#{ identity };screen_contains?;#{(image_or_path.respond_to?(:filename) ? image_or_path.filename : image_or_path.to_s)},#{tolerance.to_s}"
271
+
272
+ result
273
+
274
+ end
275
+
276
+ # enable hooking for performance measurement & debug logging
277
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
278
+
279
+
280
+ end
281
+
282
+ end
283
+ end