Sunday, September 22, 2019

13.3 ChildObjects Method


What is the ChildObjects Method ?

You can use the ChildObjects method to retrieve all objects located inside a specified parent object or only those child objects that fit a certain programmatic description. To retrieve this subset of child objects, you first create a description object, and then you add the set of properties and values that you want your child object collection to match using the Description object.

The objects contained in a window or frame are textbox, combo box and link. The window or frame is the Parent Object and the frame or textbox are the ChildObjects.

Syntax – object.ChildObjects(Description) – Description is required for Mobile ADD In and optional for all others.

Points To Remember

      1. Insight Objects do not support ChildObjects method
      2. Android objects are supported and related properties are supported – class, nativeclass, resourceid, text

1. The following script gets the name of all the links from a page -:

Dim oDesc
Set oDesc = Description.Create
oDesc("micclass").value = "Link"

'Find all the Links
Set obj = Browser("Math Calculator").Page("Math Calculator").ChildObjects(oDesc)

Dim i
'obj.Count value has the number of links in the page

For i = 0 to obj.Count - 1                              
   'get the name of all the links in the page
   x = obj(i).GetROProperty("innerhtml") 
   print x 
Next



2. The following script gets the number of Checkboxes with the HTML tag as INPUT and sets all those checkboxes as ON.

Set MyDescription = Description.Create()
MyDescription("html tag").Value = "INPUT"
MyDescription("type").Value = "checkbox"
Set Checkboxes = Browser("Itinerary").Page("Itinerary").ChildObjects(MyDescription)
NoOfChildObjs = Checkboxes.Count
For Counter=0 to NoOfChildObjs-1
        Checkboxes(Counter).Set "ON"
Next


13.2 CheckProperty Method






Description

Checks whether the actual value of the specified object property matches the specified expected value within the specified timeout.

Syntax

Object.CheckProperty(PropertyName,PropertyValue,[TimeOut])


PropertyName - Required. A String value. The name of the property whose value is checked. The available properties are listed in the description properties page under each test object.


PropertyValue - Required. A Variant.
The expected value against which the actual property value should be checked. You can either use a simple value or you can use a comparison object together with the value to perform more complex comparisons.
Example to Show the implementation of CheckProperty
'The following example uses the CheckProperty method to check whether
'the text "Mercury" is entered in the "Name" edit box.
 
Browser("Nested Lists").Page("Page").WebEdit("Name").Set "Mercury"
Browser("Nested Lists").Page("Page").WebEdit("Name").CheckProperty "value", "Mercury"
TimeOut - Optional. An unsigned long integer value.
The time, in milliseconds, within which UFT should check whether the actual value of the property matches the specified expected value. If no value is specified, UFT uses the time set in the Object Synchronization Timeout option in the Run pane of the Test Settings dialog box.
Default value = 60


Return Type A Boolean value. Returns TRUE if the property achieves the value, and FALSE if the timeout is reached before the property achieves the value.
A TRUE return value reports a Passed step to the run results; a FALSE return value reports a Failed step to the run results.
You can also use comparison objects to perform more complex value comparisons. For example, you can instruct UFT to check whether a specific property value is greater than the specified value.
An example of the syntax required when using a comparison object is: Object.CheckProperty "items count",micGreaterThan(8)
The following comparison objects can be used:
  • micGreaterThan: Greater than; Specifies that UFT checks whether the property value is greater than the specified value.
  • MicLessThan: Less than; Specifies that UFT checks whether the property value is less than the specified value.
  • MicGreaterThanOrEqual: Greater than or equal to; Specifies that UFT checks whether the property value is greater than or equal to the specified value.
  • MicLessThanOrEqual: Less than or equal to; Specifies that UFT checks whether the property value is less than or equal to the specified value.
  • MicNotEqual: Not equal to; Specifies that UFT checks whether the property value is not equal to the specified value.
  • MicRegExpMatch: Regular expression; Specifies that UFT checks whether the property value achieves a regular expression match with the specified value. Regular expressions are case-sensitive and must match exactly. For example, 'E.*h' matches 'Earth' but not 'The Earth' or 'earth'.


When the types of the expected value and actual value do not match, the comparisons are performed as follows (in this order):
  • Empty values: Empty values may be an uninitialized variable or field (which returns TRUE for the IsNull function in VBscript) or initialized to an empty value (which returns TRUE for the IsEmpty function is VBscript). When trying to compare two arguments when at least one is an empty value, the comparison assumes equality for two uninitialized arguments and for two empty arguments. Any other combination is considered unequal.
    For example:
    dim vEmpty
    Object.CheckProperty "text",micNotEqual
    (vEmpty)
    will not wait for the timeout (because the 'text' property value is an empty string and the argument passed to micNotEqual is an empty value and so micNotEqual finds them not equal and returns TRUE).
  • String values: When trying to compare a string value with non-string value, the string value is converted to the non-string type and then compared. If the string value cannot be converted to the non-string type, the comparison assumes the values are not equal.
    For example:
    Object.CheckProperty "text",micGreaterThan(8) will not wait for the timeout if the 'text' property value is '16' (because micGreaterThan finds 16 to be greater than 8 and returns TRUE), but will wait if the 'text' property value is 'a' (because 'a' cannot be converted to a number).
  • Boolean values: When trying to compare a Boolean value with non-boolean value, the non-boolean value is converted to a boolean value and then compared. The conversion method assumes that any integer value other than '0' is TRUE, and that '0' alone is FALSE. If the conversion fails to produce a boolean value (for example, if the value is 'abc'), the comparison result will be FALSE (note that for the WaitProperty method this result would instruct UFT to keep waiting). If the conversion succeeds, the method compares the two boolean values according to the comparison logic.
  • Other value types: When other value types do not match, they are compared under the assumption that different types are not equal (nor greater than or less than each other).



13.1 CaptureBitmap Method





What is the function of CaptureBitmap method?

The function of CaptureBitmap method is to save a screen capture of the mentioned object as .bmp or .png file, with a specified name and at a specified path.


Syntax -: object.CaptureBitmap(FullFileName,[OverrideExisting])

Parameters – 1. FullFileName – Required. A String value.
            1. OverrideExisitng - A boolean value. Default value is False.


Return Type – None

Capture an image to the Results Folder

'The following example uses the CaptureBitmap method to capture
 'a screen shot of the No. of Passengers edit box. The file will
 'automatically be saved to a different folder (the test run
 'results folder) in each test run.

 Browser("Mercury Tours").Page("Find  Flights").WebEdit("numPassengers").CaptureBitmap "edit_4.bmp"
Capture an image to an Absolute Folder Path.

'The following example uses the CaptureBitmap method to capture
 'a screen shot of the No. of Passengers edit box and save the
 'image to an absolute path. Each time the CaptureBitmap statement
 'runs, UFT overwrites the previous image with the new one.

 Browser("Mercury Tours").Page("Find  Flights").WebEdit("numPassengers").CaptureBitmap "C:\ScreenCaps\edit_4.bmp", True

Capture an image and upload it to the Database

'The following example uses the CaptureBitmap method to capture an image, after which the image is
 'uploaded to the database.
 Browser("Browser").Page("The official site for").Image("PURE NEW  ZEALAND").CaptureBitmap ("c:\NewZealand.bmp")
 UploadImageToDataBase ("c:\NewZealand.bmp")