Forum Discussion

Yoann's avatar
Yoann
Occasional Contributor
14 years ago

WPF TextBox caret and regions comparaison

Hi,

I'm getting test errors when comparing 2 pictures of the same TextBox, because of the blinking caret: sometimes visible, sometimes not... 

I didn't found any solution to hide it on the app side (WPF 3.5)...

Is there some trick to work around this problem? 

(working on TC v7.52)



Thanks!
  • Yoann's avatar
    Yoann
    Occasional Contributor
    Thank you for this help Jared,

    I want to avoid tolerance in pictures comparaison, but basing a method on Regions.FindRegion to determine if the caret is present, and wait it disappears to take the picture could do the trick.
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Yoann,



    Why not to move the focus to another control (thus moving the caret away from the current one) and do comparison then?
  • Yoann's avatar
    Yoann
    Occasional Contributor
    Hi Alexei,

    Because the application defines specific behavior on Focus lose :-)

    Basically a custom error template is shown on validation fail (=what i want to check), while the TextBox try to lose focus, in that case the control must keep the focus.
  • Yoann's avatar
    Yoann
    Occasional Contributor
    Yes there are solutions in Win32 and WPF4, but not found a clean one in WPF 3.5, that's why we'll work on the method I described above.

    I'll post our results.
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Yoann,



    Well... To say the truth, I'm really doubting that the code will be that fast that it will be able recognize that the caret is not displayed and take a screenshot before it is shown again.



    One more question - why do you need to compare images?

    The overall experience is that image comparison is the option that should be used as the last resort when nothing else is working. The reason for this is that usually the image comparison works acceptably well only on the computer it was initially implemented at. And it stops working when you execute the same code on another box. Usually this happens because another box has different OS, with different color scheme and color depth, etc.

    Why not to use Property Checkpoint and use the text and/or other text box properties that are stable and do not depend on OS, color, etc. ?
  • Yoann's avatar
    Yoann
    Occasional Contributor
    I totally agree with you, these tests are easy to create but hard to maintain.

    In fact we create a custom toolbox for our developers, so it's important to use accurate visual tests in our testing app.



    In this case, we can't easilly test all the visual items that are used in this TextBox (test coordinates, sizes, thickness, colors, tooltip... possible but hard to maintain too), and can't always determine the relationship between these items by visual tree (because of the use of adorners)
  • Yoann's avatar
    Yoann
    Occasional Contributor
    So...

    We found a small option in Windows (XP) keyboard configuration panel: you can set caret blinking frequency to "none".

    We need to run these tests on a single machine, so this simple trick is totally acceptable...



    Thanks for your time.