Forum Discussion

abinash11's avatar
abinash11
Occasional Contributor
4 years ago
Solved

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 ?

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

     

6 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    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.

     

    • abinash11's avatar
      abinash11
      Occasional Contributor

      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. 

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

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