The new version of WatiN 2.0 beta 1 offers some base classes to help you structure your test classes.
It basically comes down to a class for each page (inherits from the WatiN.Core.Page class). In these page classes, you add properties for each control that you want to access. Sort of:
public Button OkButton { get { return Document.Button("okbuttonId"); }
and you can create methods to transfer some more complex actions to the page. For instance:
public void AddPerson(string name, string email) {
These page classes offer the advantage of defining your elements in one place.
In your test code, you can create a page class as follows:
using(var ie = new IE("www.somedomain.com/person")) { var page = ie.Page<PersonDetailPage>(); page.AddPerson("J. Doe", " jdoe@example.com ");
Another interesting base class that helps you structure your code is the Control class. When you use ASP, you will use controls that will not be displayed on only one html element on the displayed page. Instead, it is often a construct of elements contained in a div element. When you create your own Control and inheritance class Control, you can wrap internal controls (html) and behavior. This simplifies the reuse of the control in page classes. Following the example of creating an instance of the control:
var calendar = Document.Control<CalendarControl>("calendarId");
Hopefully this gives you some insight into how you can structure your pages and controls.
Jeroen
source share