Welcome to MSDN Blogs Sign in | Join | Help

Lester's WPF blog


Simple, easy & beautiful

News

TestAPI Library Usage

TestAPI . Heard of it? Tried it?...  huh

So here is the gist of it. It’s a collection of helper functions that will make testing your applications easier.  Now this is an alpha release and is in the first iteration – so we still have a feature backlog J

Currently we support the following 5 scenarios:

Visual Verification

Sample Usage:

// Capture the actual pixels from the bounds of the screen rectangle

Snapshot actual = Snapshot.FromRectangle(windowRect);

 

// Load the reference/master data from a previously saved file

Snapshot master =

    Snapshot.FromFile(Path.Combine(TestContext.TestDeploymentDir, "Master0.png"));

 

// Compare the actual image with the master image

Snapshot difference = actual.CompareTo(master);

 

// Configure the snapshot verifier - It expects a black image with zero tolerances

SnapshotColorVerifier colorVerifier =

    new SnapshotColorVerifier(Color.Black, new ColorDifference());

 

// Evaluate the difference image

VerificationResult result = colorVerifier.Verify(difference);

 

Input Injection

Includes helpers for mouse and keyboard input

public static class Keyboard

{

    public static void Type(string text);

    public static void Type(Key key);

    public static void Press(Key key);

    public static void Release(Key key);

    public static void Reset();

}

 

public static class Mouse

{

    public static void Click(MouseButton mouseButton);

    public static void DoubleClick(MouseButton mouseButton);

    public static void Down(MouseButton mouseButton);

    public static void MoveTo(Point point);

    public static void Reset();

    public static void Scroll(double lines);

    private static void SendMouseInput(int x, int y, int data, NativeMethods.SendMouseInputFlags flags);

    public static void Up(MouseButton mouseButton);

}

 

Dispatcher Helpers

These are simple wrappers around the WPF Dispatcher.

public static class DispatcherOperations

{

    public static void WaitFor(TimeSpan time);

    public static void WaitFor(DispatcherPriority priority);

}

 

CommandLineParser

// Sample for parsing the following command-line:

// Test.exe /verbose /runId=10

// This sample declares a class in which the strongly typed arguments are populated

public class CommandLineArguments

{

   bool? Verbose { get; set; }

   int? RunId { get; set; }

}

 

CommandLineArguments a = new CommandLineArguments();

CommandLineParser.ParseArguments(args, a);

 

// SAMPLE USAGE #2:

// Sample for parsing the following command-line:

// Test.exe run /verbose /id=10

// In this particular case we have an actual command on the command-line (“run”),

// which we want to effectively de-serialize and execute.

public class RunCommand : Command

{

    bool? Verbose { get; set; }

    int? RunId { get; set; }

 

    public override void Execute()

    {

    }

}

 

Command c = CommandLineParser.ParseCommand(args, new Command[] { new RunCommand() });

c.Execute();

 

UIAutomation Helpers

public static class AutomationUtilities

{

    // Methods

    public static AutomationElement FindElementByIndex(AutomationElement rootElement, int index);

    public static AutomationElementCollection FindElements(AutomationElement rootElement, params Condition[] conditions);

    public static AutomationElementCollection FindElementsByClassName(AutomationElement rootElement, string className);

    public static AutomationElementCollection FindElementsByControlType(AutomationElement rootElement, ControlType controlType);

    public static AutomationElementCollection FindElementsById(AutomationElement rootElement, string automationId);

    public static AutomationElementCollection FindElementsByName(AutomationElement rootElement, string name);

}

 

Since this is still in development we are open to feature requests and will implement them based on the most requested. So do give us feedback. Site: http://www.codeplex.com/TestApi

 

Share this post

 

Posted: Monday, January 12, 2009 2:26 PM by llester
Filed under:

Comments

Zunanji viri said:

Beseda API pomeni Application programming Interface , kar predstavlja množico protokolov, podatkovnih

# January 13, 2009 9:32 AM

Članki said:

Beseda API pomeni Application programming Interface , kar predstavlja množico protokolov, podatkovnih

# January 13, 2009 10:06 AM

gOODiDEA.NET said:

Web Using Adobe Flex in Visual Studio What's New in Internet Explorer 8 - Responding to Change: Updated

# January 14, 2009 1:23 AM

gOODiDEA said:

WebUsingAdobeFlexinVisualStudioWhat'sNewinInternetExplorer8-RespondingtoChan...

# January 14, 2009 1:28 AM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# January 15, 2009 9:56 AM
New Comments to this post are disabled
Page view tracker