Global variable

If I'd to define a global variable "x" in A.script from A.suite, can I refer this global variable "x" in other scripts in B.suite? B.suite is a test suite sourced from A.suite. I did try before and it was not successful.

Is there a way to refer global variable from A.suite in B.suite?

regards
Ai Choo

Comments

  • JonathanOSXJonathanOSX ForumAdmin admin
    Yes, globals can be shared across suites and scrips. They just need to be part of a single execution and you need to have ALL references to the variable include the word global (not just a declaration or the initial reference).
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    Just to clarify a bit, since this seems to be confusing sometimes:

    To treat a variable as a global, you must EITHER declare it as global in every script and handler where it is used, such as:
    global x,y
    set point to (x,y) -- uses global x and y
    
    OR you must use the word global before the variable name every time it is used, like this:
    set point to (global x, global y)
    
    You can use whichever approach you like (or even both, although once a variable has been declared as global in a handler, there is no need to use the word global before the name within that handler).

    The exact same rules apply to universal variables (which retain their values across multiple runs during the same Eggplant session).
Sign In or Register to comment.