Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Classes and Actions
#1
Solved: 11 Years, 3 Months, 3 Weeks ago
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
RunAction "Action2"

'here i Try to call method "checkCall"
GlobalDictionary("checkObj").checkCall() <--------------ERROR, but WHY ?


Action2 source code:

Code:
Class check
   Function checkCall()
      MsgBox "OK"
   End Function
End Class

Set checkObj = new check
GlobalDictionary.Add "checkObj ", checkObj



Thanks a lot!
Reply
#2
Solved: 11 Years, 3 Months, 3 Weeks ago
I assume it is not because of the space you have here ( i have highlighted with _ )
Code:
Set checkObj = new check
GlobalDictionary.Add "checkObj_", checkObj

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.
Reply
#3
Solved: 11 Years, 3 Months, 3 Weeks ago
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.
Reply
#4
Solved: 11 Years, 3 Months, 3 Weeks ago
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.
Reply
#5
Solved: 11 Years, 3 Months, 3 Weeks ago
Thanks to everyone!
I figured it out with function library.

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Does QTP 8.2 suppprts classes? Star 2 2,015 07-30-2009, 03:18 PM
Last Post: supputuri
  Using QTP Automation Object Model to declare object classes sadafakhan 0 2,867 07-24-2009, 05:20 AM
Last Post: sadafakhan

Forum Jump:


Users browsing this thread: 3 Guest(s)