Forum Discussion

pgrow's avatar
pgrow
New Contributor
14 years ago

how to get return value out of tested application put into testcomplete project variable

I have an c# application which does some work (separate from any script) and I need to get the result out of it back into my testcomplete script any way possible, so far I have tried the 'Creating Connected Applications in C#', I am able to start the c#.exe from my unit script below, but I don't know how to get the string result of the application. So far I am trying the method where testecomplete has the dll in its project CLR bridge, so I thought it has access to the object of my C# application, and its result-right? Or is there another way? I checked the help, and wish I had seen there was an example for this.

My project looks like this:

LoadSuite

 LoadProject

  Unit1

function Main()

{

  try

  {

      var p;

      p = TestedApps["Items"](0)["Run"](); //this is Authentication.Authprogram C# program



      //HOW TO GET STRING RESULT from the app I just started? p.?



      while (p["Exists"])

        aqUtils["Delay"](500);

 

  }

  catch(exception)

  {

    Log["Error"]("Exception", exception["description"]);

  }

}



my C# app:

namespace Authentication

{

    public class AuthProgram

    {



     public static string HttpPost(string uri, string parameters)

        {  

           string foo;

         //etc, etc, does some stuff -tested it, this function works!

          returns foo;

   }



I followed the help carefully , included the testcomplete 2 dll's in the C# application assembly and got the app's dll put and recognized into testcomplete project properties, etc.Thanks for any advice!

3 Replies

  • pgrow's avatar
    pgrow
    New Contributor
    I am trying your suggestion but TC cannot find my process. 'Process not found. The object does not exist'.

    Can anyone help..

    I added the console app to my TestedApps.

    Here is new script - it appears I only needed to modify the 3rd line for my app name.



    Sub MyTest

      Dim p, w, txt, cnt, i, s



      Set p = Sys.Process("ConsoleAuth.exe")

      Set w = p.Window("ConsoleWindowClass", "*")



      txt = w.wText

      ' Specify the separator

      aqString.ListSeparator = vbNewLine

      ' Obtain the list's length

      cnt = aqString.GetListLength(txt)



      For i = 0 To cnt - 1

        ' Obtain a line

        s = aqString.GetListItem(txt, i)

        ' Post the line to the test log

        Call Log.Message(s)

      Next

    End Sub
  • Hi Paule,


    You do not need to include the ".exe" string in the process name. Just use the name as it is specified in the Object Browser window.