.NET 4.0 framework
- Install via NuGet
> install-package TestStack.White
- Have a look at the WPF or WinForms sample projects
- Have a look at Whites UI Tests, White has automated tests for most controls to prevent regressions in the codebase. These serve as a great example of how to automate different controls. See White's UI Tests
- Download http://uiautomationverify.codeplex.com/ which is an ESSENTIAL tool when doing UI Automation work.
- Start writing tests, first off you require a unit testing framework like xUnit or nUnit. See below for a basic walkthrough
- Join the mailing list at https://groups.google.com/forum/#!forum/teststack_white
- Report issues at https://github.com/TestStack/White/issues?state=open
- If you would like to contribute back, read Contributing to learn how to get started contributing back!
In MSTest:
[TestClass]
public class MyTests
{
[TestMethod]
public void MyFirstUITest()
{
}
}
In NUnit:
[TestFixture]
public class MyTests
{
[Test]
public void MyFirstUITest()
{
}
}
In xUnit:
public class MyTests
{
[Fact]
public void MyFirstUITest()
{
}
}
First you need to determine the correct path of the application you want to test.
In MSTest:
var applicationDirectory = TestContext.TestDeploymentDir
In NUnit:
var applicationDirectory = TestContext.CurrentContext.TestDirectory;
Then you create a new instance of your application
var applicationPath = Path.Combine(applicationPath, "foo.exe");
Application application = Application.Launch(applicationPath);
Window window = application.GetWindow("bar", InitializeOption.NoCache);
White uses the UI Automation API (UIA) to find controls on a window. UIA communicates to a displayed window via window messages. This find is performed by iterating through all the controls in a window.
Button button = window.Get<Button>("save");
button.Click();
SearchCriteria searchCriteria = SearchCriteria
.ByAutomationId("name")
.AndControlType(typeof(TextBox))
.AndIndex(2);
TextBox textBox = (TextBox) window.Get(searchCriteria);
textBox.Text = "Anil";
When reporting issues please include the following information:
- The target framework (WPF, Winforms etc)
- The version of White you are using
- [Recommended] A failing test! or
- [Recommended] A Gist with the code which is failing
- The more information the better, we accept pull requests with failing tests and pull requests which fix the issue too!