This page contains a quick introduction to scripting. For more information see the API.
The code in a script action can access the _Scenario
object and the _Results
object as well as any variables created in the scenario.
The code can also call any other script actions by calling the Method Name
of the script action and passing the
object and the _Results
object as a parameters.
Each script item requires a return type of System.string.
The string returned is added to the notes field in the results.
Any Exceptions thrown will be added to the results as Errors.
NB: When using custom .net modules, ensure that the dll is in the GAC or the same directory as the application.
The list of actions in the scenario is accessed by the code
This returns an ActionItemCollection (Inherits from IList
). Individual actions can be accessed by name or index
Actions are returned as an ActionItem, this is an abstract class that represents all actions.
This obejct has the following properties that can be accessed.
ActionItem action = _Scenario.Actions; // Gets the first action in the scenario
string s = action.Name;
ActionType at = action.ActionType;
string ct = action.CustomType;
bool hc = action.HasChildren;
bool cac= action.CanAddChildren;
ActionItem p = action.Parent;
int i = action.Index;
ActionItem ai = action.FindChild(Guid key);
ActionItem array = action.FindChildren(Guid key);
- ActionItem.Name : the name of the action.
- ActionItem.ActionType : legacy value. This is only used to differentiate between actions that use compiled code (If statements, variables, c# scripts) and those that don't.
- ActionItem.CustomType : the type of the action
- ActionItem.HasChildren : if this action has any child actions
- ActionItem.CanAddChildren : if this action accepts new children
- ActionItem.Parent : the parent of this action.
- ActionItem.Index : this actions index in its parent.
The results obejct contains information about any actions that have already been executed and is accessed from the object:
This returns a ScenarioResults object.
- This returns an ActionResultsCollection (Inherits from IList, ICollection and
IEnumerable). Individual actions can be accessed by name, index or key.
- The key is the same as the ActionItem that was used to create it.
- If the an ActionItem runs multiple times (due to loops, etc.) the suffix " (n)" is added to the original name, where n is the count.
- the count is zero base, but only shows on the second item onwards.
ActionResults result = _Results.Results[Guid key];
Dictionary<string, object> result.Data;
Dictionary<string, object> result.Results;
- The ActionType can be used to determine with a type comparison of the action or by using the CustomType field.
ActionItem_WebRequest webrequest = (ActionItem_WebRequest)action;
ActionItem_Folder folder = (ActionItem_Folder)action;
ActionItem_If if_action = (ActionItem_If)action;
ActionItem_Loop loop = (ActionItem_Loop)action;
ActionItem_Script script = (ActionItem_Script)action;
ActionItem_Variable variable = (ActionItem_Variable)action;
- Once cast to a specific type, the options specific to that action can be accessed.
- See the API for more details on these options.
// The following example changes the uri of the WebRequest with name "request_01"
ActionItem action = _Scenario.Actions["request_01"];
if(action != null && action.ActionType == ActionType.WebRequest)
ActionItem_WebRequest request_1 = (ActionItem_WebRequest)action;
request_1.Uri = new Uri("www.webpaltt.codeplex.com");
- Each scenario contains a list of cookies (List<Cookies> not a
CookieContainer or CookieCollection)
- New cookies are automatically added to when a response contains a set-cookie header.
- This list of cookies are also added to each request when sent.
To manually alter the cookies the list can be accessed as follows.
// Adds a new cookie with name "uid" and value "username" to the list if it is empty.
if(_Scenario.Cookies.Count == 0)
_Scenario.Cookies.Add(new Cookie("uid", "username"));