Forum Discussion

AndyH79's avatar
AndyH79
New Contributor
14 years ago

Need to store an Object's parameter's value as a .NET 4 data type

I have a Visual Studio 2010 C# project which is running code to automate access to websites using IE. I need to know how to expose the property value located within the TestComplete object browser and store that value as a .NET datatype which I can export to SQL Server. I'm able to obtain the object reference using:




var totalMetersCell = page["TrendMeterUsage"]["formMeterresults"]["tableMainguitable"]["cell"]["table"]["cell"]["panelControlspanel"]["table"]["cell"]["table"]["cell"]["table"]["cellNncTdnncbody"];

var totalMetersForm = totalMetersCell["panelTabbody"]["panelNncDivlist"]["frameNncFrmlist"]["frameNncListMain"]["formNnclist"];




I can successfully do this:

var count = totalMetersForm["innerText"] ;

but it doesn't expose any values I can use in the locals window.



I've also tried  this:

string count = (totalMetersForm["innerText"]).ToString();

which doesn't trip an error but stores "AutomatedQA.script.var+VarDelegate" as the value of count.



I'm also curious why this doesn't work:

var props = Connect.aqObject["GetProperties"](totalMetersForm);



It seems like a lot of the different functions with example code in the documentation don't work when you implement them as C# code in the Visual Studio project. Something I'm doing wrong? Or just lack of support for Connected Applications?

2 Replies

  • Hello Andy,



    Currently, it is necessary to add parentheses when obtaining TestComplete objects. Otherwise, some methods such as GetProperties will work incorrectly with these objects. We are going to change this behavior in one of future versions of TestComplete, so it won't be necessary to add parentheses when obtaining TestComplete objects from within a connected application.



    Besides that, TestComplete objects don't implement the ToString() method. You need to convert it to the appropriate type using the following syntax:

    string text = (string)totalMetersForm["innerText"];




    So, to obtain the innerText property of the totalMetersForm object, use the following code in your connected application:



    var totalMetersForm = totalMetersCell["panelTabbody"]["panelNncDivlist"]["frameNncFrmlist"]["frameNncListMain"]["formNnclist"](); //parentheses are required!

    string text = (string)totalMetersForm["innerText"];
     





    Besides that, you can iterate through all properties of the totalMetersForm object and obtain their values using the following code:





    var totalMetersForm = totalMetersCell["panelTabbody"]["panelNncDivlist"]["frameNncFrmlist"]["frameNncListMain"]["formNnclist"](); //parentheses are required!
     

    var props = Connect.aqObject["GetProperties"](totalMetersForm);
     

    var prop = props;
     

    while ((bool)props["HasNext"])
     

    {
     

      prop = props["Next"];
     

      string name = prop["Name"]();
     

      string val = Connect.aqConvert["VarToStr"](prop["Value"]());
     

    }
     









    It seems like a lot of the different functions with example code in the documentation don't work when you implement them as C# code in the Visual Studio project. Something I'm doing wrong? Or just lack of support for Connected Applications?





    C# code provided in the documentation should work correctly in Connected applications. If you have found some sample code that does not work, please specify the exact help topic and the code snippet(s) that does not work. We will look into this.