Skip to content
Yngve Bakken Nilsen edited this page Sep 5, 2013 · 1 revision

The Page object provides a base class to use with the INavigationService and also provides easy access to the IDocument object. Best practice when using Domify is to have a one-to-one relationship between your actual HTML-pages and your Page objects. This makes it easier to navigate and assert your application.

Example:

Our HTML looks like this:

<html>
<head><title>Log in</title></head>
    <body>
        <h1>Please enter your username and password:</h1>
        <form id="login-form" method="post" action="/account/login">
            <label for="username">Username:</label><input type="text" name="username" /><br />
            <label for="password">Password:</label><input type="password" name="password" /><br />
            <input type="submit" value="Log in" />
        </form>
    </body>
</html>

We could then have a Page object looking like this:

[PageDescription("Buttons", "http://localhost/account/login")]
public class LoginPage: Page
{
    public TextField Username { get { return Document.Form("login-form").TextField(Find.ByName("username")); } }

    public TextField Password { get { return Document.Form("login-form").TextField(Find.ByName("password")); } }

    public Button Submit { get { return Document.Form("login-form").Buttons().First(); } }
}

With these two in place we can utilize the INavigationService located on the IDocument:

var loginPage = Document.Navigation.GoTo<LoginPage>();
loginPage.Username.Text = "MyUsername";
loginPage.Password.Text = "MySecretPassword";
loginPage.Submit.Click();

// Assert expected behavior after login-button is clicked
Clone this wiki locally