cancel
Showing results for 
Search instead for 
Did you mean: 

Cast Object as WPF Object

SOLVED
Highlighted
New Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

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.)

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

2 REPLIES 2
Highlighted
Community Hero

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.)

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

Highlighted
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

New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Get properties of a web page element

See replies!

Compare images using the Region Checkpoint

See replies!

Compare HTML table with Excel file and correct data in Excel file

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!
Top Kudoed Authors