Convert Visual Basic Classes to DLL then Call them in UFT and Build the Testing Framework. ( Developer Driven Framework) :
1. Convert all Classes to DLL files in VB and
2. Just call those DLL files in UFT/QTP and Build the Testing Framework In TestPlan and Test Suites in ALM Test Lab.
Sample as below :
~~~~~~~ * ~~~~~~~ * ~~~~~~~ * ~~~~~~~ * ~~~~~~~ * ~~~~~~~ * ~~~~~~~ *
1. We need to create DLL files in VB :
DLL files are dynamic-linked library files written and controlled with VB.
DLLs make sharing, storing, and saving your code simple.
~~~~~~~ * ~~~~~~~ * ~~~~~~~ * ~~~~~~~ * ~~~~~~~ * ~~~~~~~ * ~~~~~~~ *
2. How can the functions inside DLL be called from QTP?
This part is actually simple and a two step process…
Declare the method using Extern.Declare
Example
Extern.Declare micHwnd, “FindWindow”, “user32.dll”, “FindWindowA”, micString, micString
where:
micHwnd -the data type of value returned by method
FindWindow -the user supplied procedure name. You can set it to anything as long as it’s a valid syntax.
user32.dll -the DLL from where you wish to call the method
FindWindowA -The actual method name inside the DLL
Last two are the data types of the arguments that will be passed to the procedure
Call the method
Example:
Extern.FindWindow(“Notepad”, vbNullString)
To show the above process in action, here is an example to change the title of the Notepad window by calling the user32.dll
'Declare FindWindow method
Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString
'Declare SetWindowText method
Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString
'Get HWND of the Notepad window
hwnd = Extern.FindWindow("Notepad", vbNullString)
If hwnd = 0 then
MsgBox "Notepad window not found"
End if
'Change the title of the notepad window
res = Extern.SetWindowText(hwnd, "LearnQTP.com")
Simple copy-paste the code above in your QTP ‘Expert View’. Open a blank notepad window. Run this code. You will now see that the name has changed from Untitled-Notepad to LearnQTP.com
DLL files are dynamic-linked library files written and controlled with VB.
DLLs make sharing, storing, and saving your code simple.
~~~~~~~ * ~~~~~~~ * ~~~~~~~ * ~~~~~~~ * ~~~~~~~ * ~~~~~~~ * ~~~~~~~ *
2. How can the functions inside DLL be called from QTP?
This part is actually simple and a two step process…
Declare the method using Extern.Declare
Example
Extern.Declare micHwnd, “FindWindow”, “user32.dll”, “FindWindowA”, micString, micString
where:
micHwnd -the data type of value returned by method
FindWindow -the user supplied procedure name. You can set it to anything as long as it’s a valid syntax.
user32.dll -the DLL from where you wish to call the method
FindWindowA -The actual method name inside the DLL
Last two are the data types of the arguments that will be passed to the procedure
Call the method
Example:
Extern.FindWindow(“Notepad”, vbNullString)
To show the above process in action, here is an example to change the title of the Notepad window by calling the user32.dll
'Declare FindWindow method
Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString
'Declare SetWindowText method
Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString
'Get HWND of the Notepad window
hwnd = Extern.FindWindow("Notepad", vbNullString)
If hwnd = 0 then
MsgBox "Notepad window not found"
End if
'Change the title of the notepad window
res = Extern.SetWindowText(hwnd, "LearnQTP.com")
Simple copy-paste the code above in your QTP ‘Expert View’. Open a blank notepad window. Run this code. You will now see that the name has changed from Untitled-Notepad to LearnQTP.com
3. My Hybrid Framework Structure :
No comments:
Post a Comment