SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Member
    Join Date
    Sep 2008
    Posts
    65
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Scope of Class in resource lib

    Hello,
    I am trying to build my first class. In order to get it to work to the point it does now I have:
    A. Put it in a QC lib pointed to by the resource tab.
    B. Put a 'factory function' in front of the class to instantiate it (I couldn't get it to instantiate from the action

    I have read and thought I understood Terry's doc on scope and I thought I had it set up correctly. My Calling Action (driver script) has scope on the class but the actions it calls does not have scope. What am I doing wrong?

    Thanks in Advance
    Green

  2. #2
    Member
    Join Date
    Jul 2007
    Location
    AUSTRALIA
    Posts
    68
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Scope of Class in resource lib

    Hi Mr Green Screens,

    I imagine that a class is similar to a public function in the way it uses objects.
    When I create a public function in QTP 9.5, I put any objects the public function uses into my shared repository.

    You need to Associate the shared repository with any tests that call the public function.

    If the shared repository isn't associated, the public function doesn't work because it cannot find the objects.

  3. #3
    Senior Member
    Join Date
    Apr 2007
    Posts
    124
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Scope of Class in resource lib

    To make object global in QTP (and your clas instance is not exclusion) you need:

    1. Declare it in any lib file (as Public variable), can be done in the same place you have your class and that function that makes instance (good job btw). like that:

    <font color="blue">Public</font> objStupidQTP

    2. Remove all declarations of objStupidQTP from your Actions. As QTP wouldn't mind to have more than 1 (if it is not in attached lib file)


    1 note: The order is important when you attach lib files. Took me a while to doscover that QTP reads them from bottom list. (all declarations should be in the last one)
    QA automation

  4. #4
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: Scope of Class in resource lib

    [ QUOTE ]

    1 note: The order is important when you attach lib files. Took me a while to doscover that QTP reads them from bottom list. (all declarations should be in the last one)


    [/ QUOTE ]

    Declaration can be any place as VBScript always move them to top. Here is a example of same

    Option Explicit
    Msgbox X
    Dim x

    What you are saying should be that initialization of these variable should be moved at the end.

  5. #5
    Member
    Join Date
    Sep 2008
    Posts
    65
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Scope of Class in resource lib

    My original response this morning was "Thanks for the help artemkv, my issue apparently was not making the object declaration "Public"."

    But... the fun never stops!
    I do have addressibility in my called action if I put the factory function call (to instantiate) in the func lib. BUT I lose the scope for the called action.

    If I put the factory function call in the calling action then the calling action has scope but the called action doesn't.
    And here is a detail that must be relevant but is mystifying to me.

    Scenario A:
    Instantiated in lib, called action has scope. When calling action throws the error it says " <font color="red"> Object required: '' </font> "

    Scenario B
    Instantiated in calling action, calling action has scope. When called action throws error it says " <font color="red">Object required: 'ErrObject' </font> "

    Why the difference?

    Here is Code in called action:
    <font class="small">Code:</font><hr /><pre> ErrObject.Mode = 1
    ErrObject.Origin = "MAG 006"
    ErrObject.Desc = DataTable.Value ("AssociationNumber", dtLocalSheet)&amp;" contained invalid Data" </pre><hr />

    Here is the code from calling action:
    <font class="small">Code:</font><hr /><pre> If ErrObject.Mode &lt;&gt; 0 Then
    ErrObject.Logger
    TeWindow("TeWindow").TeScreen("MASI 006 CODE ACCT").SendKey TE_PF2
    Exit Do
    End If </pre><hr />

    Here is my lib:
    <font class="small">Code:</font><hr /><pre> Function getFehler()
    Set getFehler = New Fehler
    End Function




    Class Fehler
    Private miMode 'The type of Fehler
    Private miOrigin 'The Page or Module that experienced the Fehler
    Private miDesc 'Description of the Fehler that will be printed in the log

    Private Sub Class_Initialize()
    miMode = 0
    miOrigin = " "
    miDesc = " "
    End Sub

    'WHEN ADDING MODES THE RANGE CHECK ON THE "LET" AND THE SELECT CASE ON THE "GET" MUST BE UPDATED
    Public Property Let Mode(varM) '0 = No Fehler, 1 = Invalid Data
    If varM =&gt; 2 or varM &lt; 0 Then 'CHANGE THIS WHEN ADDING MORE MODES
    ERR.RAISE vbobjecterror + 1000, "Fehler Object", "Invalid Mode"
    End If
    miMode = varM
    End Property
    Public Property Get Mode
    Mode = miMode
    End Property

    Public Property Let Origin(varO)
    miOrigin = varO
    End Property
    Public Property Get Origin
    Origin = miOrigin
    End Property

    Public Property Let Desc(varD)
    miDesc = varD
    End Property
    Public Property Get Desc
    Desc = miDesc
    End Property


    Public Function Logger()
    Select Case miMode
    Case 0
    Reporter.ReportEvent micDone, " "&amp;miOrigin&amp;" " , " "&amp;miDesc&amp;" "
    Case 1
    Reporter.ReportEvent micFail, " "&amp;miOrigin&amp;" " , " "&amp;miDesc&amp;" "
    End Select
    ClearIt()
    End Function

    Public Function ClearIt()
    miMode = 0
    miOrigin = " "
    miDesc = " "
    End Function

    Private Sub Class_Terminate()
    ' If imMode &gt; 0 Then
    ' Logger()
    ' End If
    miMode = null
    miOrigin = null
    miDesc = null
    End Sub
    End Class
    Public ErrObject
    Set ErrObject = getFehler()

    </pre><hr />

    Anyone see what I am doing wrong here? Thanks!!!

  6. #6
    Senior Member
    Join Date
    Apr 2007
    Posts
    124
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Scope of Class in resource lib

    the problem in your lib file...I've tried to make another class and it works. Don't get what exactly is wrong, hold on..
    QA automation

  7. #7
    Member
    Join Date
    Sep 2008
    Posts
    65
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Scope of Class in resource lib

    This morning I edited my previous "Thank You" post with what follows. I guess by doing the edit it didn't show up as a new post. So I am copying it here:

    My original response this morning was "Thanks for the help artemkv, my issue apparently was not making the object declaration "Public"."

    But... the fun never stops!
    I do have addressibility in my called action if I put the factory function call (to instantiate) in the func lib. BUT I lose the scope for the called action.

    If I put the factory function call in the calling action then the calling action has scope but the called action doesn't.
    And here is a detail that must be relevant but is mystifying to me.

    Scenario A:
    Instantiated in lib, called action has scope. When calling action throws the error it says " Object required: '' "

    Scenario B
    Instantiated in calling action, calling action has scope. When called action throws error it says " Object required: 'ErrObject' "

    Why the difference?

    Here is Code in called action:
    Code:
    --------------------------------------------------------------------------------

    ErrObject.Mode = 1
    ErrObject.Origin = "MAG 006"
    ErrObject.Desc = DataTable.Value("AssociationNumber",dtLocalSheet)& amp;" contained invalid Data"

    --------------------------------------------------------------------------------


    Here is the code from calling action:
    Code:
    --------------------------------------------------------------------------------

    If ErrObject.Mode &lt;&gt; 0 Then
    ErrObject.Logger
    TeWindow("TeWindow").TeScreen("MASI 006 CODE ACCT").SendKey TE_PF2Exit DoEnd If

    --------------------------------------------------------------------------------


    Here is my lib:
    Code:
    --------------------------------------------------------------------------------

    Function getFehler()
    Set getFehler = New Fehler
    End Function




    Class Fehler
    Private miMode 'The type of Fehler
    Private miOrigin 'The Page or Module that experienced the Fehler
    Private miDesc 'Description of the Fehler that will be printed in the log

    Private Sub Class_Initialize()
    miMode = 0
    miOrigin = " "
    miDesc = " "
    End Sub

    'WHEN ADDING MODES THE RANGE CHECK ON THE "LET" AND THE SELECT CASE ON THE "GET" MUST BE UPDATED
    Public Property Let Mode(varM) '0 = No Fehler, 1 = Invalid Data
    If varM =&gt; 2 or varM &lt; 0 Then 'CHANGE THIS WHEN ADDING MORE MODES
    ERR.RAISE vbobjecterror + 1000, "Fehler Object", "Invalid Mode"
    End If
    miMode = varM
    End Property
    Public Property Get Mode
    ' Select Case miMode
    ' Case 0
    ' Mode = "No Current Errors"
    ' Case 1
    ' Mode = "Invalid Data"
    ' End Select
    Mode = miMode
    End Property

    Public Property Let Origin(varO)
    miOrigin = varO
    End Property
    Public Property Get Origin
    Origin = miOrigin
    End Property

    Public Property Let Desc(varD)
    miDesc = varD
    End Property
    Public Property Get Desc
    Desc = miDesc
    End Property


    Public Function Logger()
    Select Case miMode
    Case 0
    Reporter.ReportEvent micDone, " "&amp;miOrigin&amp;" " , " "&amp;miDesc&amp;" "
    Case 1
    Reporter.ReportEvent micFail, " "&amp;miOrigin&amp;" " , " "&amp;miDesc&amp;" "
    End Select
    ClearIt()
    End Function

    Public Function ClearIt()
    miMode = 0
    miOrigin = " "
    miDesc = " "
    End Function

    Private Sub Class_Terminate()
    ' If imMode &gt; 0 Then
    ' Logger()
    ' End If
    miMode = null
    miOrigin = null
    miDesc = null
    End Sub
    End Class
    Public ErrObject
    Set ErrObject = getFehler()

    --------------------------------------------------------------------------------


    Anyone see what I am doing wrong here? Thanks!!!

  8. #8
    Senior Member
    Join Date
    Apr 2007
    Posts
    124
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Scope of Class in resource lib

    you know what,,. for now to get it done,get rid of all getters and setters in your class.It works without that crap. And make those memebers public. VBScript is not fully object oriented anyways, who knows maybe QTP adding some stupid rules on top of that...I'll look closer at this issue, thanks for pointing it out!

    Class Fehler
    Public miMode 'The type of Fehler
    Public miOrigin 'The Page or Module that experienced the Fehler
    Public miDesc 'Description of the Fehler that will be printed in the log
    QA automation

  9. #9
    Member
    Join Date
    Sep 2008
    Posts
    65
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Scope of Class in resource lib

    OK, Now my class looks like this:
    <font class="small">Code:</font><hr /><pre> Function getFehler()
    Set getFehler = New Fehler
    End Function




    Class Fehler
    Public Mode 'The type of Fehler
    Public Origin 'The Page or Module that experienced the Fehler
    Public Desc 'Description of the Fehler that will be printed in the log

    Private Sub Class_Initialize()
    Mode = 0
    Origin = " "
    Desc = " "
    End Sub

    'WHEN ADDING MODES THE RANGE CHECK ON THE "LET" AND THE SELECT CASE ON THE "GET" MUST BE UPDATED
    ' Public Property Let Mode(varM) '0 = No Fehler, 1 = Invalid Data
    ' If varM =&gt; 2 or varM &lt; 0 Then 'CHANGE THIS WHEN ADDING MORE MODES
    ' ERR.RAISE vbobjecterror + 1000, "Fehler Object", "Invalid Mode"
    ' End If
    ' miMode = varM
    ' End Property
    ' Public Property Get Mode
    '' Select Case miMode
    '' Case 0
    '' Mode = "No Current Errors"
    '' Case 1
    '' Mode = "Invalid Data"
    '' End Select
    ' Mode = miMode
    ' End Property
    '
    ' Public Property Let Origin(varO)
    ' miOrigin = varO
    ' End Property
    ' Public Property Get Origin
    ' Origin = miOrigin
    ' End Property
    '
    ' Public Property Let Desc(varD)
    ' miDesc = varD
    ' End Property
    ' Public Property Get Desc
    ' Desc = miDesc
    ' End Property


    Public Function Logger()
    Select Case Mode
    Case 0
    Reporter.ReportEvent micDone, " "&amp;Origin&amp;" " , " "&amp;Desc&amp;" "
    Case 1
    Reporter.ReportEvent micFail, " "&amp;Origin&amp;" " , " "&amp;Desc&amp;" "
    End Select
    ClearIt()
    End Function

    Public Function ClearIt()
    Mode = 0
    Origin = " "
    Desc = " "
    End Function

    Private Sub Class_Terminate()
    ' If imMode &gt; 0 Then
    ' Logger()
    ' End If
    Mode = null
    Origin = null
    Desc = null
    End Sub
    End Class
    Public ErrObject
    Set ErrObject = getFehler()

    </pre><hr />


    It's still showing same behavior as explained in my previous post.

  10. #10
    Member
    Join Date
    Sep 2008
    Posts
    65
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Scope of Class in resource lib

    ARTEMKV! I figured out my problem. You didn't have a chance because the problem was not in anything I showed you. When I originally wrote the class in my action I had put the object name in my 'group DIM' statement at the top of the action and never removed it. So I had two declarations for it, a global one int he lib and a local one in the action. I took it out and it works fine. Thanks so much for your help, sorry for the sabotage.

 

 
Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.71%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 01:12 PM.

Copyright BetaSoft Inc.