Forum Discussion

edrider's avatar
edrider
New Contributor
15 years ago

Using script variables in keyword tests

Hi there folks, I am trying to call a script variable for use as a keyword test value.



The script variable holds the location of the current users desktop, and looks like ....



function desktopPath()

{

  try

  {

    var wshShell = Sys.OleObject("WScript.Shell");

    var desktopPath = (wshShell.ExpandEnvironmentStrings("%USERPROFILE%\\Desktop"));

    Log.Message(desktopPath);

  }

  catch(exception)

  {

    Log.Error("Exception", exception.description);

  }

}






I am trying to use "desktopPath" variable as the value of a step in my keyword test which saves a file.



I want to be able to re-use this "desktopPath" variable throughout my keyword test so that the need to hardcode filepaths is removed.  I am aware that I could simply use a regular test variable and put the path in there, but the special folder %USERPROFILE% does not work there.



The use of %USERPROFILE% is crucial so that my keyword tests will work which ever system or user profile they are run on.



Hope that all makes sense, thanks.

3 Replies

  • Hi,



    Use a keyword test variable. In your code, assign the needed value to it. See the "Keyword Test Variables" help topic.
  • edrider's avatar
    edrider
    New Contributor
    Using "%USERPROFILE%" in a keyword test variable does not work.
  • Hi,



    Expand this environment variable in script and assign the result to a keyword test variable.