Classes and Actions - Printable Version +- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums) +-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP) +--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming) +--- Thread: Classes and Actions (/Thread-Classes-and-Actions) |
Classes and Actions - hmelhmel - 03-23-2012 Helo everyone! I'm try to pass class objects beetwen two actions using GlobalDictionary but I have problem When I try to pass simple values it's ok and even I try to pass object it's also everything fine but I can't call any methods from passed class object! So, question: WHY ? Here is example: Action1 source code: Code: GlobalDictionary.RemoveAll <---- before start cleanup global hash Action2 source code: Code: Class check Thanks a lot! RE: Classes and Actions - vIns - 03-24-2012 I assume it is not because of the space you have here ( i have highlighted with _ ) Code: Set checkObj = new check and the reason would be... Actually when the library files you have added in the resources are loaded, it would be available for all the actions. It is global scope. Once Recovery scenarios and library files are loaded, when QTP enters the action, it creates only local scope for everything. So in Action2, 'new check' is what creates an instance of the class and assigns a reference. When you try to call this in Action1, obviously it will not be available for Action1. It happens as it is an object. If you assign a value, it will work because it is a value not a reference. So you can not access methods or properties of the class In order to make this work, 'Set checkObj = new check' should be in a external library file. So that it can create an object in global scope. But in order to put this statement, you also need to keep the class as well in the external file where you have 'Set checkObj = new check'. But if you do so, i bet you do not need to have any globaldictionary because the 'checkObj' itself will be available globally!! This is my best guess. Others, Please correct if i am wrong. RE: Classes and Actions - rajeevszone - 03-25-2012 Declare global dictionary as a global object in a .vbs file and associate tjis vbs file to all QTP scripts. This file acts as a collection file for all global variables and global objects. Environment Variables chapter of "Test Automation and QTP - Excel with Ease' book provides a good reference of this. RE: Classes and Actions - rajeevszone - 03-25-2012 Declare dictionary object as a global object in a .vbs file and associate tjis vbs file to all QTP scripts. This file acts as a collection file for all global variables and global objects. Environment Variables chapter of "Test Automation and QTP - Excel with Ease' book provides a good reference of this. RE: Classes and Actions - hmelhmel - 03-26-2012 Thanks to everyone! I figured it out with function library. |