Yes we can use dictionary globally. We can define dictionary object in an external library file and after associating that library file to our test we can access dictionary object across all the actions. Its pretty simple, just what we need to do is define a dictionary object in a notepad. Save is with the extension .vbs and associate that particular file in our test. Now we can perform any operation on dictionary object in any of the actions and it will be visible across all the actions. It means if we add the any item in action1 we can retrieve the value of that item from Action2. It now acts as an global object. Dictionary object is kind of associated array used by QTP. So by this method we can also define global variables which can be used across all the scripts.
Wednesday, 22 April 2015
QTP - 5- Why we use dictionary object in QTP inspite we have a good option of storing data in arrays?
This could be a tricky question by an interviewer. Well lemme take you through the dictionary object and uses. As arrays, the dictionary functionality in QTP is also used to store values , but the difference comes out to be in the datatype. As we know we can only store similar type of data in an array so only same type of object can be stored in arrays on the contrary the QTP has given the flexibility of storing values in key value pair in dictionary. We can store any type of data against any key value in dictionary object.The key value should be unique against each value. One more benefit I can talk about is the indexing, in array we have predefined indexes while in QTP we can give indexes or keys as per our requirement.Its very simple to create a dictionary object and add any values :
> Set Objname = createobject("scripting.ditionary")
Now if we want to add any key value pair to the dictionary we can do as :
> Objname.add "Key","Value"
NOTE : for string datatype we need to put a double quotes "" , but for integer we don't need it.
Similarly we can define multiple dictionary objects.
If we want to count the key and values we can simply use the following command.
> Objname.Count
If we want to see any value against any key we can use the following command :
>objname.item("key name")
If we want to set any new value then :
>Objname.Item("Key Name")= "Key value"
If we want to update any key name
> Objectname.key("key name")= "New Key name"
If we want to get the name of all the keys/items in the dictionary
> arr = Objectname.Keys
> arr =Objectname.Items
further we can apply array Ubound and Lbound methods to display the keys.
If we want to remove any items we can use the following command :
> Objectname.Remove("Key")
and if we want to remove all items from dictionary
>Objectname.RemoveAll
and lastly if we want to check if any item exist or not then we can simply use
> Objectname.Exist("Key")
These are few basic dictionary commands.
> Set Objname = createobject("scripting.ditionary")
Now if we want to add any key value pair to the dictionary we can do as :
> Objname.add "Key","Value"
NOTE : for string datatype we need to put a double quotes "" , but for integer we don't need it.
Similarly we can define multiple dictionary objects.
If we want to count the key and values we can simply use the following command.
> Objname.Count
If we want to see any value against any key we can use the following command :
>objname.item("key name")
If we want to set any new value then :
>Objname.Item("Key Name")= "Key value"
If we want to update any key name
> Objectname.key("key name")= "New Key name"
If we want to get the name of all the keys/items in the dictionary
> arr = Objectname.Keys
> arr =Objectname.Items
further we can apply array Ubound and Lbound methods to display the keys.
If we want to remove any items we can use the following command :
> Objectname.Remove("Key")
and if we want to remove all items from dictionary
>Objectname.RemoveAll
and lastly if we want to check if any item exist or not then we can simply use
> Objectname.Exist("Key")
These are few basic dictionary commands.
Tuesday, 21 April 2015
QTP - 4 - When and Why - ROProperties ??
By word ROProperties refers to the Runtime Object Properties. It seems like we are talking about some objects which are generated in runtime.Yeah....but what are runtime objects ?
Any Web-base application, GUI , Desktop application, mobile applications,etc consists of various objects. What are objects then...Objects are the units of code. Examples of objects are link , editbox , image , etc. So while creating any object the developer thinks of some properties. These properties are called the expected properties of the object. While writing Scripts or while recording the QTP captures the properties of the objects. When the scripting is done and application is stable we exeute the written scrips, it may be done in sanity or regression or before any build. While executing the scripts the objects actual properties are compared against the recorded expected properties. These properties of the object are called ROproperties(Runtime Object Properties).
Uses of GetROProperties method :
-> This method gives a flexibility to know the runtime object property and compare against the wtitten properties
-> We can also use this property with childobjects to count the number of similar objects on a webpage
-> the GetROProperty method can be used with description object in descriptive programming to identify any unique object
Any Web-base application, GUI , Desktop application, mobile applications,etc consists of various objects. What are objects then...Objects are the units of code. Examples of objects are link , editbox , image , etc. So while creating any object the developer thinks of some properties. These properties are called the expected properties of the object. While writing Scripts or while recording the QTP captures the properties of the objects. When the scripting is done and application is stable we exeute the written scrips, it may be done in sanity or regression or before any build. While executing the scripts the objects actual properties are compared against the recorded expected properties. These properties of the object are called ROproperties(Runtime Object Properties).
Uses of GetROProperties method :
-> This method gives a flexibility to know the runtime object property and compare against the wtitten properties
-> We can also use this property with childobjects to count the number of similar objects on a webpage
-> the GetROProperty method can be used with description object in descriptive programming to identify any unique object
QTP - 3 - String functions used in QTP
Here I will take you through different string functions which are used on daily basis in scripting. I can also say this as an step up for the interview.
> Len(string) - This function is used to find the length of any given string.
With this function, you can directly pass a string as an argument and we can get the length of it.
>LCase(string) - This function is used to convert the upper case of characters in lower case. If the string is already in lower case then it will remain as it is.
>UCase(string) - This function is used to convert the lower case of characters into upper case. If the string is already in upper case then it will remain as it is.
>LTrim(String) - LTrim is used to remove a leading space from any string.
>RTrim(String) - RTrim is used to remove a trailing space from any string.
>Trim(String) - Trim is used to remove the leading and trailing space from any string.
>InStr([start,]string1,string2[,compare])
This function searches for a string within another another string and returns the location of occurrence of one string within another string.It actually returns the position of first occurrence of the second string within first
>InstrReverse(String1, string2, start position, compare)
it returns the occurence of second string from the first but this starts the comparison from last.
>Left(String,no of characters) - Left function returns the specified number of characters from left side of the string
>Right(String , No of characters) - Right function returns specified number of characters from right side of the string.
>Mid(String, Start position, no of characters) - Mid function returns specified number of characters from the given start position.
>StrReverse(String) - This function reverses the given string.
>StrComp(String1,string2,binary(0)/textual(1)) - Strcomp is used to compare two strings. We can decide the binary and textual comparison by giving the 3rd parameter as 0 or 1. Binary comparison also checks for the case of the characters and textual comparison only checks for the test of the strings.
>Replace(expression, expression to be replaced, Start position, no of replacements ,binary(0)/textual(1) comparison)
Replace function is used to replace the given character from the given expression. The last 3 parameters are optional. We can give the start position if we want any particular position to be checked. We can also give the number of replacements and at last we can do replacement by binary or textual comparison.
>Space(no of spaces)
This is a simple function which is used to give space in a particular string or at any place. We can give the count of no of spaces we want.
>Split(expression, delimiter, count ,compare)
Split is used to split or seperate the given expression with the given delimiter(eg-space,comma,etc). The last 2 parameters are optional, the count is used to give the no till where we want to split the expression and -1 is the default value of it.
So this was most of the string functions used in QTP, a quick revision of it favours a lot in the interviews!!
> Len(string) - This function is used to find the length of any given string.
With this function, you can directly pass a string as an argument and we can get the length of it.
>LCase(string) - This function is used to convert the upper case of characters in lower case. If the string is already in lower case then it will remain as it is.
>LTrim(String) - LTrim is used to remove a leading space from any string.
>RTrim(String) - RTrim is used to remove a trailing space from any string.
>Trim(String) - Trim is used to remove the leading and trailing space from any string.
>InStr([start,]string1,string2[,compare])
This function searches for a string within another another string and returns the location of occurrence of one string within another string.It actually returns the position of first occurrence of the second string within first
>InstrReverse(String1, string2, start position, compare)
it returns the occurence of second string from the first but this starts the comparison from last.
>Left(String,no of characters) - Left function returns the specified number of characters from left side of the string
>Right(String , No of characters) - Right function returns specified number of characters from right side of the string.
>Mid(String, Start position, no of characters) - Mid function returns specified number of characters from the given start position.
>StrReverse(String) - This function reverses the given string.
>StrComp(String1,string2,binary(0)/textual(1)) - Strcomp is used to compare two strings. We can decide the binary and textual comparison by giving the 3rd parameter as 0 or 1. Binary comparison also checks for the case of the characters and textual comparison only checks for the test of the strings.
>Replace(expression, expression to be replaced, Start position, no of replacements ,binary(0)/textual(1) comparison)
Replace function is used to replace the given character from the given expression. The last 3 parameters are optional. We can give the start position if we want any particular position to be checked. We can also give the number of replacements and at last we can do replacement by binary or textual comparison.
>Space(no of spaces)
This is a simple function which is used to give space in a particular string or at any place. We can give the count of no of spaces we want.
>Split(expression, delimiter, count ,compare)
Split is used to split or seperate the given expression with the given delimiter(eg-space,comma,etc). The last 2 parameters are optional, the count is used to give the no till where we want to split the expression and -1 is the default value of it.
So this was most of the string functions used in QTP, a quick revision of it favours a lot in the interviews!!
Monday, 20 April 2015
QTP 2 - What are the OR's and types of object Repositories suppoted by QTP.
Object Repository is a collection of object and their properties with which QTP recognizes the objects and performs actions on it. When a user records a test, the objects and its properties are captured by default. These recorded properties are then used to uniquely identify the objects during execution.
Adding the objects to OR :
1) By recording the objects
When we record any object the object properties are stored automatically to the OR, by default in per-action/Local OR.
When we record any object the object properties are stored automatically to the OR, by default in per-action/Local OR.
2) By adding the objects to OR manually through Object repository manager.
In Object repository manager we have an option of adding the objects. Again by default its local OR.
In Object repository manager we have an option of adding the objects. Again by default its local OR.
QTP has 2 types of Object Repository
1) Shared Object Repository (also called Global OR) - This type of repository is visible in all the actions and by default its in non-edit mode, although we can edit the repository. Once edited it is visible across all the actions in which it is associated. Its extension is .tsr(test shared repository)
2) Per-Action Object Repository, (also called Local OR) - Local Object Repository is used by particular actions only. Its visible only in actions. Its extension is .mtr(module test repository). Its in edit mode by default for the action. The changes made to it is only visible in particular action.
QTP 1 - How to identify an object from the list of objects whose properties are changing in every build ?
To automate such scenarios we need to use "getROproperties" and "setTO properties" methods. First of all we need to get all the unique properties of a continuously changing object through getROproperties and then we need to set these properties through setTO properties in the OR. Once the properties are set in Object repositories we can use those properties to uniquely identify any object.
For example : suppose there are 10 links on a page and we need to click on the 5th link out of those 10, but for all of them the properties are changing , then how will we identify the link.
-> First of all we need to count the childobjects having the miclass : "link", now one by one we can set the properties to OR through GetROProperties and SetTOProperties. Now we can easily click on the link using the childobjects at 4th position.
-> we can also use indexing , a ordinal identifier to identify object at fourth place.
For example : suppose there are 10 links on a page and we need to click on the 5th link out of those 10, but for all of them the properties are changing , then how will we identify the link.
-> First of all we need to count the childobjects having the miclass : "link", now one by one we can set the properties to OR through GetROProperties and SetTOProperties. Now we can easily click on the link using the childobjects at 4th position.
-> we can also use indexing , a ordinal identifier to identify object at fourth place.
Subscribe to:
Posts (Atom)