Creating a hello world filter

The first step to making a new filter is simply making a new class. Every filter is a single class which is instantiated once. The class should be placed in the "Filters" folder of the AXExtension project.
Step1.png

After that, we can add the framework that is necessary for every filter. First off, extend Filter and let the IDE automatically implement it for you. You'll also need to add a constructor to designate requirements of the action stack.
Step2.png

The hello world filter will simply add an action for typing "Hello world" after every user left click (Be aware, this will break every test recording while you have this filter in place.). To do this, we first need to create a requirement. We want to make sure that the filter only acts when the most recent action was a left click. To do this, simply add the requirement of the stack in a Require call.

In addition, we want to actually add the key action in the Run function, which will only be called if requirements are satisfied. To do this, we instantiate a SendKeysAction, set its text, and push it onto the stack.
Step3.png

An important step that is easy to forget is adding the filter to the actual runtime. AXActionFilter manages delegating extension calls to the Filters. The place to add the new filter is in the instantiation of FilterGroup. In this case we'll put it on the end. Usually filter ordering doesn't matter, though RemoveRedundancyFilter should almost always be on top.
Step4.png

In order to run extensions, visual studio searches a specific folder on startup for extensions. When you build the AXExtension project, you'll have to copy the produced DLL to this folder. The destination folder is going to be:
C:\Program Files (x86)\Common Files\Microsoft Shared\VSTT\{version of visual studio}\UITestExtensionPackages
For example, in Visual Studio 2013:
C:\Program Files (x86)\Common Files\Microsoft Shared\VSTT\12.0\UITestExtensionPackages

It's also possible that it could be in C:\Program Files\ instead. If the VSTT folder already exists in either path, it should be valid.
Step5.png

After this is done, the extension should be loaded. Now you can create a simple test and every time you click, a keyboard action should be added!

Last edited Jul 29, 2014 at 3:25 PM by wgoodin, version 6