[Expand]General Information/viewarticle/88628/
 [Expand]Using Help System/viewarticle/81465/
 [Expand]Getting Started Tutorial/viewarticle/82003/
 [Collapse]Using TestComplete/viewarticle/84431/
  [Expand]TestComplete User Interface, Projects and Settings/viewarticle/87798/
  [Collapse]Creating, Recording and Running Tests/viewarticle/88044/
   [Expand]Naming Objects/viewarticle/82017/
   [Expand]Creating Tests/viewarticle/83818/
   [Expand]Managing Tested Applications/viewarticle/85827/
   [Expand]Checkpoints and Stores/viewarticle/82018/
   [Expand]Running Tests/viewarticle/83220/
   [Expand]Handling Playback Errors/viewarticle/84986/
   [Collapse]Keyword Testing/viewarticle/80985/
     Keyword Testing in TestComplete - Overview/viewarticle/81102/
     Creating and Recording Keyword Tests/viewarticle/85467/
     Running Keyword Tests/viewarticle/82503/
     Setting and Checking a Keyword Test Result/viewarticle/84662/
     Keyword Test Parameters/viewarticle/88748/
     Keyword Test Variables/viewarticle/87474/
     Converting Keyword Tests to Scripts/viewarticle/81037/
    [Expand]Creating Keyword Tests - Common Tasks/viewarticle/85045/
    [Collapse]Operations Reference/viewarticle/86157/
     [Expand]Checkpoints Category/viewarticle/80980/
     [Expand]Logging Category/viewarticle/82051/
     [Expand]Miscellaneous Category/viewarticle/86474/
     [Expand]Performance Category/viewarticle/81418/
     [Expand]Statements Category/viewarticle/82060/
     [Collapse]Test Actions Category/viewarticle/82040/
       Call Object Method Operation/viewarticle/82034/
       Data-Driven Loop Operation/viewarticle/81130/
       Find Object Operation/viewarticle/81449/
       If Object Operation/viewarticle/87714/
       Menu Action Operation/viewarticle/83704/
       On-Screen Action Operation/viewarticle/81021/
       Process Action Operation/viewarticle/85307/
       Run Code Snippet Operation/viewarticle/82008/
       Run Keyword Test Operation/viewarticle/82686/
       Run Script Routine Operation/viewarticle/82030/
       Run Test Operation/viewarticle/82300/
       Run TestedApp Operation/viewarticle/80916/
     [Expand]Web Category/viewarticle/81214/
      Frequently Used Category/viewarticle/81256/
      Selecting Objects for Keyword Test Operations/viewarticle/85788/
   [Expand]Test Visualizer/viewarticle/80575/
   [Expand]Exploring Applications/viewarticle/80624/
   [Expand]Debugging Tests/viewarticle/83018/
  [Expand]Test Results/viewarticle/80579/
  [Expand]Enhancing Tests/viewarticle/83506/
  [Expand]Teamwork and Integration Into QA Process/viewarticle/84972/
  [Expand]Extending TestComplete/viewarticle/81408/
  [Expand]Automating TestComplete/viewarticle/88022/
  [Expand]Best Practices/viewarticle/87218/
 [Expand]Testing Types/viewarticle/85355/
 [Expand]Applications Testing/viewarticle/83383/
 [Expand]Working With Application Objects and Controls/viewarticle/81481/
 [Expand]Samples and Tutorials/viewarticle/81997/
 [Expand]Other Tools That Help You Test Better/viewarticle/82893/
 [Expand]TestComplete Licensing Guide/viewarticle/88365/
Updated: 10/12/2016 Applies To: TestComplete 12 Rating: No votes Click to rate: PoorNot badAverageGoodExcellent
Keyword Testing Operations: Test Actions Category

Run Code Snippet Operation


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.

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.

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.


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:


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

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

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

© 2016 SmartBear Software. All rights reserved.
Email Send feedback on this document