Testing application with both WPF and Win version

Jul 9, 2013 at 6:46 PM
Hi,

I have to automate an application that has both a WPF version and Win version. A great example is Visual Studio where VS2005 and VS2008 is all win controls and VS2010 and VS2012 are mostly WPF controls (I know there are some win controls still mixed in but the main window is WPF).

I'd like to write my tests once, so I don't have to worry about the multiple versions. I've defined my win and wpf pieces separately, creating the structure necessary to access all of the elements that I want to (for example VSWinWindow.VSWinMenuBar.FileMenu and VSWPFWindow.VSWPFMenuBar.FileMenu).

To write my test, say clicking on the menu, I want to try to find a way to avoid casing in my test code (so I don't write the tests twice).

For example
[TestMethod]
Test()
{
if (VS2008)
{
VSWinWindow.VSWinMenuBar.FileMenu.Click();
}
else if (VS2010) 
{
VSWPFWindow.VSWPFMenuBar.FileMenu.Click();
}
}
I know this isn't necessarily a CUITe specific question, but is there a way that I can avoid doing this kind of if statement to access the different set of objects. The hardest part is that the tree structure of the different objects for the application seems different between WPF and Win when you inspect it in the coded ui recorder so I don't necessarily have the exact same definition in each class.
Coordinator
Jul 16, 2013 at 8:07 AM
Hi ddoorn,

I recommend using interfaces.

For example:
public interface IVSWindow
{
 IVSMenuBar MenuBar {get; set;}
}

public interface IVSMenuBar
{
 UITestControl FileMenu {get; set;}
}

public class VSWinWindow : IVSWindow
{
  public IVSMenuBar MenuBar
  {
    get
    {
      return Get<VSWinMenuBar>("Name=MenuBar");
    }
  }
}

public class VSWinMenuBar : CUITe_WinMenuBar, IVSMenuBar
{
  public UIControl FileMenu
  {
    get
    {
      return Get<CUITe_WinMenu>("Name=File").UnWrap();
    }
  }
}

public class VSWPFWindow : IVSWindow
{
  public IVSMenuBar MenuBar
  {
    get
    {
      return Get<VSWpfMenu>("Name=MenuBar");
    }
  }
}

public class VSWpfMenuBar : CUITe_WpfMenu, IVSMenuBar
{
  public UIControl FileMenu
  {
    get
    {
      return Get<CUITe_WinMenuItem>("Name=File").UnWrap();
    }
  }
}
and then your test code may look like this:
IVSWindow vsWindow;

if (VS2008)
{
  vsWindow = new VSWinWindow();
}
else if (VS2010) 
{
  vsWindow = new VSWPFWindow();
}

vsWindow.MenuBar.FileMenu.Click();