Writing NUnit tests with White for views / controls

Feb 18, 2010 at 7:58 PM

Hello,

how can I write NUnit Tests with white? With NUnit.Forms I can do the following:

 

[TestFixture]
public class MyViewTests{

    [Test]
    public void Setting_a_text_works(){
        var tester = new TextBoxTester("nameOfTextBox");
        var view = new MyView();
        view.Show();
        view.Text = "a text";
        Assert.That(tester.Text, Is.EqualTo("a text"));
        view.Close();
    }
}

but if I try this with White

[TestFixture]
public class MyViewTests{

    [Test]
    public void Setting_a_text_works(){
        var view = new MyView();
        view.Show();
        view.Text = "a text";
        var application = Application.Attach(Process.GetCurrentProcess());
        Window window = application.GetWindow(view.Title)
        var textBox = window.Get<TextBox>(SearchCriteria.ByAutomationId("nameOfTextBox"));
        Assert.That(textBox.Text, IsEqualTo("a text"))
        view.Close();
    }
}

White doesn't find the window. But in the process I can see the window as mainwindow. As a Workaround I make the White-configurations in another thread but this is more complicated than with NUnit.Forms and causes trouble if I want to debug the code. I can't use NUnit.Forms because now I'm working with WPF.

Has someone any ideas how to solve this problem?

regards

Armin

Coordinator
Feb 19, 2010 at 6:28 PM

Since is this question has been repeated a few time I add the response to it here http://white.codeplex.com/wikipage?title=Other%20questions

Please look at the point 9.

 

Feb 20, 2010 at 1:09 AM

Thanks for your answer. Is this a problem of the white implementation or a problem of uiautomation?

Feb 20, 2010 at 1:16 AM

Ok maybe this is the answer http://msdn.microsoft.com/en-us/library/ms788709.aspx