cancel
Showing results for 
Search instead for 
Did you mean: 

Checking WPF style in TestComplete

SOLVED
Highlighted
Occasional Contributor

Checking WPF style in TestComplete

We have a GUI based desktop application built using WPF.

 

There are requirements to check the colour change of the GUI controls when they are clicked.

 

However, the application uses WPF styles and apply the different styles when some controls are clicked/toggled etc.

When I use Object spy in TestComplete, the background and foreground properties do not reflect the real colours displayed and this is most probably due to the styles being applied instead of setting the colour changes directly using the background and foreground properties.

 

Does someone know a way to Identify these WPF style changes using TestComplete ?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Checking WPF style in TestComplete

Hi,

 

I am not knowledgeable in WPF development, so I will try to rephrase my understanding of your question.

I am guessing that 'style' in WPF is something that is similar to the 'style' in the web development. I.e. somewhere there is a defined set of properties and their values (width, color, size, etc.) with the name assigned to it. This name is assigned to the style property of the control when the style is applied to it. Then, during runtime, the engine parses the set of properties that are included in the style and assigns properties' values to the corresponding properties of the object been styled.

For your case, the above effectively means that your tested object must have a property named like 'color' and this property should contain the value of the color that the system must use when rendering this object on screen.

So, I still think that you should talk to your developers and ask them how styling works for WPF applications. What property of the object is used to keep the color to be used which is specified in the style?

For web, every web element has a method with the name like getComputedStyle that can be used to get the actual value of this or that styled property (color, size, visibility, etc.). Maybe something like this exists for WPF as well.

 

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

6 REPLIES 6
Community Hero

Re: Checking WPF style in TestComplete

Hi,

 

I would talk to developers and ask them how the applied style translates to the color. My expectation is that they will be able to name some native control's property that you will be able to read from test code.

 

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
================================
Highlighted
Occasional Contributor

Re: Checking WPF style in TestComplete

Yes, there is a property that applies the Style.

But the requirement is explicitly mentioning the colour change into Red or Blue. So, If there is a bug on using the property in the application code, TestComplete will still "Pass" the test case if we stick to using only the property for testing the Style.

 

I am surprised that this is not already handled in someway by TestComplete. Retrieving the style name at least will be a good start. 

Highlighted
Community Hero

Re: Checking WPF style in TestComplete

Hi,

 

I meant not the property with the name of the style, but the property that indicates the current color of the given element (text, background, border, etc.). If such property is exposed (i.e. is of public or published type) then TestComplete should be able to access it. Otherwise ask your developers for the method that returns color for the specified element of the control.

 

P.S. If there is a property that contains the name of the applied style, then you may consider slightly different approach: get the name of the applied style and for this style get the value of the required element (foreground/background color, etc.) and check that it is of required value (red, green, ...).

 

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
================================
Highlighted
Occasional Contributor

Re: Checking WPF style in TestComplete

"get the name of the applied style and for this style get the value of the required element (foreground/ background color, etc.)"

 

I can get the property that is exposed when a particular style is applied but the question is exactly the above statement from you - How do I get the color when I know this property that is known when a particular style is applied. I don't seem to find a way to do this. So, any pointers on this will be good.

 

 

Highlighted
Community Hero

Re: Checking WPF style in TestComplete

Hi,

 

I am not knowledgeable in WPF development, so I will try to rephrase my understanding of your question.

I am guessing that 'style' in WPF is something that is similar to the 'style' in the web development. I.e. somewhere there is a defined set of properties and their values (width, color, size, etc.) with the name assigned to it. This name is assigned to the style property of the control when the style is applied to it. Then, during runtime, the engine parses the set of properties that are included in the style and assigns properties' values to the corresponding properties of the object been styled.

For your case, the above effectively means that your tested object must have a property named like 'color' and this property should contain the value of the color that the system must use when rendering this object on screen.

So, I still think that you should talk to your developers and ask them how styling works for WPF applications. What property of the object is used to keep the color to be used which is specified in the style?

For web, every web element has a method with the name like getComputedStyle that can be used to get the actual value of this or that styled property (color, size, visibility, etc.). Maybe something like this exists for WPF as well.

 

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
Community Manager

Re: Checking WPF style in TestComplete

Thank you for the thorough explanation Alex!

 

@abinash11 does this answer help?


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors