First there was WatiN, Web Application Testing in .NET, enabling a developer to automate Internet Explorer. Jesus Jimenez has written an article about it, also. The code for it looks something like this:
using (IE ie = new IE("http://www.google.com"))
This code opens the Google home page, enters "WatiN" into the search text box and then clicks the search button. The test recorder was born from the need to automatically record clicks and typing within a web page, enabling the faster production of tests for WatiN. It can produce code in C#, VB.NET and PHP. Languages can be changed in the settings dialog.
The recorder is an application with an embedded web browser, thanks to mehrcpp and his great embedded browser article. The browser hooks several happenings -- such as navigation, right-clicking and popup windows -- and Windows hooks are used to pick up keystrokes. The fundamental thing I wanted to accomplish with the recorder was the proper handling of all HTML input elements, like checkboxes and select lists. The application reaches beyond these modest goals.
NOTE: The application uses a modified version of the WatiN library to support the embedded browser, but your code does not need to.
The browser interface was designed by mehrcpp and has not strayed far. The top of the window looks like a typical browser, but the bottom of the window is where our magic happens. The list of tests are on the left; the code is on the right. To begin a test, enter the name of the test, which will be the name of the method. Click Record and begin using the web page normally. Notice that navigation, clicks, and keystrokes generate code. When you are done with your test, click Stop. From here, you have the option of simply copying and pasting to your favorite IDE, running the code or just compiling it. Of course, if you chose PHP as your code language, the compilation button will be disabled.
If you click on Run or Compile, you'll see a list of code templates available for the language. These templates are simple XML files in the templates directory and can be modified to fit your needs. For instance, if you need your tests to send data to a database, you can reference assemblies and add the code you need.
Some methods implemented in WatiN don't correspond to simple mouse clicks or keypresses, such as the
Blur method. To that end, when you right-click an element, the Function Explorer window opens. This is a specially formatted HTML page that returns code in a post method to the window and to the code box.
By extension, a developer can make a function page for their own snippets, inserting significant amounts of code when desired. Functions can be language- and element-dependent.
Besides the main interfaces, the next important base class is the
WatinScript object. This implements an interface pattern through virtual methods and handles methods for keyboard interpretation, select list handling, and compilation. Methods to add specific lines of code are handled in descendant
WatiNPHP objects. To implement another language, you would need to inherit from
WatinScript, create a code template and then create (or modify) functions to generate appropriate code.
PHP is able to run WatiN through the use of a COM interface (WatiNCOM.dll) in the installation package. This interface is also freeware open source and available on the recorder website. The interface attempts to mirror much of WatiN, but because static methods and overloading are currently difficult in PHP, some changes had to be made. Your code will therefore differ slightly from what you may be used to. For instance, the code from above looks like this in PHP:
$Interface=new COM('WatiN.COMInterface') or die('Cannot create IE object');
$ie = $Interface->CreateIE("http://www.google.com/");
CreateIE is a method of the base COM interface, not a separate constructor. Additionally, the static Find methods in the .NET assembly are methods of the base COM interface also. Jeroen is considering adding the interface to his core, but that may be further in the future.
showModelessDialog -- cannot be tracked by this application. It does not fire the
NewWindow event, so a handle to the new browser cannot be captured for use by the recorder. If you are someone or know someone at Microsoft who can change this, we'd love to support it. Read the Microsoft KnowledgeBase article.
Project information can be found here.
Full release anticipated for early July, 2007
Beta 3 - 6/1/07
- Add: Support for VB.NET code generation
- Add: Support for PHP code generation
- Add: User-definable templates for code pages (see the "Templates" directory)
- Add: Replaced Property Explorer (right-click) with user-definable code generation (see the "Functions" directory)
Beta 2 - 4/24/07
- Fix: DOM/WatiN selection caused exception or not highlighting element
- Fix: Non-alpha keys were not printing properly
- Fix: Popup did not support
- Add: Exceptions show a window to email report
- Add: WatiN Element support for frames
- Add: Natural support for traditional input tags (select, checkbox, radio, and file)
- Add: Setting for search types and ordering
Beta 1 - 4/9/07
Raised by wolves in the mean streets of Macintosh C/C++ for IBM and Motorola, moved on to Delphi and now C#. Ah, the mother's milk of Microsoft...