vrijdag 26 juni 2009

Page class gets friends

In my previous blog post I explained how you can use the new Page class in your code. Having this class available did spark some new ideas in the community. And again Jeff Brown offered some hours of sleep to make your page classes even more terse by introducing the FindByAttribute. Another new attribute is the DescriptionAttribute.

FindByAttribute

The FindByAttribute can be used on Fields and Properties and gives you a declarative style of expressing how an element should be found. In the following example the GoogleSearchPage is revamped and makes use of the new FindByAttribute.

image

Note that I only changed the GoogleSearchPage class and didn't have to change the test. And yes indeed, no actual c# code is needed and it almost reads like a real sentence. If only we could get ride of the syntax overhead like the [()] public:

FindBy Name q TextField SearchCriteria

And there is more

Talking about readability, Daaron Dwyer suggested to add a DescriptionAttribute. This new attribute sets the (also new) Description property of an Element or Control instance. This description is set on the element when a page object gets instantiated. With the description you can give the element a meaningful name which will show up in the log WatiN can create (see the Logger class in WatiN). The description will also be used when ToString() is called on an Element or Control.

If you like to have a look at these brand new features then go and get the source from the SourceForce code repository. If you are a little less adventures today, just wait until the next WatiN 2.0 release.

4 reacties:

Jeff Brown zei

Next up: Integrating Kirk's JQuery constraint for WatiN.

Dieter Menne zei

The new syntax is nice. Is it possible to use it for nested searches, e.g. "the first Link named "back" in Table with id "menu"?

Dieter

Jeff Brown zei

@Dieter, that's the kind of stuff that would be supported by the JQuery syntax that Kirk implemented.

Unfortunately I haven't ported it over to public builds of WatiN yet.

dkirk zei

Checkout my jquery style CSS selectors for watin. It may be very similar to the jQuery constraint you are talking about. http://bit.ly/7kiQdL