Navigation to Different Pages After Click

How to perform the navigation to different pages after the button/link click.

Given

Simple sign in form which after ‘Sign In’ button click can navigate user to different pages. For example, to admin page or regular user profile page, depending on user account.

<div class="form-group">
    <label for="email">Email</label>
    <input type="email" class="form-control" id="email">
</div>
<div class="form-group">
    <label for="password">Password</label>
    <input type="password" class="form-control" id="password">
</div>
<button class="btn btn-primary">Sign In</button>

Approach #1

Using Go.To navigation in the test method.

using Atata;

namespace SampleApp.UITests
{
    using _ = SignInPage;

    public class SignInPage : Page<_>
    {
        public TextInput<_> Email { get; private set; }

        public PasswordInput<_> Password { get; private set; }

        public Button<_> SignIn { get; private set; }
    }
}

Navigate to Regular User Profile Page

Go.To<SignInPage>().
    Email.Set("user@mail.com").
    Password.Set("abc123").
    SignIn.Click();

Go.To<UserProfilePage>();

Navigate to Admin Page

Go.To<SignInPage>().
    Email.Set("admin@mail.com").
    Password.Set("abc123").
    SignIn.Click();

Go.To<AdminPage>();

Conclusions

Pros

Cons

Approach #2

Using Go.To navigation in the page object methods.

using Atata;

namespace SampleApp.UITests
{
    using _ = SignInPage;

    public class SignInPage : Page<_>
    {
        public TextInput<_> Email { get; private set; }

        public PasswordInput<_> Password { get; private set; }

        public Button<_> SignInButton { get; private set; }

        public UserProfilePage SignInAsUser()
        {
            SignInButton.Click();
            return Go.To<UserProfilePage>();
        }

        public AdminPage SignInAsAdmin()
        {
            SignInButton.Click();
            return Go.To<AdminPage>();
        }
    }
}

Navigate to Regular User Profile Page

Go.To<SignInPage>().
    Email.Set("user@mail.com").
    Password.Set("abc123").
    SignInAsUser();

Navigate to Admin Page

Go.To<SignInPage>().
    Email.Set("admin@mail.com").
    Password.Set("abc123").
    SignInAsAdmin();

Conclusions

Pros

Cons