SPONSORS:






User Tag List

Results 1 to 10 of 10
  1. #1
    Member
    Join Date
    May 2001
    Location
    Santa Clara, CA, USA
    Posts
    57
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Global Variables - Best Practise

    Hi,
    I wanted to know whats the best practice wrt to Global Variables. What I mean is
    should U declare the Global variables in the .inc file or should I create a .ini file and access then from there.
    Whats the best practice and what are the pros and cons

    Any suggestions would be appreciated for this beginer


  2. #2
    Senior Member
    Join Date
    Mar 2000
    Location
    Dublin, Ireland
    Posts
    152
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Global Variables - Best Practise

    Hi,

    I would recommend that you keep things simple and use an include file for global variables. Placing global variables into an .ini file is going to require code to extract the values and place them into local variables.

    John.

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

    John O'Neill.
    Quality Automation Ltd.
    www.quality-automation.com
    John O'Neill.
    Quality Automation Ltd.
    www.quality-automation.com

  3. #3
    Senior Member
    Join Date
    Aug 1999
    Location
    Cambridge, UK
    Posts
    470
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Global Variables - Best Practise

    An ini file is not best used for global variables of the ordinary sort. What it is very useful for is the (relatively rare) case where you need to remember a variable value from one testcase to the next; silktest does not hold any variables in memory between testcases, so an ini file is a fairly easy way of doing this.
    But be careful; if you find yourself requiring this a lot, then you might want to look again at your test designs; one element of good testing practice is that the operation of one test should not depend on the success or failure of previous tests, so it should be something unusual which requires you to store variables in an ini file. One example of what we use an ini file for here is when a testcase captures a screenshot of the app under certain error conditions (in order to help identify the bug quickly), we number the screenshots taken, and the 'highest-screenshot-number-so-far' has to be recorded somewhere outside of silktest.

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

  4. #4
    Junior Member
    Join Date
    May 2001
    Location
    Portland, OR
    Posts
    27
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Global Variables - Best Practise

    I agree with using the .inc file to store global variables. I generally create two files named Constants.inc and Variables.inc. Much like the names imply, if I have Global constants I place them in Constants.inc, if I have Global variables then I place them in Variables.inc.

    Hope this helps.

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

  5. #5
    Member
    Join Date
    May 2001
    Location
    Santa Clara, CA, USA
    Posts
    57
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Global Variables - Best Practise

    Thanks for all the ans. I am clear on the usage now.
    I really appreciate the quick responses I get on this forum.

  6. #6
    Senior Member
    Join Date
    Jan 2001
    Posts
    750
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Global Variables - Best Practise

    vincebowdren has some good points.

    Rule of thumb:

    Grab all the ones that are common to all your script and put it in an .inc file.

    All the rest can go in an .ini file. if you can somehow classify them.

    .inc require no knowledge of the constant.
    .ini require you know what kind of costant it is used for and classify it under sections. You don't want too many of them.



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

  7. #7
    Senior Member
    Join Date
    Jul 1999
    Location
    Burlingame CA 94010
    Posts
    502
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Global Variables - Best Practise

    I normally recommend using .ini files when different users need different values for global variables.

    For example, suppose you have 5 people on the automation team, and each one tests a different URL, with a different user, password, and database. Using a local .ini file on each user's machine, these values can be set differently for each user, while sharing one common test frame.

    Silk has easy-to-use functions for setting and retrieving values from .ini files.

    You can also write to these .ini files from the top of a master testplan, changing specific values before running the test.

    Hope this helps


    ------------------
    John W Green
    jwgreen@automationexpertise.com
    http://www.automationexpertise.com

  8. #8
    Senior Member
    Join Date
    Jan 2001
    Posts
    750
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Global Variables - Best Practise

    After reading all of you. I see a weak point.

    Reading from a file requires a variable declaration(once this is done you can't remove it) This said all common variables for all scripts in a inc file should do the job. Then you don't even need to declare new variables. Just access them.

    Read from an ini file and get all of it values sounds weak.

    Ini is only good to keep track of mutiple information of same structure; as Tom said userid and password.


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

  9. #9
    Senior Member
    Join Date
    Jul 1999
    Location
    Bellingham, WA USA
    Posts
    1,323
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Global Variables - Best Practise

    John has a bullseye with this one. My team uses a local ini file on every test box in the system. We also use a shared include file with a GetSetupValue( ) method to access anything in that ini file. The purpose of using this ini file is to populate all variable values that would potentially tie the script to a specific machine. It works beautifully.

  10. #10
    Senior Member
    Join Date
    Aug 1999
    Location
    San Diego, CA USA
    Posts
    219
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Global Variables - Best Practise

    I initially setup my frame file to use global variables and they have grown to a point where they're hard to maintain. At one point I even setup a way for script developers to be able to TEMPORARILY override them (to support their development and debugging effrots) without having to actually edit the Globals.inc file. The approach works but it's kludgy at best and not all that intuitive either.

    I even developed my own kludgy way to "remember" vlaues from one testcase to the next - that was before I looked into the built-in functions for working with INI files.

    I am currently in the process of deciding which "global variables" are best left as the usual kind of global variable (basically ones that should not change often if at all) and which ones are best handled using the INI file approach. I've already experimented with having TestCaseEnter read the INI file and having TestCaseExit write to the INI file.

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

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin 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 02:30 AM.

Copyright BetaSoft Inc.