Monday, October 10, 2011

Dictionary Object


Scripts often retrieve information from an outside source, such as a text file or a Database. After this information has been retrieved, it needs to be stored in Memory so that the script can act upon it. Information such as this can be stored Dictionary object.

The Dictionary object functions stores values in key-item pairs. The Dictionary object is similar to a Collection object .Like an array or a Collection object, Dictionary object holds elements, called items or members, containing data. A Dictionary object can contain any data whatsoever, including objects and other Dictionary objects. Access the value of these dictionary items by using unique keys (or named values) that are stored along with the data. Dictionary is a COM object.
Creating Dictionary
Set oDictionary = CreateObject("Scripting.Dictionary")
Adding Key-Item Pairs to a Dictionary
Set oDictionary = CreateObject("Scripting.Dictionary")
oDictionary.Add "Fax", "Faxing"
Here the Key is Fax and Key Value is Faxing

Descriptive Programming:QTP


As I described earlier that how QTP identifies test objects during execution.

The answer is simple that during run time it recognize the test object by referring to its object repository ,where we already have stored test object earlier(before creating any test we must make QTP to learn all the test required test object and store it in object repository).

Now the Question is the application is not ready then there is no test object available, then how QTP will learn the test objects and what will we store in the object repository??

Now answer may be the one of the following or all
    1)    It is impossible to automate any application which is not ready.
    2)    QTP cannot work without Object repository.
    3)  What QTP will learn and where will it store.

But all of the above answers are totally wrong J

There is concept/technique which is known as Descriptive Programming is the solution for those.
If we are using object repository then during the run session, QTP finds the object in the object repository based on its name and parent objects, and uses the stored test object description for that test object to identify the object in the application.
We can also instruct QTP to perform operations on objects without referring to the object repository or to the object's name. To do this, we provide QTP with a list of properties and values that QTP can use to identify the object or objects on which we want to perform an operation. This technique is known as Descriptive Programming (inserting programming descriptions).
There are two types of programmatic descriptions:
<!Static. List the set of properties and values that describe the object directly in a VBScript statement
       Synatx:  Testobj(“Propname1:=PropVal1” , “Propname2:=PropVal2”)
              TestObject. The test object class.
            PropertyName:=PropertyValue. The identification property and its value.
            Each   property:=value pair should be separated by commas and quotation marks

Example :
  Browser("Title:=Mercury Tours").Page("Title:=Mercury Tours").WebEdit("Name:=Author",   "Index:=3").Set "Alok"
2) Dynamic.  Add a collection of properties and values to a Description object, and then enter the Description object name in the statement.
The Dynamic type provides more power, efficiency, and flexibility.
We can use the Description object to return a Properties collection object containing a set of Property objects. A Property object consists of a property name and value. We can then specify the returned Properties collection in place of an object name in a statement. (Each property object contains a property name and value pair.)
To create the Properties collection, you enter a Description. Create statement using the following syntax:
Set MyDescription = Description.Create()
Example:
Set Objbtn = Description.Create()
Objbtn(“value”).Value =  Google Search”
Objbtn(“type”).Value = “submit”
Browser(“Google”).Page(“Google”).WebButton(Objbtn).Click
Note: For getting the object properties and their values respectively please refer the Object Spy section described in earlier posts http://expertqtp.blogspot.com/2011/05/object-spy-in-qtp.html