Skip to content
Nick Gamroth edited this page Apr 13, 2014 · 9 revisions

Here's the order you're gonna want to look in:

Create maps for your pages: Page Maps

Initialize your test: Test Initialization

Write Tests: Tests

Advanced Usage

Default Control Selectors

This one's real good. I just (as of v2.1.+) added default locator keys, and if you name your page properties with the same name as what you're locating on, you don't have to add a locator. That doesn't make sense so here's and example:

<div data-qa="ImportantInfo">This is important information that my test needs to know about</div>

And here's our page:

public interface MyRegularPage : IPage
{
  IStatic ImportantInfo { get; }
}

And now for the good part - the page map gets real simple:

public class MyRegularPageMap : PageMap<MyRegularPage>
{
  public MyRegularPageMap() : base("data-qa")
  { }
}

Since we set the default locator in the MyRegularPageMap constructor and MyRegularPage has a property named 'ImportantInfo' which matches the data-qa attribute in the html, the control will be automatically added to the page map.

Platform Selection

A main use case of this library is to have tests that you write once and run on multiple platforms. Mostly, this would be used for mobile testing - you write a test for a certain use case and you want to run the test say on Android and iOS. As of version 2.2.7 you can implement this as follows:

Here's a page that we want to use in our tests

public class MultiPlatformPage : IPage
{
  IClickable MyButton { get; }
}

And now you'll create two page maps for it, specifying the Platform attribute on them:

[Platform("iOS")]
public class MultiPlatformPageMapIos : PageMap<MultiPlatformPage>
{
  public MultiPlatformPageMapIos()
  {
    AddToMap(x => x.MyButton, "Xpath", "//window[0]/mybutton");
  }
}

And another one for Android:

[Platform("Android")]
public class MultiPlatformPageMapAndroid : PageMap<MultiPlatformPage>
{
  public MultiPlatformPageMapAndroid()
  {
    AddToMap(x => x.MyButton, "Name", "MyButton_Name");
  }
}

To select which map to use at runtime, you initialize your test with something to specify what platform you want to use:

var test = new TestBuilder()
  .SelectMapsWithPlatform("Android")
  .UsingSeleniumRemote("http://localhost:4723/wd/hub);
Clone this wiki locally