SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 7 of 7
  1. #1
    Member
    Join Date
    Jul 2004
    Location
    hyderabad
    Posts
    68
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    how to avoid sending varaible to each function

    I have main script which reads some variables from excel sheet once in the Test or Action1


    i have two library files a.txt b.txt

    i want the variable which i read in the Main QTP Script/Action1/Test
    to be available to the functions in the a.txt , b.txt lib files



    when i use public it is available only in a.txt to all functions

    what should i do ,so that i can ensure variable are available to all the library files etc

  2. #2
    Moderator
    Join Date
    Jan 2007
    Location
    Pittsburgh, PA
    Posts
    2,497
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to avoid sending varaible to each function

    You will need to declare public variables in function library and attach the library to test settings.

  3. #3
    Member
    Join Date
    Aug 2005
    Posts
    119
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to avoid sending varaible to each function

    you can also use environment variables and access its value in functions a.txt and b.txt

  4. #4
    Member
    Join Date
    Jul 2004
    Location
    hyderabad
    Posts
    68
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to avoid sending varaible to each function

    Reddy garu public variable usage is not working

    pls correct me .. if i am wrong

    the currect sitiation is

    i have Main QTP /Test in which i read the values in excel sheet

    there is an a.txt ,b.txt which has funcation definitions which are called from Main QTP /Test

    as i have a.txt ,b.txt i have declared "servername" varaible as public in a.txt and a.txt,b.txt are in Test Settings=>Resources=>associated function libraries

    in the Test(not in library i.e a.txt,b.txt ),i am reading "servername" but its not available in a.txt
    though i have read the value of the Server name from excel
    sheet in the TEST and its public variable in the a.txt file

    Pls suggest

  5. #5
    Member
    Join Date
    Oct 2007
    Posts
    68
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to avoid sending varaible to each function

    Hi Singh

    I thought of an approach

    '=======Main script========
    'a class named Global_MainScript
    'having public variables to share values
    'making it RW
    Class Global_MainScript

    Public Value1

    End Class

    Dim objGlobal

    Set objGlobal=New Global_MainScript

    'Pack the values here in instance variable of the class
    objGlobal.Value1="abc"

    'call method s1 in a.txt.Note :i has the parameter as the
    'class reference.
    s1(objGlobal)

    'call method s2 in b.txt.Note :i has the parameter as the
    'class reference
    s2( objGlobal)

    'Function Libraries:a.txt, b.txt

    '==============================

    Sub s2(objGlobal)

    msgbox objGlobal.Value1
    End Sub
    '============================


    Sub s1(objGlobal)

    msgbox objGlobal.Value1
    End Sub

    Note:This is a demo it can be made more versatile to implement inheritance and abstarction features. [img]/images/graemlins/smile.gif[/img]

  6. #6
    Junior Member
    Join Date
    Apr 2009
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to avoid sending varaible to each function

    I simply add the the public variable to the main test and it remains all the way through my functions, in fact in my framework I call all of the objects and paramters as variables and set them to as public in the main script - then all of the functions utilize those same variables without having to set them in each vbs (txt) file. Are you accidently reseting the value in one of the libraries?
    Jim

  7. #7
    Senior Member
    Join Date
    Jun 2007
    Location
    Toronto, Canada
    Posts
    362
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: how to avoid sending varaible to each function

    If it is just a couple of variables and in your case its just servername, use environment variables. create a user defined environment variable and retrieve the value of the environment variable in your functions

 

 

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 8.82%
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 12:05 PM.

Copyright BetaSoft Inc.