Ask a Question

Using script variables in keyword tests

edrider
New Contributor

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 3
YMinaev
Staff

Hi,



Use a keyword test variable. In your code, assign the needed value to it. See the "Keyword Test Variables" help topic.
------
Yuri
TestComplete Customer Care Engineer

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
edrider
New Contributor

Using "%USERPROFILE%" in a keyword test variable does not work.
YMinaev
Staff

Hi,



Expand this environment variable in script and assign the result to a keyword test variable.
------
Yuri
TestComplete Customer Care Engineer

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: