Forum Discussion

sugia279's avatar
sugia279
Occasional Contributor
8 years ago
Solved

How to use FindAllChildren function by C#

Hi All, I try to use FindAllChildren function by C#, but the exception NulReferenceException is threw like the below image. I used code at https://support.smartbear.com/viewarticle/82015/?q=C%23+sc...
  • HKosova's avatar
    HKosova
    8 years ago

    Just to clarify.

     

    If you want to run TestComplete projects from C#, you should use the TestComplete COM object, TestComplete.TestCompleteApplication. See examples here.

    If you want to use the TestComplete engine to interact with applications and objects -- find objects, click objects, input text and so on, -- that's a different thing. Assuming you use TestComplete 12, the recommended way to do that is to use the TestComplete REST API. You can call it by using any C# REST client, such as RestSharp. This way you can write your own tool like TestLeft (TestLeft is built around this API). It requires some knowledge of REST APIs and JSON, though.

     

    To enable the REST API in TestComplete:

    • Launch TestComplete.
    • Go to File | Install Extensions and enable the REST API plugin in the Common category.

    After that you can browse the API documentation at:

    http://localhost:2377/1/docs/index.html

     

    Note that the API works only when TestComplete is running.

     


    The first API call should be

    POST http://localhost:2377/1/initialize

    to initialize the test engine. Then you can query the object tree (the Sys tree), get object properties, call object methods, etc.

    For example, a call to

    Sys.FindAllChildren("UserName", user_name, 1)

    can be done with the REST API as follows:

    POST http://localhost:2377/1/sys/4a9f9237-c1f7-4b80-9573-8440d7b37dc6/find_all?depth=1
    { "UserName": user_name }

    Data is passed and returned as JSON, which is easy enough to parse.

     

    Hope this helps!