Getting Started with White
Pre-requisites
.NET 4.0 framework
Getting Started
- 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!
Writing your first test
Start off with an empty test stub
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()
{
}
}
Get hold of a window
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.
Finding a UI Item and performing action
Button button = window.Get<Button>("save");
button.Click();
Finding a UIItem based on SearchCriteria
SearchCriteria searchCriteria = SearchCriteria
.ByAutomationId("name")
.AndControlType(typeof(TextBox))
.AndIndex(2);
TextBox textBox = (TextBox) window.Get(searchCriteria);
textBox.Text = "Anil";
Updated less than a minute ago