0
votes

Is there any way to create a coded UI test for a WPF application that only detects the parent window element? We are using a component suite that does not support Coded UI tests, but I would still like to be able to automate the UI for testing purposes. Ideally, such a solution would detect the parent window element, then use pixel offsets for automating any button presses, etc.

Thanks.

3

3 Answers

0
votes

You can use the Coded UI Test Builder to discover the properties you need, but the basic method for getting a window is pretty simple.

Here's a really simple class representing a window:

using System;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITesting.WpfControls;

public class MyWpfWindow : WpfWindow
{
    public MyWpfWindow() : base()
    {
        this.SearchProperties[WpfWindow.PropertyNames.Name] = "My Wpf Window Name";
    }
}

And here's a test

[CodedUITest]
public class MyWpfWindowUITests
{
    [TestMethod]
    public void MyWpfWindowExistsTest()
    {
        Assert.IsTrue(MyWpfWindow.Exists(5000), "The window was not found within five seconds");
    }
}
0
votes

While technically it is possible (Mouse.Click has overloaded version with x,y coordinates), it is not a good idea. Any change in control layout will break your test.