Use the Run Code Snippet operation to execute a script statement or method call from your keyword test.
This operation is like the Run Script Routine operation, but you use it to call a script statement that is not a script routine. You usually use the operation to call an object’s method or property that does not have a keyword test analogue, and there is no need to create a script statement for this.
|The called script statement must be a single-lined statement.|
To assign variable values, we recommend that you use the Set Variable Value operation.
If the executed script statement returns a value (for instance, if the statement is a method call and the method returns some value), then the operation returns this value. For information on how to obtain this value, see Checking Operation Result.
If the executed script statement does not return any value, the operation has no result value as well.
The operation cannot have child operations.
When you add the operation to your keyword test, TestComplete displays a dialog where you can specify the operation parameters. The dialog contains an edit box in which you can enter the desired script statement. You can also add an object to this statement. The way you add it depends on the object’s type:
If the object is an on-screen window or control, click Select On-Screen Object and choose the desired window or control in the subsequent Select Object dialog.
If the object is a TestComplete run-time object, click Select Object and choose the desired object in the subsequent Select Runtime Object dialog.
If the object’s name is stored in a project suite, project or keyword test variable, click Select Variable and choose the needed variable or create a new one in the Select Variable dialog.
To modify parameters of the operation you added earlier, simply double-click the operation row in the Keyword Test editor. TestComplete will invoke the dialog in which you can enter the desired script code.
In VBScript projects, Run Code Snippet treats the equals sign (=) as a comparison operator by default, not as an assignment operator. To use Run Code Snippet for assigning variables, put an assignment into the
Execute("KeywordTests.Test1.Variables.Var1 = 10")
Alternatively, use the Set Variable Value operation to assign variables.