How to check if a WPF control is hidden / compensated using MS UI tests (CUIT)

I want to write a coded UI test like "Some WPF Controls When Some Condition Should Not Be Visible". How to say "not visible"?

To reproduce the problem:

  • create a new WPF application
  • add only one big named button to the main window
  • go to the CUIT editor and find out the button
  • without closing the CUIT editor close the WPF application
  • add Visibility = "Hidden" on the button
  • restart application
  • select the button in the CUIT editor and click the "Refresh" button
  • NOTE: the properties of the hidden button are exactly the same as the properties of the visible button!

There is no way to say the button is hidden!

Additionally:

  • I'd love to hear about the workarounds you are using. In the end, I need to write a test, not calculate CUITs
  • I know that I can compare screenshots.
  • Interestingly, if you try to do something with a hidden button, then CUIT will quit. This means that CUIT knows when the button is hidden.
  • I wonder if Visibility = "Collapsed" instead of "Hidden" CUIT recognizes it by specifying Width = Height = -1. This doesn't help with crumbling buttons :(
+3


source to share


2 answers


I found the best way to get around the limitation IsVisible

is to use the method TryGetClickablePoint(out System.Drawing.Point)

of the UITestControl object. This method returns a boolean value. So, for example, if you have a WpfButton:

WpfButton mine = new WpfButton(parent);
mine.SearchProperties["id"] = "id";

Point toString;
bool result = mine.TryGetClickablePoint(out toString);
Assert.IsTrue(result, "My Assertion here.");

      



This works more often than not. However, in order to handle collapsed or expanded, is there any property of the object that changes based on its state? For example, if a class class="myobject expanded"

, you can easily assert based on mine.GetProperty("Class").ToString().Contains("expanded");

as boolean.

+1


source


Try using GetProperty method :



WpfButton myButton = new WpfButton();
if(myButton.GetProperty("Enabled").Equals(true))
{
     ... CODE
}

      

-1


source







All Articles