cutedriver-qt-sut-plugin 2.0.0.20210120165900
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/env.rb +24 -0
- data/installer/extconf.rb +62 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin.rb +23 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/action.rb +157 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/application.rb +312 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/attribute.rb +300 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/behaviour.rb +214 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/configure_behaviour.rb +317 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/cute_cpu.rb +145 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/cute_gpu.rb +147 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/cute_mem.rb +142 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/cute_pwr.rb +146 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/events.rb +192 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/file_transfer.rb +375 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/find.rb +82 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/fixture.rb +214 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/fps.rb +189 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/gesture.rb +1039 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/infologger.rb +767 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/key_press.rb +166 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/locale_db.rb +157 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/method.rb +112 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/multitouch.rb +474 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/os.rb +100 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/qt_api_method.rb +148 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/record.rb +134 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/screen_capture.rb +279 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/settings.rb +302 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/sut.rb +840 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/synchronization.rb +257 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/treewidgetitemcolumn.rb +117 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/type_text.rb +97 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/view_item.rb +97 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/webkit.rb +272 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/widget.rb +877 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/action.rb +30 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/configure_command.rb +38 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/drag.rb +44 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/find_object.rb +67 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/group.rb +44 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/infologger_command.rb +38 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/qt.rb +171 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/tap.rb +54 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/version.rb +34 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/widget.rb +199 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/agent.rb +54 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/application.rb +192 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/configure_command.rb +53 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/find_object.rb +48 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/fixture.rb +65 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/group.rb +57 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/infologger_command.rb +53 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/key_sequence.rb +93 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/screen_capture.rb +53 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/tap.rb +62 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/version.rb +46 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/widget.rb +98 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/plugin.rb +200 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/adapter.rb +466 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/communication.rb +185 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/controller.rb +69 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/util/find_object_generator.rb +287 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/util/fixture_parameter.rb +77 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/util/message_composer.rb +370 -0
- data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/util/widget.rb +79 -0
- data/lib/testability-driver-qt-sut-plugin.rb +24 -0
- data/xml/behaviour/qt.xml +845 -0
- data/xml/defaults/sut_qt.xml +9 -0
- data/xml/keymap/qt.xml +321 -0
- data/xml/keymap/win.xml +174 -0
- data/xml/template/qt.xml +141 -0
- metadata +127 -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
|
+
# force_refresh
|
64
|
+
# rescue Exception => e
|
65
|
+
# $logger.behaviour "FAIL;Failed open_file with path \"#{path}\", dialog_name \"#{dialog_name}\", button \"#{button.to_s}\".;#{identity};open_file;"
|
66
|
+
# raise e
|
67
|
+
# end
|
68
|
+
# $logger.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
|
+
execute_command( MobyCommand::WidgetCommand.new( nil, nil, nil, 'PressEnter', params, nil, 'uiCommand') )
|
87
|
+
rescue Exception => e
|
88
|
+
$logger.behaviour "FAIL;Failed to send an Enter keystroke request to the qttas server;press_enter;"
|
89
|
+
raise e
|
90
|
+
end
|
91
|
+
$logger.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
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/qt_api_method.rb
ADDED
@@ -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
|
+
raise ArgumentError.new("Invalid argument type for type. (Actual: %s, Expected: String)" % [ type.class.to_s ] ) unless type.kind_of?( String )
|
32
|
+
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
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::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
|
+
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
|
+
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
|
+
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
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::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
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
@@ -0,0 +1,134 @@
|
|
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
|
+
# == nodoc
|
50
|
+
# == returns
|
51
|
+
# NilClass
|
52
|
+
# description: -
|
53
|
+
# example: -
|
54
|
+
def start_recording
|
55
|
+
|
56
|
+
begin
|
57
|
+
|
58
|
+
command = plugin_command() #in qt_behaviour
|
59
|
+
command.command_name( 'Start' )
|
60
|
+
command.service( 'recordEvents' )
|
61
|
+
@sut.execute_command( command)
|
62
|
+
|
63
|
+
rescue Exception => e
|
64
|
+
|
65
|
+
$logger.behaviour "FAIL;Failed start_recording.;#{ identity };start_recording;"
|
66
|
+
raise e
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
$logger.behaviour "PASS;Operation start_recording executed successfully.;#{ identity };start_recording;"
|
71
|
+
|
72
|
+
nil
|
73
|
+
end
|
74
|
+
|
75
|
+
# == nodoc
|
76
|
+
# == returns
|
77
|
+
# NilClass
|
78
|
+
# description: -
|
79
|
+
# example: -
|
80
|
+
def stop_recording
|
81
|
+
|
82
|
+
begin
|
83
|
+
|
84
|
+
command = plugin_command() #in qt_behaviour
|
85
|
+
command.command_name( 'Stop' )
|
86
|
+
command.service( 'recordEvents' )
|
87
|
+
@sut.execute_command( command)
|
88
|
+
|
89
|
+
rescue Exception => e
|
90
|
+
|
91
|
+
$logger.behaviour "FAIL;Failed stop_recording.;#{ identity };stop_recording;"
|
92
|
+
raise e
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
$logger.behaviour "PASS;Operation stop_recording executed successfully.;#{ identity };stop_recording;"
|
97
|
+
|
98
|
+
nil
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
# == nodoc
|
103
|
+
def print_recordings
|
104
|
+
|
105
|
+
ret = nil
|
106
|
+
|
107
|
+
begin
|
108
|
+
|
109
|
+
command = plugin_command(true) #in qt_behaviour
|
110
|
+
command.command_name( 'Print' )
|
111
|
+
command.service( 'recordEvents' )
|
112
|
+
ret = @sut.execute_command( command )
|
113
|
+
|
114
|
+
rescue Exception => e
|
115
|
+
|
116
|
+
$logger.behaviour "FAIL;Failed print_recordings.;#{ identity };print_recordings;"
|
117
|
+
raise e
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
$logger.behaviour "PASS;Operation print_recordings executed successfully.;#{ identity };print_recordings;"
|
122
|
+
|
123
|
+
return ret
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
# enable hooking for performance measurement & debug logging
|
128
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
129
|
+
|
130
|
+
end # Record
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
end # MobyBase
|
data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/screen_capture.rb
ADDED
@@ -0,0 +1,279 @@
|
|
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
|
+
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
|
+
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
|
+
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
|
+
#$logger.behaviour "FAIL;Failed capture_screen with format \"#{format}\", file_name \"#{file_name}\".;#{ identity };capture_screen;"
|
116
|
+
|
117
|
+
$logger.behaviour "FAIL;Failed capture_screen with format \"%s\", file_name \"%s\".;%s;capture_screen;" % [ format, file_name, identity ]
|
118
|
+
|
119
|
+
raise e
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
#$logger.behaviour "PASS;Operation capture_screen executed successfully with format \"#{format}\", file_name \"#{file_name}\".;#{ identity };capture_screen;"
|
124
|
+
$logger.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
|
+
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
|
+
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
|
+
raise RuntimeError.new("Could not load target for image comparison from path: \"#{image_or_path.to_s}\".")
|
191
|
+
end
|
192
|
+
|
193
|
+
else
|
194
|
+
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
|
+
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
|
+
$logger.behaviour "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}"
|
209
|
+
|
210
|
+
raise e
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
$logger.behaviour "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}"
|
215
|
+
|
216
|
+
result
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
# == description
|
221
|
+
# 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.
|
222
|
+
#
|
223
|
+
# == arguments
|
224
|
+
# image_or_path
|
225
|
+
# String
|
226
|
+
# description: Path to image being searched for. Must not be empty.
|
227
|
+
# example: 'image_data/icon_help.png'
|
228
|
+
# Magick::Image
|
229
|
+
# description: RMagick Image object to be searched for. You must 'require rmagick' in your script prior to using this.
|
230
|
+
# example: Magick::Image.read('image_data/icon_help.png').first
|
231
|
+
# Magick::ImageList
|
232
|
+
# 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.
|
233
|
+
# example: Magick::ImageList.new('image_data/icon_help.png')
|
234
|
+
#
|
235
|
+
# tolerance
|
236
|
+
# Integer
|
237
|
+
# description: Integer defining the maximum percentage difference in RGB value when compared to maximum values where two pixels are still considered to be equal.
|
238
|
+
# example: 20
|
239
|
+
# default: 0
|
240
|
+
#
|
241
|
+
# == returns
|
242
|
+
# Boolean
|
243
|
+
# description: true if the given image is found on the device screen.
|
244
|
+
# description: false if the image was not found on the screen.
|
245
|
+
# example: true
|
246
|
+
#
|
247
|
+
# == exceptions
|
248
|
+
# ArgumentError
|
249
|
+
# 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.
|
250
|
+
# RuntimeError
|
251
|
+
# description: No image could be loaded from the path given in image_or_path
|
252
|
+
def screen_contains?( image_or_path, tolerance = 0 )
|
253
|
+
|
254
|
+
begin
|
255
|
+
# find_on_screen returns nil if the image is not found on the device screen
|
256
|
+
result = !find_on_screen(image_or_path, tolerance).nil?
|
257
|
+
rescue Exception => exc
|
258
|
+
|
259
|
+
$logger.behaviour "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}"
|
260
|
+
|
261
|
+
raise exc
|
262
|
+
|
263
|
+
|
264
|
+
end
|
265
|
+
|
266
|
+
$logger.behaviour "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}"
|
267
|
+
|
268
|
+
result
|
269
|
+
|
270
|
+
end
|
271
|
+
|
272
|
+
# enable hooking for performance measurement & debug logging
|
273
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
274
|
+
|
275
|
+
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|
279
|
+
end
|