Run Code Snippet Operation

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

Use the Run Code Snippet operation to execute a script statement or call an object’s method from a keyword test.

This operation is like the Run Script Routine operation. However, you use it to execute an individual script statement, not a script routine. Usually, you use the operation to perform an action that you cannot perform by using the existing keyword operations.

The script statement the operation executes must be a single-line statement.

To assign values to variables, we recommend that you use the Set Variable Value operation.

Operation Result

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.

Child Operations

The operation cannot have child operations.

Operation Parameters

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.

Remarks

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 statement:

VBScript

Execute("KeywordTests.Test1.Variables.Var1 = 10")

Alternatively, use the Set Variable Value operation to assign variables.

Example

The following example includes a script statement that sends an HTTP request and gets the global IP address of your machine in the response:

The Run Code Snippet Operation

See Also

Test Actions Category
Specifying Operation Parameters
Checking Operation Result
Run Script Routine Operation
Set Variable Value Operation

Highlight search results