Sometimes you need functionality that QTP does not provide. Other times you may need to interact with an existing DLL. Using a simple C# DLL, that we create, I will show how you can easily call it in QuickTest Pro.
Creating a Simple .NET DLL
Open Visual Studio (If you don’t have a copy of Visual Studio you can download a free copy of Visual C# Express.) and create a new ‘Class Library’ project named QTP.UI.Automation:
Rename Class1 to QTP:
Next let’s add a simple function that take two numbers and adds them together:
Go to the QTP.UI.Automation properties and make sure you have the following:
Make sure the ‘Make assembly COM-Visible’ is checked.
Go to the Build section and make sure that the ‘Register for COM interop’ is checked:
Build your solution (F6) and make sure there are no errors.
Call Your DLL in QuickTest Pro
Start QTP and add the following code:
Set oTestCom = CreateObject(“QTP.UI.Automation.QTP”)
QTP should return 10
Cool – that’s it.