A Function helps to build modularity and reusable framework in test automation. It saves time and effort, and lines of code in the program. In this blog post, we will see how to call a function in QTP.
What you need is simple notepad or open source editor notepad++ or even in QTP IDE will do. First, you need to analyze and identify the purpose of your function. In this tutorial, we will see how to sum up the values by sending two numbers to the function Add().
Here I am using a simple notepad to create a function. Simply copy and paste below code and save it as SumFunction.vbs
Public Function Add (a,b)
sum = a + b
Add = sum
Now launch QTP and copy and paste below code to your test script.
Dim a, b, sum
a = 5
b = 10
sum = Add(a, b)
Here I declared two variables a & b and assigned 5 & 10 respectively. I am calling the function Add() and displaying the sum in message box.
If you execute above code immediately, you will get error. Because I did not associate yet *.vbs file to the QTP script.
How to associate function or library files to QTP script?
- Go to File > Settings
- In Test Settings dialog box, click on Resources
- Click on + icon and then click on Browse button to map your function file i.e. SumFunction.vbs
- Click on Apply and then OK.
You can check the syntax error in your *.vbs file by clicking on Check Syntax button or by pressing CTRL + F7 key in QTP IDE.
Thanks for visiting QAInsights!
We’re always posting interesting articles on QAInsights. I request you to subscribe so you don’t miss out anything.
- Unboxing Apache JMeter 4.0 - February 13, 2018
- Swagger Inspector and Swagger Hub Hands-on - January 25, 2018
- Speedometer 2.0 Testing - January 17, 2018
- Performance Analysis of Rajini Makkal Mandram Website - January 8, 2018
- Must Have Tools For Technical Founders - November 9, 2017