Forum Discussion

ashok_natar's avatar
ashok_natar
Occasional Contributor
11 years ago

Convert String to Objects

Hi All, 



We are working on the application, where the Objects are unstable hence decided to get the Objects from xml and use it. 



The issue is here! i am able to retrieved the node values successfully and when i print it, it printing the absolute the same string!!! 



Issues is the testcomplete could do the action correctly! and also it throwing an error message? 



is there any methord to convert the str to Object?



Really appreciated for any suggestion

sample code here !!

function Test_Test()

{

 try

{

filepath_Setup="T:\\NameMapping\\OBJ.xml"; 

var Obj_Customer=aqConvert["VarToStr"](Utility["doGetxmlvaluebyNode"](filepath_Setup,"Data_Article_Number")) ;

//var Obj_Customer1=aqConvert["VarToStr"](Utility["doGetxmlvaluebyNode"](filepath_Setup,"Data_Article")) ;

//

 

Log["Message"]("Before action")

 

Obj_Customer["WinFormsObject"]("Customer")["SetText"]("Symphony Telca")

 

Log["Message"]("After action")

 

  

 

}

  • Ashok,



    It's not clear from the snipped what Obj_Customer contains after the following statement:



    var Obj_Customer=aqConvert["VarToStr"](Utility["doGetxmlvaluebyNode"](filepath_Setup,"Data_Article_Number"))



    If it includes a TestComplete full name, try Obj_Customer = eval(Obj_Customer);
  • Ashok,



    It's not clear from the snipped what Obj_Customer contains after the following statement:



    var Obj_Customer=aqConvert["VarToStr"](Utility["doGetxmlvaluebyNode"](filepath_Setup,"Data_Article_Number"))



    If it includes a TestComplete full name, try Obj_Customer = eval(Obj_Customer);
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Ashok, the nature of forums is that urgent requests requesting direct attention from support staff may get lost. &nbsp;There is a customer support portal that you can send requests directly to SmartBear staff with a ticket number for issue tracking. &nbsp;You can find that here.<br /> <br /> http://support.smartbear.com/message/?prod=TestComplete<br /> <br /> <br /> <br /> <br />



    Again, as mentioned above, it's not clear as to exactly what is returned from the XML file.  Is it a fully qualified path to an object (for example, "Aliases.MyObject.MyCustomer") or is it some other value?  Without knowing exactly what it is you are getting from your xml, it's hard to give an answer as to the best way to resolve it.



    The eval method as suggested would work if the text returned as Obj_Customer is a fully qualified path as indicated above.  If it is simply a descriptor text string, it most likely will not work.



    If the text string returned is an Alias name for an aliased object, you could use



    Aliases.WaitAliasChild(Obj_Customer)




    This will return the object.



    If the text string returned is the value of a particular property on the object, you can use the FindChild method to find the object.  Having only a single property may make this more difficult so that most likely will be a lot trickier than you need.



    In any case, if you can reply with what the actual contents of Obj_Customer ends up being, we can target your answer for you with much more accuracy.









  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    You said:

    Obj_Customer is contents of 



    <Data>

    <Name>Obj_Customer</Name> <Value>Sys["Process"]("Orders")["WPFObject"]("HwndSource: OrderForm")["WPFObject"]("OrderForm")["WPFObject"]("gridMain")</Value></Data>




    This is why the eval does not work.  What you should do is have you code that reads the XML file return the Value contents, only.  It seems, if I'm reading this correctly, you're getting a lot of other XML as well.  So, you're trying to do, essentially



    eval(<Data>

    <Name>Obj_Customer</Name> <Value>Sys["Process"]("Orders")["WPFObject"]("HwndSource: OrderForm")["WPFObject"]("OrderForm")["WPFObject"]("gridMain")</Value></Data>)




    And that won't work.  You need to have your code grab that Value contents so that what you end up with is



    eval("Sys["Process"]("Orders")["WPFObject"]("HwndSource: OrderForm")["WPFObject"]("OrderForm")["WPFObject"]("gridMain")")




    Keep in mind, also, that if you're reading a set of quotes from the XML, it's probably being parsed out improperly in the attempt to eval... you may need to use a /" to send in your actual quotes.
  • ashok_natar's avatar
    ashok_natar
    Occasional Contributor
    Hi Mark Smith, 



    Thanks for your reply Mark, But it was not helped me.



    Hi Smeart Bear Team, 



    could you please step into this and throw some workaount...I can surly refer the customer id if that is, make you not to step in!







  • ashok_natar's avatar
    ashok_natar
    Occasional Contributor
    Thanks for the reply!!





    Obj_Customer is contents of 



    <Data>

    <Name>Obj_Customer</Name> <Value>Sys["Process"]("Orders")["WPFObject"]("HwndSource: OrderForm")["WPFObject"]("OrderForm")["WPFObject"]("gridMain")</Value></Data>

     

    and stored into the xml.



    Here what i want is!!! Instead of defining the entire Objects Namemapping directly into the scripts... Wanted to call from xml....

    here...

    Obj_Customer["WPFObject"]("Customer")["SetText"]("test"); 





    The testcomplete should perform the SetText action!! Which is only because its coming from xml....when i have written it throw(log.message(Obj_Customer)) i am getting the correct string!! Without any truncate... but the SetText action is not getting performed successfully, I mean it’s not entering the values into the text box!

  • ashok_natar's avatar
    ashok_natar
    Occasional Contributor


    Obj_Customer=



     



    Sys["Process"]("Orders")["WPFObject"]("HwndSource: OrderForm")["WPFObject"]("OrderForm")["WPFObject"]("gridMain")



    Obj_Customer["WPFObject"]("Customer")["SetText"]("retest")



    The above set of code is working well and fine!!!