Unable to create class instance
I created 4 user-defined classes that provide access to some external testing framework facilities. Each of these classes resides in its own .qfl file. The 4 files are associated with my test using the Associate Function Libraries feature. There are no missing resources listed.
One of the user-defined classes is QaUtils. I have the following lines in my test:
Set objQaUtils = new QaUtils
The set statement causes the error:
Variable is undefined: 'QaUtils'
I am new to QTP, but it looks like the class definition is not in scope. Is there something else I need to do in my test in addition to including the class definition .qfl files as associated function libraries?
Set NewQaUtils = New QAUtils
Then call it from your test:
Set objQaUtils = NewQaUtils
This is an annoying quirk of QTP, but the workaround works.
Use the executfile function. On the library. This will allow you to use the "new" operator. The downside is that you will not be able to debug the classes. This in my opinion is unworkable.
Inside the class library do this...
Public Function New_MyClass()
Set New_MyClass = new myClass
Then inside your script you can reference the class...
Set myInst = New_MyClass()
Using this method, you can debug the class just like any other code.
I'm using classes in my script ,and QTP displays error message from Class_Initialize sub proc instead of going to catch method.
here is my scenario...
My .vbs file has
Private Sub Class_Initialize
msgbox "inside test class"
Browser("title:=Welcome.*").WebElement("text:=Relevant Codes").Click ' *QTP hangs here*
Msgbox "This line is not printed"
Private Sub Catch 'Catch
If Err.Number = 0 Then Exit Sub
Print "Entering test class Catch.."
Print "Error caught: " & Err.Description & vbNewLine
Private Sub Class_Terminate : Catch 'Finally
Public Function testfunction
Set testfunction=new test
Main script :
On Error Resume Next
please help me here.
Thanks in Advance.
(Opinions expressed in my postings are mine alone, and do not reflect the opinions of my employer.No warranties express or implied for any solution/suggestion posted.)