How to use Classes in QTP
来源:互联网 发布:2g网络关闭 编辑:程序博客网 时间:2024/05/19 09:17
From: http://makeqtpeasy.blogspot.com/2009/01/how-to-use-classes-in-qtp.html
Here i am giving an useful information about how to use classes in QTP.
Before going to that we will discuss about using functions in QTP.
If there is a function in our script like this
'*********** ********* ********* ********* ********* ********* **
Function Demo(a,b)
demo=a+b
End Function
'*********** ********* ********* ********* ********* ********* **
This is a function to add two numbers.
To call this function we write
'*********** ********* *****
val=demo(2,3)
msgbox val
'*********** ********* *****
We can store the functions in library files (.vbs) and to use this function, Library should be associated to the QTP Test or library file should be executed by QTP Test using ExecuteFile statement.
This means we can use the functions which are written in QTP Script or in Library files by associating it or by executing it.
But this is not possible when using classes in our QTP Test. If we want to use a class which is there in the libraryfile its mandotory that the library should be executed using Executefile statement.
Classes will not work which are there in associated libraries. Here is an example...
'*********** ********* ********* ********* ********* **
Class Maths
Function Add1(a,b)
add1=a+b
End Function
Function sub1(a,b)
sub1=a-b
End Function
End Class
'*********** ********* ********* ********* ********* **
If the above code is there with in the test script then the usage of this class will be like this
'*********** ********* ********* ********* ********* **
Set mat=New Maths
val=mat.add1( 2,3)
msgbox val
'*********** ********* ********* ********* ********* **
If the class code is there with in the library file then the usage of this class will be like this
'*********** ********* ********* ********* ********* **
ExecuteFile (Library Path)
Set mat=New Maths
val=mat.add1( 2,3)
msgbox val
'*********** ********* ********* ********* ********* **
This class will not work If you just associate the library with in the
File--> Settings --> Resources
But there is a way of using the classes even though if it is in associated library.
First Method:
Where ever the class is declared in the library it self create the class instance and use it in your qtp script.
'*********** ********* ********* ********* ********* **
Set mat=New Maths
Class Maths
Function Add1(a,b)
add1=a+b
End Function
Function sub1(a,b)
sub1=a-b
End Function
End Class
'*********** ********* ********* ********* ********* **
To Use this class
'*********** ********* *
val=mat.add1( 2,3)
msgbox val
'*********** ********* *
Second Method:
Create a function which is returning class object by creating instance of the class.
'*********** ********* ********* ********* ********* **
Function mat()
Set mat=New Maths
End Function
Class Maths
Function Add1(a,b)
add1=a+b
End Function
Function sub1(a,b)
sub1=a-b
End Function
End Class
'*********** ********* ********* ********* ********* **
To Use this class
'*********** ********* *
Set mth=mat ' mat is a function which will return the class instance
val=mth.add1( 2,3)
msgbox val
'*********** ********* *
Before going to that we will discuss about using functions in QTP.
If there is a function in our script like this
'*********** ********* ********* ********* ********* ********* **
Function Demo(a,b)
demo=a+b
End Function
'*********** ********* ********* ********* ********* ********* **
This is a function to add two numbers.
To call this function we write
'*********** ********* *****
val=demo(2,3)
msgbox val
'*********** ********* *****
We can store the functions in library files (.vbs) and to use this function, Library should be associated to the QTP Test or library file should be executed by QTP Test using ExecuteFile statement.
This means we can use the functions which are written in QTP Script or in Library files by associating it or by executing it.
But this is not possible when using classes in our QTP Test. If we want to use a class which is there in the libraryfile its mandotory that the library should be executed using Executefile statement.
Classes will not work which are there in associated libraries. Here is an example...
'*********** ********* ********* ********* ********* **
Class Maths
Function Add1(a,b)
add1=a+b
End Function
Function sub1(a,b)
sub1=a-b
End Function
End Class
'*********** ********* ********* ********* ********* **
If the above code is there with in the test script then the usage of this class will be like this
'*********** ********* ********* ********* ********* **
Set mat=New Maths
val=mat.add1( 2,3)
msgbox val
'*********** ********* ********* ********* ********* **
If the class code is there with in the library file then the usage of this class will be like this
'*********** ********* ********* ********* ********* **
ExecuteFile (Library Path)
Set mat=New Maths
val=mat.add1( 2,3)
msgbox val
'*********** ********* ********* ********* ********* **
This class will not work If you just associate the library with in the
File--> Settings --> Resources
But there is a way of using the classes even though if it is in associated library.
First Method:
Where ever the class is declared in the library it self create the class instance and use it in your qtp script.
'*********** ********* ********* ********* ********* **
Set mat=New Maths
Class Maths
Function Add1(a,b)
add1=a+b
End Function
Function sub1(a,b)
sub1=a-b
End Function
End Class
'*********** ********* ********* ********* ********* **
To Use this class
'*********** ********* *
val=mat.add1( 2,3)
msgbox val
'*********** ********* *
Second Method:
Create a function which is returning class object by creating instance of the class.
'*********** ********* ********* ********* ********* **
Function mat()
Set mat=New Maths
End Function
Class Maths
Function Add1(a,b)
add1=a+b
End Function
Function sub1(a,b)
sub1=a-b
End Function
End Class
'*********** ********* ********* ********* ********* **
To Use this class
'*********** ********* *
Set mth=mat ' mat is a function which will return the class instance
val=mth.add1( 2,3)
msgbox val
'*********** ********* *
- How to use Classes in QTP
- 第九天(How to Use Classes in Sencha Touch)
- How to use WMI classes
- Multithreading: How to Use the Synchronization Classes
- When to Use Static Classes in C#
- How to use Serial Port in Windows
- How To Use Macro In Program.
- How to use virt-install in OpenSolaris
- How to use tinyfck in drupal
- How to use Regular Expression in LotusScript
- How to Use PeekMessage() Correctly in Windows
- How to use IMGDECMP.DLL in WindowsCE
- how to use deb files in ubuntu
- How to use Common Navigator in RCP
- How to use SCAT in ECC6
- HOW TO : use DDMS in Ubuntu
- How to use getBodyClass() in magento?
- How to use forms in Tapestry 5.
- 42个免费的长阴影的图标(PSD格式)
- 关注好友动态,请访问CSDN个人空间
- myls-l.c 实现ls -l指令
- 生产者/消费者模型
- 判断字符串interleave
- How to use Classes in QTP
- 20130918学习小结
- 4 Different Ways to Associate Function Libraries to your QTP Scripts
- UI控件详解01-UISegmentedControl的详细使用(附效果图)
- TCP链接建立到释放过程
- HDOJ 1520 Anniversary party
- POJ 2446 Chessboard (匈牙利算法)
- Java核心技术,支撑Java程序对外接口的I/O
- LeetCode | Validate Binary Search Tree