Module: MobyBehaviour::TestObject
- Defined in:
- lib/tdriver/base/test_object/behaviours/test_object.rb
Overview
description
Describes the generic behaviour of TestObject, common methods that can be used to control TestObject
behaviour
GenericTestObject
requires
*
input_type
*
sut_type
*
sut_version
*
objects
*
Instance Attribute Summary collapse
-
#creation_attributes ⇒ Object
nodoc == description attr_accessor == returns Hash description: Hash containing the identification attributes that were used when the test object was created.
Instance Method Summary collapse
-
#[](name = nil) ⇒ Object
description Wrapper method to returns one or all test object attributes.
-
#activate ⇒ Object
nodoc == description Changes the status of the test object to active == returns TrueClass:: == example @app.Node( :name => ‘Node1’ ).activate() # activate given object.
-
#attribute(name) ⇒ Object
description Function returns a attribute of test object.
-
#attributes ⇒ Object
description Return all test object attributes.
-
#child(attributes) ⇒ Object
description Creates a child test object of this test object.
-
#children(attributes, find_all_children = true) ⇒ Object
description Function similar to child, but returns an array of children test objects that meet the given criteria.
-
#force_refresh(refresh_args = nil) ⇒ Object
nodoc Function refreshes test objects to correspond with the current state of the device, forcing the sut to request a new XML dump from the device.
-
#get_application ⇒ Object
description Function for finding out the application this test ojbect == returns MobyBase::TestObject description: Application test object that the test object belongs to, or nil, if no parent of type application can be found.
-
#get_application_id ⇒ Object
nodoc == description Function for finding out the application id for this test object == returns String:: representing the id of the application test object that this test object belongs to.
-
#get_parent ⇒ Object
description Returns the parent test object for the current object in question, according to the UI object hierarchy.
-
#parent_object ⇒ Object
deprecated 0.8.x.
-
#refresh(refresh_args = {}) ⇒ Object
nodoc Function refreshes test objects to correspond with the current state of the device.
-
#set_application_id(application_id) ⇒ Object
nodoc.
-
#state ⇒ Object
deprecated 1.1.1.
-
#state_object ⇒ Object
description Returns a StateObject containing the current state of this test object as XML.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *method_arguments) ⇒ Object (private)
TODO: document me Tries to use the missing method id as a child object type and find an object based on it
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 673 def method_missing( method_id, *method_arguments ) # create rules hash rules_hash = method_arguments.first # set rules hash to empty Hash if rules hash is not type of Hash unless rules_hash.kind_of?( Hash ) # pass empty rules hash if no argument given, otherwise assume value to be object name if rules_hash.blank? rules_hash = {} else rules_hash = { :name => rules_hash } end end # set test object type rules_hash[ :type ] = method_id.to_s begin # return created child object child( rules_hash ) rescue MobyBase::TestObjectNotFoundError, MobyBase::TestObjectNotVisibleError rules_hash_clone = rules_hash.clone # remove type attribute from hash rules_hash_clone.delete(:type) # string representation of used rule hash, remove curly braces attributes_string = rules_hash_clone.inspect[ 1 .. -2 ] if attributes_string.empty? # do not show any attribute details if none given attributes_string = "" else # show used attributes attributes_string = " (attributes #{ attributes_string })" end # raise slightly different exception message when receiver test object is type of application if application? = "The application (id: #{ @id }, name: #{ @name.inspect }) has no child object with type or behaviour method with name #{ method_id.to_s.inspect }#{ attributes_string } on #{ @sut.id.inspect }" else = "The test object (id: #{ @id }, type: #{ @type.inspect }, name: #{ @name.inspect }) has no child object with type or behaviour method with name #{ method_id.to_s.inspect }#{ attributes_string } on #{ @sut.id.inspect }" end # raise exception raise MobyBase::TestObjectNotFoundError, end end |
Instance Attribute Details
#creation_attributes ⇒ Object
nodoc
description
attr_accessor
returns
Hash
description: Hash containing the identification attributes that were used when the test object was created.
example: { :name => 'Triangle1', :type => :Triangle }
52 53 54 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 52 def creation_attributes @creation_attributes end |
Instance Method Details
#[](name = nil) ⇒ Object
description
Wrapper method to returns one or all test object attributes. This method calls [link=“#GenericTestObject:attribute”]attribute or [link=“#GenericTestObject:attributes”]attributes depending on the given argument.
arguments
name
String
description: Attribute name
example: "attribute_name"
NilClass
description: Return all attributes
example: nil
returns
String
description: Value of the attribute
example: "value"
Hash
description: Hash of all attributes
example: {:x=>"0", :y=>"0"}
222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 222 def []( name = nil ) if name.nil? attributes else attribute( name ) end end |
#activate ⇒ Object
nodoc
description
Changes the status of the test object to active
returns
- TrueClass
-
example
@app.Node( :name => ‘Node1’ ).activate() # activate given object
84 85 86 87 88 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 84 def activate @_active = true end |
#attribute(name) ⇒ Object
description
Function returns a attribute of test object. Please see [link=“#GenericTestObject:[][/link] method for alternative approach.
arguments
name
String
description: String defining the name of the attribute to get
example: "name"
returns
String
description: Value of the attribute as a string
example: "value"
exceptions
TestObjectNotInitializedError
description: if the test object xml data has not been initialized
AttributeNotFoundError
description: if the requested attribute can not be found in the xml data of the object
example
puts @test_app.Triangle( :name => ‘Triangle1’ ).attribute(‘color’) # prints color of triangle object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 186 def attribute( name ) # TODO: add behaviour logging? # raise exception if attribute name variable type is other than string name.check_type( [ String, Symbol ], "wrong argument type $1 for attribute (expected $2)" ) # convert name to string if variable type is symbol name = name.to_s if name.kind_of?( Symbol ) # retrieve attribute value find_attribute( name ) end |
#attributes ⇒ Object
description
Return all test object attributes. Please see [link=“#GenericTestObject:[][/link] method for alternative approach.
returns
Hash
description: Test object attributes
example: {"localeLanguage"=>"English", "startDragDistance"=>"4", "windowIcon"=>"", "memUsage"=>"25669"}
example
attributes_hash = @test_app.Triangle( :name => ‘Triangle1’ ).attributes # retrieve all attribute for triangle object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 113 def attributes # retrieve sut attribute filter type filter_type = sut_parameters[ :filter_type, 'none' ] # temporarly disable attribute filter to retrieve all test object attributes sut_parameters[ :filter_type ] = 'none' begin # raise exception to refresh test object ui state if filter_type was something else than 'none' raise MobyBase::TestObjectNotFoundError unless filter_type == 'none' # retrieve xml data, performs xpath to sut xml_data _xml_data = xml_data rescue MobyBase::TestObjectNotFoundError # attributes used to refresh parent application if @creation_attributes[ :type ] == 'application' # use application name and id attributes refresh_args = { :name => @creation_attributes[ :name ], :id => @creation_attributes[ :id ] } else # test object if not type of application refresh_args = { :id => get_application_id } end #lets refresh if attribute not found on first attempt refresh( refresh_args ) # retrieve updated xml data _xml_data = xml_data ensure # restore attributes filter type sut_parameters[ :filter_type ] = filter_type end # return hash of test object attributes @test_object_adapter.test_object_attributes( _xml_data ) end |
#child(attributes) ⇒ Object
description
Creates a child test object of this test object. Caller object will be associated as child test objects parent.n n
- b]NOTE:[/b
-
Subsequent calls to TestObject#child( rule ) always returns reference to same Testobject:n
[code]a = to.child( :type => ‘Button’, :text => ‘1’ ) b = to.child( :type => ‘Button’, :text => ‘1’ ) a.eql?( b ) # => true n
- b]NOTE:[/b
-
If the parameter ‘use_find_object’ in tdriver_parameters.xml is true (default), objects with visibleOnScreen value ‘false’ might be
optimized out and not appear in the results. n
arguments
attributes
Hash
description: Hash object holding information for identifying which child to create
example: { :type => :slider }
returns
MobyBase::TestObject
description: new child test object or reference to existing child
example: -
exceptions
TypeError
description: Wrong argument type <class> for attributes (expected Hash)
MultipleTestObjectsIdentifiedError
description: raised if multiple objects found that match the given attributes
TestObjectNotFoundError
description: raised if the child object could not be found
TestObjectNotVisibleError
description: rasied if the parent test object is no longer visible
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 482 def child( attributes ) # verify attributes argument format attributes.check_type [ Hash, String, Symbol, Regexp, Array ], "wrong argument type $1 for attributes (expected $2)" # set rules hash to empty Hash if rules hash is not type of Hash unless attributes.kind_of?( Hash ) # pass empty rules hash if no argument given, otherwise assume value to be object name if attributes.blank? attributes = {} else attributes = { :name => attributes } end end get_child_objects( attributes ) end |
#children(attributes, find_all_children = true) ⇒ Object
description
Function similar to child, but returns an array of children test objects that meet the given criteria. nn
- b]NOTE:[/b
-
If the parameter ‘use_find_object’ in tdriver_parameters.xml is true (default), objects with visibleOnScreen value ‘false’ might be
optimized out and not appear in the results.
arguments
attributes
Hash
description: object holding information for identifying which child to create
example: { :type => :slider }
find_all_children
TrueClass
description: Boolean specifying whether all children under the test node or just immediate children should be retreived
example: true
FalseClass
description: Boolean specifying whether all children under the test node or just immediate children should be retreived
example: false
returns
Array
description: An array of test objects
example: [ MobyBase::TestObject, MobyBase::TestObject, MobyBase::TestObject, ... ]
exceptions
TypeError
description: raised if agument is not a Hash
TestObjectNotFoundError
description: raised if the child object could not be found
TestObjectNotVisibleError
description: rasied if the parent test object is no longer visible
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 541 def children( attributes, find_all_children = true ) # verify attributes argument format attributes.check_type( Hash, "wrong argument type $1 for attributes (expected $2)" ) # verify find_all_children argument format find_all_children.check_type( [ TrueClass, FalseClass ], "wrong argument type $1 for find_all_children (expected $2)" ) # If empty or only special attributes then add :type => '*' to search all attributes[ :type ] = '*' if attributes.select{ | key, value | key.to_s !~ /^__/ ? true : false }.empty? # children method specific settings attributes.merge!( :__multiple_objects => true, :__find_all_children => find_all_children, :__no_caching => true ) # disable optimizer state if enabled #disable_optimizer -> leave it on, tuukka if breaks take it back... # retrieve child objects result = get_child_objects( attributes ) # restore optimizer state if it was enabled #enable_optimizer # return results result end |
#force_refresh(refresh_args = nil) ⇒ Object
nodoc
Function refreshes test objects to correspond with the current state of the device, forcing the sut to request a new XML dump from the device.
NOTE:
@sut#force_refresh will call update method for this TestObject, if state has changed. Thus, calling
raises
- TestObjectNotFoundError
-
if TestObject is not identified within synch timeout.
342 343 344 345 346 347 348 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 342 def force_refresh( refresh_args = nil ) refresh_args = @creation_attributes if refresh_args.nil? refresh( refresh_args ) end |
#get_application ⇒ Object
description
Function for finding out the application this test ojbect
returns
MobyBase::TestObject
description: Application test object that the test object belongs to, or nil, if no parent of type application can be found.
example: -
example
parent_app = @app.Node( :name => ‘Node1’ ).get_application() #get application for some test object, this should return @app.
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 358 def get_application # test object should have @parent_application always return @parent_application if @parent_application # workaround: fetch application from sut, this part of code should not be executed ever return self if application? test_object = @parent while test_object return test_object if ( test_object.type == 'application' ) test_object = test_object.parent end # return application object or nil if no parent found # Does is make sense to return nil - should n't all test objects belong to an application? Maybe throw exception if application not found begin @sut.child( :type => 'application' ) rescue nil end end |
#get_application_id ⇒ Object
nodoc
description
Function for finding out the application id for this test object
returns
- String
-
representing the id of the application test object that this test object belongs to.
example
puts @app.Node( :name => ‘Node1’ ).get_application_id() #print the application id, this should print @app.id
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 397 def get_application_id if @parent_application @parent_application.id else # workaround # What about the case when get_application returns nil? This line will throw an exception in that case. get_application.id end end |
#get_parent ⇒ Object
description
Returns the parent test object for the current object in question, according to the UI object hierarchy. For getting the test object that was actually used as the parent when the test object instance was created, see [link=“#GenericTestObject:parent”]parent method.
returns
TestObject
description: test object that is parent of this test object, self if no parent (ie. application objects)
example: -
example
parent_test_object = @app.Node( :name => ‘Node1’ ).get_parent() #get parent for some test object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 246 def get_parent # return current test object if it's type of application return self if application? @sut.refresh if disable_optimizer # retrieve parent of current xml element; objects/object/objects/object/../.. parent_element = @test_object_adapter.parent_test_object_element( self ) # retrieve parent element attributes parent_attributes = @test_object_adapter.test_object_element_attributes( parent_element ) if get_application_id && parent_attributes[ 'type' ] != 'application' parent = @sut.child( :id => get_application_id, :type => 'application' ).child( :id => parent_attributes[ 'id' ], :name => parent_attributes[ 'name' ], :type => parent_attributes[ 'type' ], # there was a case when the same parent was included twice in the ui dump :__index => 0 ) else parent = @sut.child( :id => parent_attributes[ 'id' ], :name => parent_attributes[ 'name' ], :type => parent_attributes[ 'type' ] ) end enable_optimizer parent end |
#parent_object ⇒ Object
deprecated
0.8.x
description
This method is deprecated, please use TestObject#parent This method is deprecated, please use [link=“#GenericTestObject:parent”]TestObject#parent instead.
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 1012 def parent_object # == description # Returns the actual test object that was used as the parent when this object instance was created. # Userd to retrieve the parent object in the UI object hierarchy, # see get_parent. # # == returns # TestObject:: test object that was used as parent when this object was created. Can also be of type SUT if sut was the parent (ie. application objects) warn_caller '$1:$2 warning: TestObject#parent_object is deprecated, please use TestObject#parent instead.' @parent end |
#refresh(refresh_args = {}) ⇒ Object
nodoc
Function refreshes test objects to correspond with the current state of the device.
NOTE:
@sut#refresh will call update method for this TestObject, if state has changed. Thus, calling
raises
- TestObjectNotFoundError
-
if TestObject is not identified within synch timeout.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 301 def refresh( refresh_args = {} ) refresh_args.check_type Hash, "wrong argument type $1 for #{ application? ? 'application' : 'test object' } refresh attributes (expected $2)" if refresh_args.blank? if application? refresh_args = { :name => @name, :id => @id } else refresh_args = { :name => @parent_application.name, :id => @parent_application.id } end end @sut.refresh( refresh_args, @test_object_factory.make_object_search_params( parent, @creation_attributes ) ) # update childs if required, returns true or false update( xml_data ) unless @sut.use_find_objects nil end |
#set_application_id(application_id) ⇒ Object
nodoc
414 415 416 417 418 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 414 def set_application_id( application_id ) @_application_id = application_id end |
#state ⇒ Object
deprecated
1.1.1
description
This method is deprecated, please use [link=“#GenericTestObject:state_object”]TestObject#state_object instead.
1034 1035 1036 1037 1038 1039 1040 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 1034 def state warn_caller '$1:$2 warning: deprecated method TestObject#state; please use TestObject#state_object instead' state_object end |
#state_object ⇒ Object
description
Returns a StateObject containing the current state of this test object as XML. The state object is static and thus is not refreshed or synchronized etc.
returns
StateObject
description: State of this test object
example: -
exceptions
ArgumentError
description: If the xml source for the object cannot be read
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/tdriver/base/test_object/behaviours/test_object.rb', line 431 def state_object # == example # app_state = @sut.application( :name => "calculator" ).state #get the state object for the app # button_state = app_state.Button( :text => "Backspace" ) #get the state for test object button # button_text = button_state.attribute( "text" ) #get attribute text from the button state object MobyBase::StateObject.new( :source_data => xml_data, :parent => self, :test_object_adapter => @test_object_adapter ) end |