Writing your own client using UITest Object Model

In my earlier series on extensibility of Coded UI Test, I mentioned that it is possible to write your own client using UITest Object Model i.e. use the recording for something else.  This post is targeted towards that.

The UITest Object Model today is pretty simple with 3 main classes -

  1. The UITest class – This class encapsulates a *.uitest file.  You can use this to create, save or read a .uitest file.
  2. The UITestInterpreter class – This class takes a UITest object and interprets it.  The actual interpretation depends on the UITestActionInvoker interface defined below.  For folks familiar with Gang of Four design patterns, this class is iterator that iterates through each action in UITest and for each action it calls a visitor which is UITestActionInvoker.
  3. The UITestActionInvoker class – This defines what needs to be done with each class.  There are 3 standard implementation of this in the product –
    • UITestActionInterpreter for playback of the action during fast forward of the actions from MTM.
    • ActionLogInterpreter for generating action log text for an action.
    • And an internal implementation for doing code generation for an action.

Refer the sample attached to this blog to see how all this fits in together and in action.  In the sample, I am using above extensibility to playback an action with audio. To use the sample,

  • Download and unzip the sample attached to this blog.
  • Build the sample.
  • Copy the PlaybackWithAudio.exe and PlaybackWithAudio.exe.config files to <VS Install Dir>\Common7\IDE.  Essentially this is same location as devenv.exe or CodedUITestBuilder.exe.  To do this, you can also take help of CopyDrop.bat file. (Note on 64 bit OS, the batch file should be run from 32 bit VS command prompt.)
  • Run the sample by doing -

PlaybackWithAudio <your UITest file>

The sample itself is pretty straightforward and you should be able to follow it.