'Open a Google page and count the no of links and buttons in that page
If Browser("index:=0").Exist(1) then 'If Browser is already opened
a=Browser(index:=0").GetROProperty("hwnd")
Browser("hwnd:="&a).Navigate("http://www.google.com")
Browser("hwnd:="&a).Sync
wait(2)
Else 'If Browser is not opened
Systemutil.Run "IEXPLORE.exe"
a=Browser("index:=0").GetROProperty("hwnd")
Browser("hwnd:="&a).Navigate("http://www.google.com")
Browser("hwnd:="&a).Sync
wait(2)
End If
Set butObj=Description.Create ''''For Buttons
butObj("html tag").value="INPUT"
butObj("type").vlaue="submit"
Set linkObj=Description.Create ''''For Links
linkObj("html tag").value="A"
Set Buttons=browser("hwnd:=&a).page(title:=.*") .ChildObjects(butObj)
Set Links=browser("hwnd:=&a).page(title:=.*") .ChildObjects(linkObj)
msgbox "Total Button are: "&Buttons.count
msgbox " Total Links are: "&Links.count
Important Topics & Useful Scripts on QTP. Ask your QTP related questions at this id - asrajaputra@gmail.com
Saturday, May 31, 2008
Option Explicit
When you use the Option Explicit statement, you must explicitly declare all variables using the Dim, Private, Public, or ReDim statements.
If you attempt to use an undeclared variable name, an error occurs.
VB Script in general doesn't need variable declaration. Without using Dim, a variable can be directly used for assigning. For ex - temp=1
However, such practice can always be error prone. Ex: If i want to use the same variable in some other statement and miss spell it, say tempe=temp+1
VB Script still considers "tempe" as valid. In this case if we use Option Explicit on top of our script and proceed, then application will not proceed unless until u declare each and every variable.
Hence you make sure that your variable is serving your purpose.
If you attempt to use an undeclared variable name, an error occurs.
VB Script in general doesn't need variable declaration. Without using Dim, a variable can be directly used for assigning. For ex - temp=1
However, such practice can always be error prone. Ex: If i want to use the same variable in some other statement and miss spell it, say tempe=temp+1
VB Script still considers "tempe" as valid. In this case if we use Option Explicit on top of our script and proceed, then application will not proceed unless until u declare each and every variable.
Hence you make sure that your variable is serving your purpose.
Test Object Model
Test Object Model is the model that QTP uses to recognize objects in the application.
Every object has a set of properties and attributes which QTP uses to perform the operations.
Also using these attributes in form of mandatory and assistive properties, QTP recognize the particular object.
Every object has a set of properties and attributes which QTP uses to perform the operations.
Also using these attributes in form of mandatory and assistive properties, QTP recognize the particular object.
Automation Object Model
Quick test Automation Object Model is used to automate the quick test operations.
For example, if you want to run a test in QTP you have to follow these steps -
'i. Open a QTP
Set qtApp=CreateObject("Quicktest.Application")
qtApp.Launch
qtApp.visible=true
'ii. Open a test in a QTP
qtApp.open "testpath", true
'iii. Specify the result folder
Set qtTest=qtApp.test
Set qtResults=CreateObject("Quicktest.runreslutoption")
qtResults.ResultLocation="resultpath"
'iv. Run the test
qtTest.run qtResults
'v. Close QTP or Open another test and run it
qtTest.close
qtTest.open"TestPath", true
For example, if you want to run a test in QTP you have to follow these steps -
'i. Open a QTP
Set qtApp=CreateObject("Quicktest.Application")
qtApp.Launch
qtApp.visible=true
'ii. Open a test in a QTP
qtApp.open "testpath", true
'iii. Specify the result folder
Set qtTest=qtApp.test
Set qtResults=CreateObject("Quicktest.runreslutoption")
qtResults.ResultLocation="resultpath"
'iv. Run the test
qtTest.run qtResults
'v. Close QTP or Open another test and run it
qtTest.close
qtTest.open"TestPath", true
Before going to Automation
Before going to Automation, there is a process -
1. Whether we have to go for automation.
2. What are the client requirement for automation.
3. Which tool we have to use for automation
4. Gathering suggestions from others and searching for the resources.
5. Identifying the application components to be Automated.
6. Preparing the automation approach document (Which list the Functionalities, Risks, Assumptions, Tool Identification, and Proof of Concept functionalities)
7. Gathering the test cases for automation
8. Giving trainings
9. Resource allocation.
1. Whether we have to go for automation.
2. What are the client requirement for automation.
3. Which tool we have to use for automation
4. Gathering suggestions from others and searching for the resources.
5. Identifying the application components to be Automated.
6. Preparing the automation approach document (Which list the Functionalities, Risks, Assumptions, Tool Identification, and Proof of Concept functionalities)
7. Gathering the test cases for automation
8. Giving trainings
9. Resource allocation.
Environment Variables
Environment variables helps us to use the variables from other sources during the run session.
Types of Environment Variable:
1. User defined Internal - These variables are saved with in the test and accessible only with in the test in which they were defined.
2. User defined External - We can use external environment variables from any other program.
Example for User Defined Environment Variables is Email, FirstName,LastName, PhoneNumber, etc..
3. Built In - It enables you to know the current information about the test and computer on which the test is run. These variables are accessible from all test and components. They are read only.
Example for Built In Environment Variable is OperatingSystem, OSVersion, LocalHostName, ProductName, ProductVersion, etc..
By default, Environment variables are internal type that means we cannot use that internal environment variables from any other program. That's why we can make it as external variables.
Deference between Built In and User Defined Environment Variables -
We cannot create or modified the values for built in environment variables. But we can create and modify the values for user-defined environment variables.
Use of Environment variable -
Environment variable comes into picture when we try to parameterize data.
It is one kind of data source.
When we want to test an application, where the user interface string changes, depending on the selected language.
We can use external environment variables from any other program by loading xml file.
Ex: Environment.LoadFromFile"Path of the xml file"
To check whether it is exist or not -
By using "Environment("ParamterName").value" we can know that variable exist in the environment.
By using "Environment.value("ParameterName")" then QTP will create a new internal environment variable if does not exists already.
Types of Environment Variable:
1. User defined Internal - These variables are saved with in the test and accessible only with in the test in which they were defined.
2. User defined External - We can use external environment variables from any other program.
Example for User Defined Environment Variables is Email, FirstName,LastName, PhoneNumber, etc..
3. Built In - It enables you to know the current information about the test and computer on which the test is run. These variables are accessible from all test and components. They are read only.
Example for Built In Environment Variable is OperatingSystem, OSVersion, LocalHostName, ProductName, ProductVersion, etc..
By default, Environment variables are internal type that means we cannot use that internal environment variables from any other program. That's why we can make it as external variables.
Deference between Built In and User Defined Environment Variables -
We cannot create or modified the values for built in environment variables. But we can create and modify the values for user-defined environment variables.
Use of Environment variable -
Environment variable comes into picture when we try to parameterize data.
It is one kind of data source.
When we want to test an application, where the user interface string changes, depending on the selected language.
We can use external environment variables from any other program by loading xml file.
Ex: Environment.LoadFromFile"Path of the xml file"
To check whether it is exist or not -
By using "Environment("ParamterName").value" we can know that variable exist in the environment.
By using "Environment.value("ParameterName")" then QTP will create a new internal environment variable if does not exists already.
Function Vs Action
If we want to use the Object Repository feature then we have to go for Actions
If the functionality is not about any automation script we can go for functions.
(Example, a function like getting a string between two specific characters, now this is something not specific to QTP and can be done by pure VB Script, so this should be done in a function not an action.)
If the functionality is not about any automation script we can go for functions.
(Example, a function like getting a string between two specific characters, now this is something not specific to QTP and can be done by pure VB Script, so this should be done in a function not an action.)
About Functions
Function is a group of methods and instruction and it can be access by calling that function.
User defined functions can be coded as part of QTP files or can be coded as separate ".vbs" files.
These can be associated as library files under Run Settings. This would enable you to create a library functions which can be used across scripts as and when required.
Example for User Defined Function for WebEdit Class:
Public function edit(name) 'Defining the function
Browser("BrowserName").Page("PageName").WebEdit("User ID").set name
End Function
Call edit("rajaputra") 'Calling the function
User defined functions can be coded as part of QTP files or can be coded as separate ".vbs" files.
These can be associated as library files under Run Settings. This would enable you to create a library functions which can be used across scripts as and when required.
Example for User Defined Function for WebEdit Class:
Public function edit(name) 'Defining the function
Browser("BrowserName").Page("PageName").WebEdit("User ID").set name
End Function
Call edit("rajaputra") 'Calling the function
Descriptive Programming
If the object is not in the object repository, then based on the unique property of the object we can write a program on that object. It is nothing but Descriptive Programming.
QTP cannot take an action on a object until unless its object description is in the Object Repository.
But Descriptive programming provides a way to perform action on objects which are not in Object Repository.QTP cannot take an action on a object until unless its object description is in the Object Repository.
When to Use:
1. The object in the application are dynamic in nature and need special handling to identify the object.
2. When object repository is getting huge due to the no of objects being added. If the size of the object repository increases too much then it decreases the performance of QTP while recognizing the object.
Example for when to use DP:
Suppose, we have an application that has not been developed yet.
Now QTP recording the script and adding the objects to the object repository needs the application to be up. That would mean waiting for the application to be deployed.
But if we know the description of the objects that will be created then we can still start of with the script writing for testing.
How to write Descriptive Programming:
There are two ways to write.
1. By creating the properties collection objects for the description.
To use this method you need to create an empty description
Set ObjDesc=Description.Create 'Now we have blank description in ObjDesc.
'Each description has 3 properties, they are Name, Value, RegularExpression.
ObjDesc("PropertyName").Value="Value of the Property"
'When you use the property name for the first time the property is added to the collection and 'when you use it again the property is modified. Now we can use it as ....
Browser("BrowserName").Page(PageName).WebEdit(ObjDesc) .set "Test"
'To Remove the property from the collections -
ObjDesc.remove"PropertyName"
'To know the property exist or not in the property collection -
If ObjDesc("PropertyName").value=empty then
msgbox "Not Exist"
else
msgbox "Exist"
2. By giving the description in form of the string arguments.
Browser("PropertyName:=PropertyValue").Page ("PropertyName: =PropertyValue")..........
About Actions
Action is used to split out test script into more flexible and logic unit.
When it is used:
If we require a particular step of our test scripts then we can use action by making it reusable action.
If two or more test require the same script then we go for the actions.
Action Types:
1. Non Reusable Action -It can be called only once in our test. It cannot be called in any other test.
2. Reusable Action - It can be called multiple times in our test as well as in other test.
When it is called in other test then it becomes External Action.
By default each action is non reusable action. If we want to convert it as reusable action then there are two ways:
1. Select Action, write click, select the check box reusable action
2. Select Action Properties, select check box reusable action
(From keyword view both methods will be possible. But from expert view only 2nd method is possible.)
By making action as a reusable action, we can call that actions from other tests, rather than recording, modifying, and enhancing the same steps each time.
How to call an Action:
By using "Call to copy" or "Call to Existing" we can call the actions in QTP.
Defference betweeen Call to Copy and Call to Existing:
Call to Copy:
1. It is read and write mode
2. We can call both reusable actions and non reusable actions.
3. If we make any changes in base program, that will not be effected to the copied program
Call to Existing:
1. It is read only mode
2. We can call both reusable actions and non reusable actions.
3. If we make any changes in base program, that will not be effected to the copied program.
When it is used:
If we require a particular step of our test scripts then we can use action by making it reusable action.
If two or more test require the same script then we go for the actions.
Action Types:
1. Non Reusable Action -It can be called only once in our test. It cannot be called in any other test.
2. Reusable Action - It can be called multiple times in our test as well as in other test.
When it is called in other test then it becomes External Action.
By default each action is non reusable action. If we want to convert it as reusable action then there are two ways:
1. Select Action, write click, select the check box reusable action
2. Select Action Properties, select check box reusable action
(From keyword view both methods will be possible. But from expert view only 2nd method is possible.)
By making action as a reusable action, we can call that actions from other tests, rather than recording, modifying, and enhancing the same steps each time.
How to call an Action:
By using "Call to copy" or "Call to Existing" we can call the actions in QTP.
Defference betweeen Call to Copy and Call to Existing:
Call to Copy:
1. It is read and write mode
2. We can call both reusable actions and non reusable actions.
3. If we make any changes in base program, that will not be effected to the copied program
Call to Existing:
1. It is read only mode
2. We can call both reusable actions and non reusable actions.
3. If we make any changes in base program, that will not be effected to the copied program.
Wednesday, May 28, 2008
How to Write Script
Here I am giving an idea of how we can write the script in different ways
Here I am taking an example to write a statement to click on a specified button.
I took two conditions, first one is when we are using object repository, second one is when we are not using object repository (Using Descriptive Programming)
Using Object Repository:
'1st Method -
Window("Flight Reservation").WinButton("Update Order").click 'Common Method
'2nd Method -
Set wndObject=Window("Flight Reservation") 'Assigning window object to an object variable
wndObject.WinButton("Update Order").click
OR
Set btnObject=Window("Flight Reservation").WinButton("Update Order") 'Assigning button 'object to an object variable
'3rd Method -
With Window("Flight Reservation") 'Using with statement
.WinButtton("Update Order").click
End with
Usingh Descriptive Programming :
'4th Method -
Window("text:=Flight Reservation").WinButton("text:=&Update Order").click
'5th Method
Set oDes=Description.Create 'Creating a description Object
oDes("nativeclass").value=Button 'Assigning description to the description object
oDes("text").value="&Update Order"
Window("text:=Flight Reservation").WinButton(oDes).click 'Clicking on button using the 'created description object
'6th Method -
Set oDes=Description.Create 'Creating a description Object
set btnObjList=Window("text:=Flight Reservation").childObjects(oDes) 'Filtering objects
For objIndex=0 to btnObjList.count-1
propVal=btnObjList(objIndex).getROProperty("text") 'Get Property value from object
If propVal="&Update Order" then 'Compare Property value
btnObjList(objIndex).click 'Click on identified object
Exit for 'Exit for loop after clicking on the button
End if
Next
'7th Method -
Public const wndFlight="text:=Flight Reservation" 'Assigning a window object to a constant
Public const btnUpdate="text:=&Update Order" 'Assigning a button object to a constant
window(wndFlight).WinButton(btnUpdate).click 'clicking on a button using constants
Here I am taking an example to write a statement to click on a specified button.
I took two conditions, first one is when we are using object repository, second one is when we are not using object repository (Using Descriptive Programming)
Using Object Repository:
'1st Method -
Window("Flight Reservation").WinButton("Update Order").click 'Common Method
'2nd Method -
Set wndObject=Window("Flight Reservation") 'Assigning window object to an object variable
wndObject.WinButton("Update Order").click
OR
Set btnObject=Window("Flight Reservation").WinButton("Update Order") 'Assigning button 'object to an object variable
'3rd Method -
With Window("Flight Reservation") 'Using with statement
.WinButtton("Update Order").click
End with
Usingh Descriptive Programming :
'4th Method -
Window("text:=Flight Reservation").WinButton("text:=&Update Order").click
'5th Method
Set oDes=Description.Create 'Creating a description Object
oDes("nativeclass").value=Button 'Assigning description to the description object
oDes("text").value="&Update Order"
Window("text:=Flight Reservation").WinButton(oDes).click 'Clicking on button using the 'created description object
'6th Method -
Set oDes=Description.Create 'Creating a description Object
set btnObjList=Window("text:=Flight Reservation").childObjects(oDes) 'Filtering objects
For objIndex=0 to btnObjList.count-1
propVal=btnObjList(objIndex).getROProperty("text") 'Get Property value from object
If propVal="&Update Order" then 'Compare Property value
btnObjList(objIndex).click 'Click on identified object
Exit for 'Exit for loop after clicking on the button
End if
Next
'7th Method -
Public const wndFlight="text:=Flight Reservation" 'Assigning a window object to a constant
Public const btnUpdate="text:=&Update Order" 'Assigning a button object to a constant
window(wndFlight).WinButton(btnUpdate).click 'clicking on a button using constants
Subscribe to:
Posts (Atom)
About Me
- RAJAPUTRA
- Hi all,I am Arun Singh Rajaputra. I am working as a Project Lead in a reputed organization in Hyderabad, AP, India. I have little bit knowledge on Quick Test Professional and like to share my knowledge to all through this blog.
Subscribe to get updates on this blog
NOTE
Some of the posts posted in this blog are collected and most of them have been prepared by me. If any one have objections regarding any copied posts. Please mail me so that I can take a necessary action on that post.