So I ran into a customer recently that was getting pretty advanced with Coded UI and they were having trouble maintaining the UI Map technology as part of Visual Studio. One the things that I had noticed is that the UI Map does store lots of information including page names, URL’s and many other things that are interesting but not needed. This technology is great for beginners that need to get started with the technology.
So as I started thinking about it I was reflecting on some of the technologies that I have used before that included a way to search the DOM or Control Tree if you did not have an items mapped. Being a long time developer and avid Coded UI user I started thinking about how to solve this problem.
As I found quickly there are many ways solve this problem including taking the generated code from UI Map and move it around. It seems pretty simplistic under the covers but sure generates a LOT of code. J
As I started to think about how to condense the code and quickly .Net Generics came to mind. As I started this process I quickly started introducing the dynamic type and some of the cool things about the .Net Framework. So in the end I was left with a Custom Extension Method that extended the UITestControl class so that I could use it in line with my standard testing sequence. The code quickly became compact, readable and most of all it WORKED! I am always happy when those things align. I have included a snippet below of the TestMethod and also the static extension. You could also certainly use this with other web technologies since the base UI Testing framework uses UITestControl for all inherited types. So short story you can use the Class Extension for Windows, Web, WPF or any other automation controls that become part of Coded UI in the future.
Hope this helps someone else solve a very common problem.
Sample Test Method
|
[TestMethod]
{
app.Close(); } |
Custom Extension Method
|
public {
{ T ctrl = new T(); ctrl.Container = _this;
{ ctrl.SearchProperties.Add(item, ((object)searchProperties).GetPropertyValue(item).ToString()); }
{ propNames = ((object)filterProperties).GetPropertiesForObject();
{ ctrl.SearchProperties.Add(item, ((object)filterProperties).GetPropertyValue(item).ToString()); } }
}
{
}
{
}
} |