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.
- Brotli Compression in Performance Testing - October 6, 2017
- Unboxing HPE StormRunner 2.7 - September 27, 2017
- What’s new in Apache JMeter 3.3? - September 25, 2017
- Measuring Client-side performance using Performance APIs - September 19, 2017
- Unboxing HPE LoadRunner 12.55 - August 20, 2017