edrider
14 years agoNew 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.
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.