|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionFirst 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"))
{
ie.TextField(Find.ByName("q")).TypeText("WatiN");
ie.Button(Find.ByName("btnG")).Click();
}
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. InterfaceThe 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. FunctionsSome methods implemented in WatiN don't correspond to simple mouse clicks or keypresses, such as the
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. The codeBesides the main interfaces, the next important base class is the PHP supportPHP 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/");
$ie->TextField($Interface->FindByName("q"))->TypeText("watin");
$ie->Button($Interface->FindByName("btnG"))->Click();
Notice that Known issueAn HTML Dialog -- i.e. a web page opened with JavaScript using Project information can be found here. HistoryFull release anticipated for early July, 2007 Beta 3 - 6/1/07
Beta 2 - 4/24/07
Beta 1 - 4/9/07
|
||||||||||||||||||||||