Forum Discussion

dbaechtel's avatar
dbaechtel
Contributor
11 years ago

Can I make a Project wide Variable for Username and Password ?

I am doing web application testing. I would like to store a Username and Password variable that will be used project wide. I would obviously like this Username and Password value to be as hidden as possible and possibly cleared at the end of each test session.

What is the best way to manage this?

3 Replies

  • MikeSchmid's avatar
    MikeSchmid
    Occasional Contributor
    Alternately you can set up a project variable or project suite variable.

    Open the project item and click the variables tab. Set up your temporary variable variables. Since you want them hidden leave the default values blank.

    Then when you want to populate them all you have to do is set Project.Variables.variable name=value

    or ProjectSuite.Variables.variable name=value

    And clear them at the end of the run.
  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    You'll want to look at the USEUNIT option as well as creating a global variable by placing it outside all procedures/functions. As far as securing the password you may use something like this for simple encryption/decryption:





    'VBS Example

    Function encrypt(Str, key)

    Newstr = ""


    lenKey = Len(key)


    KeyPos = 1


    LenStr = Len(Str)


    str = StrReverse(str)


    For x = 1 To LenStr


     Newstr = Newstr & chr(asc(Mid(str,x,1)) + Asc(Mid(key,KeyPos,1)))


     KeyPos = keypos + 1


     If KeyPos > lenKey Then KeyPos = 1


    Next


    encrypt = Newstr


    End Function


     


    Function decrypt(str,key)


    Newstr = ""


    lenKey = Len(key)


    KeyPos = 1


    LenStr = Len(Str)


    str=StrReverse(str)


    For x = LenStr To 1 Step -1


     Newstr = Newstr & chr(asc(Mid(str,x,1)) - Asc(Mid(key,KeyPos,1)))


     KeyPos = KeyPos+1


          If KeyPos > lenKey Then KeyPos = 1


    Next


          Newstr=StrReverse(Newstr)


          decrypt = Newstr


    End Function

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert

    Hi Don, we follow an approach similar to Mikes except we don't even persist the Project Variables.


     


    Instead, we store all usename/password information in an .ini file, then when tests are run, this .ini file is read and a combination of the following methods are used to create and purge Project Variables containing the credentials:


     


    Project.Variables.VariableExists()


    Project.Variables.AddVariable()


    Project.Variables.RemoveVariable()


     


    Because the runtime is interpreted, the Project Variables do not need to exist until the code accessing them is executed.


     


    Regards,


    Phil Baird