I'm currently trying to help automate some coded UI tests using C # for a web application. A common problem that I am facing is that it is very difficult to determine if a UITestControl object UITestControl on the page or not. Unfortunately, the Microsoft documentation on its MSDN website for virtually everything related to coded user interface tests practically does not exist ( see their page for UITestControl ).
I basically ask:
- What is the best way to determine if a
UITestControl on a page? - How does the
UITestControl.Exists property UITestControl.Exists ? - What does the
UITestControl.Find() method UITestControl.Find() ? - How does the
UITestControl.TryFind() method UITestControl.TryFind() ?
How I tried to handle this:
As I mentioned earlier, the documentation for all of these classes and methods is mostly empty. The most that you can describe with any of the methods and properties is a 1-line description in Intellisense, so I experimented with the methods listed below.
At first I tried to check if the UITestControl.Exists property UITestControl.Exists true, but over time and with the experience of other people with it it became apparent that it always returns true, even if the browser is not open. Since the option that seemed most obvious didn't work, I tried using the UITestControl.Find() method, but since it takes no arguments and returns nothing, I could not understand what it did. I tried to use the UITestControl.TryFind() method, and sometimes it worked, but I found that it only returned to false when I was not on the correct page; he always returned otherwise. Clearly, I had no idea how this works, and should not be used as a test.
I decided that if I could not get the provided methods to do my work, I would have to try to create my own tools. I recently tried using Mouse.Hover(UITestControl) in a try / catch block to determine if such a control exists:
public bool DoesExist(UITestControl control){ if(control == null) return false; try{ Mouse.Hover(control); } catch (UITestException) { return false; } return true; }
It works sometimes, but in some situations it seems to return false positives for reasons that I don't understand. I'm still flying blind, and I have almost no ideas.
I am using Visual Studio 2012 and Microsoft.NET Framework version 4.5.50709.
c # web-applications visual-studio-2012 coded-ui-tests
Daniel Stone
source share