Test Automation FX - User Guide
Test Automation FX - User Guide
Test Fixtures
Test fixtures are at the heart of a TAFX project. They contain the actual test code and
objects they need to find the applications and windows that are exercised during a test.
Test Methods
When TAFX is running the suite of tests in your application, it will look for all public
methods with the UITest attribute attached to them. So every method in your test code
needs to have the following signature:
[UITest]
public void TestAddition()
{
}
If you want to temporarily ignore a test method, you can attach the UIIgnoreTest attribute
to it. This will cause TAFX to leave that test out of the test run and report it as ignored. You
should add a reason to the ignore attribute so that it will be clear from the test results why
the test has been ignored.
[UITest]
[UIIgnoreTest("Waiting for new component library")]
public void TestAddition()
{
}
Test Automation FX
UI test automation for .NET developers
The following test method uses UIObjects to manipulate the Windows Calculator:
[UITest()]
public void TestAddition()
{
Button1.Click();
ButtonAdd.Click();
Button4.Click();
ButtonEquals.Click();
TextBox1.VerifyProperty("Text", "5, ");
}
There are several types of UIObjects, but the most common ones are UIApplication, which
represents an application, and UIWindow, which represents windows in an application.
The UIObjects of a TAFX project are stored in a hierarchical structure with the TestFixture at
the root, having one or several UIApplication objects as its direct descendants. Under each
UIApplication there are UIWindow objects that represents the different windows and
controls of the application.
All of the objects used here are UIObjects. TAFX creates and initializes these in the designer
part of your TestFixture class:
partial class TestFixture1
{
// ...
private void InitializeComponent()
{
CalcApplication = new TestAutomationFX.UI.UIApplication();
CalculatorWindow = new TestAutomationFX.UI.UIWindow();
Button1 = new TestAutomationFX.UI.UIWindow();
ButtonAdd = new TestAutomationFX.UI.UIWindow();
Button4 = new TestAutomationFX.UI.UIWindow();
ButtonEquals = new TestAutomationFX.UI.UIWindow();
Test Automation FX
UI test automation for .NET developers
TextBox1 = new TestAutomationFX.UI.UIWindow();
// ...
}
}
Matching UIObjects
The UIObjects acts as representatives for the parts of the application under test that we
want to manipulate. When we perform an action, such as a click, on a UIObject for the first
time, it will attach itself to the corresponding object in the application under test.
How a UIObject will find the corresponding object in the AUT is controlled by its matching
properties. These describe the conditions used to determine what object in the AUT we
should attach to.
The UIWindow object that represents the button for the number 1 in the Windows
Calculator example, has the following matching properties set:
Button1.Parent = CalculatorWindow;
Button1.WindowText = "1";
Button1.WindowClass = "Button";
Button1.Index = 7;
Button1.MsaaRole = System.Windows.Forms.AccessibleRole.PushButton;
Button1.MatchedIndex = 0;
When we call Button1.Click() for the first time in the test code, these properties will be
used to find the window that:
-
Attaching to a Process
The UIApplication has matching properties as well.
CalcApplication.ImagePath = "C:\\WINDOWS\\system32\\calc.exe";
CalcApplication.ProcessName = "Calc";
CalcApplication.CommandLineArguments = "";
CalcApplication.MatchedIndex = 0;
CalcApplication.UsedMatchedProperties =
Test Automation FX
UI test automation for .NET developers
IApplicationMatchedProperties.ProcessName |
UIApplicationMatchedProperties.ImagePath) |
UIApplicationMatchedProperties.CommandLineArguments;
When TAFX attempts to attach CalcApplication to an application, it will look for a process
that:
-
ActionExecuting. UIObjects generate this event when you perform an action on them, such as
clicking or dragging.
Attaching. UIObjects generate this when they are attempting to attach to objects in the AUT.
Attached. UIObjects generate this event when they have attached to objects in the AUT.
AttachFailing. UIObjects generate this event when they are about to consider the attempt to
attach to objects in the AUT failed.
AttachFailed. UIObjects generate this event when they have failed to attach to objects in the
AUT.
ActionExecuted. UIObjects generate this event an action is completed.
To subscribe to the events that are generated by a UIObject, the easiest way is to select
that UIObject in the design view and add an event handler in its property grid.
Test Automation FX
UI test automation for .NET developers
ActionExecuting
The ActionExecuting event is generated when your test code performs an action on a
UIObject.
private void Button1_ActionExecuting(object sender, ActionEventArgs e)
{
UIWindow button1 = (UIWindow)sender;
//...
}
The sender parameter is a reference to the UIObject that generated the event, and the
ActionEventArgs contains information about what action is performed on it.
It is possible to cancel the action by setting the ActionEventArgs.IsCanceled property to
true.
Attaching
If this is the first action on the UIObject in question, it will attempt to attach itself to the
corresponding object in the AUT. This will trigger the Attaching event.
You have the opportunity to override the attaching behavior in this event handler. You can,
for instance, create your own function for finding the correct window in the AUT and set
the Window property of a UIWindow yourself.
private void Button1_Attaching(object sender, EventArgs e)
{
UIWindow button1 = (UIWindow)sender;
button1.Window = CustomWindowFinder();
}
Attached
When a UIObject is attached to its AUT counterpart it will trigger the attached event.
private void Button1_Attached(object sender, EventArgs e)
{
UIWindow button1 = (UIWindow)sender;
//...
AttachFailing
If TAFX fails to find a match for a UIObject, it will fire the AttachFailing event.
private void Button1_AttachFailing(object sender, AttachFailingEventArgs e)
{
UIWindow button1 = (UIWindow)sender;
//...
}
Test Automation FX
UI test automation for .NET developers
The AttachFailingEventArgs parameter gives you the opportunity to change TAFXs default
behavior of considering the test failed. You can change some of the conditions of the AUT
and then tell TAFX to try again by setting the Action property to AttachFailingAction.Retry.
You can also use your own method of finding the correct object in the AUT and attach the
result to the UIObject triggering the event. You indicate this by setting the Action property
to AttachFailingAction.Handled.
AttachFailed
When an attach operation has failed for a UIObject, it will generate the AttachFailed event.
private void Button1_AttachFailed(object sender, EventArgs e)
{
UIWindow button1 = (UIWindow)sender;
//...
}
ActionExecuted
UIObjects triggers the ActionExecuted event when they have completed an action. This
event marks the end of the cycle for performing actions.
private void Button1_ActionExecuted(object sender, ActionEventArgs e)
{
UIWindow button1 = (UIWindow)sender;
//...
}
The ActionEventArgs enumerator contains information about what type of action has been
completed.
Test Automation FX
UI test automation for .NET developers
Verifying the State of the AUT
Up until now we have been talking about how to automatically exercise your AUT from
TAFX. We also need to verify that the application responds to the actions we perform on it
in the way we expected. We need to test the state of the application.
TAFX allows you to verify the state of the AUT in several ways. You can also create your own
custom verifiers to if you need to go beyond the ones provided out of the box.
Verifying Properties
Most of the time you will probably verify that the properties of controls have the correct
values. You might, for instance, verify that a text box displays the correct text, or that a
button is enabled or disabled correctly.
You verify the property of a UIObject by calling its VerifyProperty method:
[UITest()]
public void TestAddition()
{
Button1.Click();
ButtonAdd.Click();
Button4.Click();
ButtonEquals.Click();
TextBox1.VerifyProperty("Text", "5, ");
}
This code verifies that text box of the Windows Calculator (TextBox1) contains the correct
result after weve performed a simple calculation. The first parameter is the name of the
property that we want to verify, and the second parameter is the expected value.
TextBox1.VerifyImage();
}
Test Automation FX
UI test automation for .NET developers
Miscellaneous Verification Helpers
The Verify class contains helper methods that you can use to perform a few useful
verifications in your test code. All these methods will throw a VerifyException if the
verification fails.
You can use the Verify.FileExists method and its overloads to verify that a file exists.
[UITest]
public void Test()
{
//...
Verify.FileExists("C:\\Output\\Result.log");
}
You can use the Verify.AreEqual method to verify that two different objects are equal.
[UITest()]
public void Test()
{
//...
Verify.AreEqual(resultFromOperation, 5);
}
You can use the Verify.UserAcknowledge to make the test display a dialog asking the user to
verify that the AUT seem to be in the correct state.
[UITest()]
public void Test()
{
//...
if(SomeImportantRequirementIsNotMet())
{
Verify.FailTest("Some important requirement is not met.");
}
}
Test Automation FX
UI test automation for .NET developers
Custom Verifiers
TAFX allows you to easily create your own custom verifiers. A custom verifier that you
create will automatically be visible and configurable from the Add Verification dialog when
you are recording a new test.
To add your own verifier, you simply add a new class that derives from the CustomVerifier
class to your test project.
public class MyCustomVerifier : CustomVerifier
{
//...
Test Automation FX
UI test automation for .NET developers
get
{
return "Check maximum WorkingSet";
}
}
This property is used by the Add Verification dialog to display the name of the custom
verifiers.
If you need to, you can also add public properties to your class. These will automatically be
editable from the Add Verification dialog. You should also use the DescriptionAttribute to
add a short description about the properties and how they should be used.
[Description("The UIApplication to check the WorkingSet for.")]
public UIApplication Application { get; set; }
You use the Validate method to make sure that the user has set up the custom verifier
properly. When the user clicks the Ok button to add the verifier, TAFX will call this method.
If something is wrong with how the verifier has been set up, you have the opportunity to
tell the user that something has to be done to be able to continue.
public override bool Validate()
{
if (Application == null)
{
MessageBox.Show("The Application property must be set");
return false;
}
return true;
}
When youre done recording a test, TAFX will generate code that will perform the
verification when you run the test later. To determine what code to generate, TAFX will call
the methods StaticVerifyMethodName and GetParameters.
You implement the code that performs the actual verification when you run a test as a
static method in your custom verifier. The StaticVerifyMethodName should return the
name of that method.
public override string StaticVerifyMetodName
{
get
{
return "VerifyMaxWorkingSet";
}
}
10
Test Automation FX
UI test automation for .NET developers
You can tell TAFX what parameters it should pass to your custom static verification method
by having the GetParameters method return the values of those parameters as an object
array.
public override object[] GetParameters()
{
return new object[] { MaxWorkingSetKb, Application};
}
This will cause TAFX to inject something like the following code into your tests:
MyCustomVerifier.VerifyMaxWorkingSet(12, CalcApplication);
11