Skip to content
Nick Gamroth edited this page Mar 22, 2014 · 2 revisions

Pages

Pages consist of an IPage interface and a mapping class to tell the library how to find each controls. Page interfaces look like this:

public interface IGoogleHomePage : IPage
{
    IEditable SearchBox { get; }
    IClickable SearchButton { get; }
}

Pretty straightforward - each control you're going to use in your tests gets to be a property. You only need getters for these properties since it doesn't make sense to set them. Available controls are:

  • IClickable
  • IEditable
  • IStatic

Page Maps

Once you have your page controls defined you'll need to create a PageMap. Here's a sample map for the page shown above:

public class GoogleMap : PageMap<IGoogleHomePage>
{
    public GoogleMap()
    {
        AddToMap(x => x.SearchBox, LocatorKey.Name, "q");
        AddToMap(x => x.SearchButton, LocatorKey.Name, "btnQ");
    }
}

If you've used Entity Framework code first before this technique will be familiar. Each control needs an entry here or the test won't be able to find it. In this example we're using LocatorKey.Name which looks for the given value to match the value in the name attribute of the tags on the page. Available locator keys are:

  • Name
  • Css
  • Xpath
  • Id
  • TagName
  • Class Or, you can just put a string in there if there's something else you want to search by. For example, you could write your application with tags like this:
<a href="#" data-test="test-link">hello</a>

Using the data-test expando attribute, specifically for automated UI testing. Then, in your page map constructor you'd use the locator key like this:

AddToMap(x => x.HelloLink, "data-qa", "test-link");
Clone this wiki locally