Forum Discussion

RobertPeip's avatar
RobertPeip
New Contributor
5 years ago

Cast Object as WPF Object

Hi,

 

i'm trying to use Testcomplete standard functions with an object received directly from a function call to a WPF/.net application on a request, rather than going through the usual Namemapping/Search tree.

 

It looks like this:

var obj = Aliases.App.Main.GetControl();

 

This obj can access all .net properties and methods just fine.

E.g. for a Button i can call

obj.OnClick();

 

However,  if the button was received through namemapping like this:

var NMobj = Aliases.App.Main.ButtonTest;

 

I can also access e.g:

NMobj.Click();

 

Which doesn't work with "obj" because "this object doesn't support this method".

So my question is: is there any possibility to tell Testcomplete, that "obj" is a WPFButton, to make all the usual methods available?

I tried FindChild with some of the attributes of "obj", to receive a Testcomplete object, which works, but it takes around 10 seconds for every control, which is not acceptable.

 

Any better possibility?

 

Thanks a lot!

Robert

  • Hi Robert,

     

    is there any possibility to tell Testcomplete, that "obj" is a WPFButton

    No, this is not possible.

    If I got it right, .GetControl() is a method of the tested application that returns native .Net object. WPFButton (and others a-like) is TestComplete's wrapper over the .Net object identified via the means provided by TestComplete.

    10 seconds for every control seems weird and my guess is that you should optimize either your NameMapping/Aliases or the way how .FindChild is used. (For example, the search that starts at application level and searches for the object that is too deep in the wide objects tree might be slow. But the preliminary search for one or several intermediate parent containers for the same object might speed up the search quite significantly.)

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Robert,

     

    is there any possibility to tell Testcomplete, that "obj" is a WPFButton

    No, this is not possible.

    If I got it right, .GetControl() is a method of the tested application that returns native .Net object. WPFButton (and others a-like) is TestComplete's wrapper over the .Net object identified via the means provided by TestComplete.

    10 seconds for every control seems weird and my guess is that you should optimize either your NameMapping/Aliases or the way how .FindChild is used. (For example, the search that starts at application level and searches for the object that is too deep in the wide objects tree might be slow. But the preliminary search for one or several intermediate parent containers for the same object might speed up the search quite significantly.)

     

    • RobertPeip's avatar
      RobertPeip
      New Contributor

      Hi Alex,

       

      thanks a lot for your answer.

       

      It's unfortunate, that casting the object would not work.

       

      FindChild probably takes 10 seconds, because the target object isn't mapped at all and it's a large application with thousands of objects and many hierarchy levels. Visible at once however maybe few 100.

       

      This method with getting the object from .net within few milliseconds was a new approach so we don't need the namemapping, which is just a massive bloat of work to create and maintain with so many objects and changing hierarchy structures.

      It's all handwork(drag here, click here, choose names, choose properties...) and hierarchies that are sometimes there and sometimes not doesn't work well with the namemapping either, so we require something better.

       

      Best regards,

      Robert