Search code examples
automated-testswatinwebaii

Does the WebAii framework support a page class structure in the way that WatiN does?


I am evaluating a couple of different frameworks for test automation. One of the things I really like about WatiN is the page model for abstracting page code from your tests.

Watin Example for a login Page:

public class AVLoginPage : Page
{
    public TextField Email
    {
        get { return Document.TextField(Find.ById("UserLogin_UserName")); }
    }

    public TextField Password
    {
        get { return Document.TextField(Find.ById("UserLogin_Password")); }
    }

    public Button LoginBtn
    {
        get { return Document.Button(Find.ById("UserLogin_LoginButton")); }
    }

    /// <summary>
    /// Enters the email and loging in to the corresponding boxes and clicks the login button.
    /// </summary>
    /// <param name="email"></param>
    /// <param name="password"></param>
    public void Login(string email, string password)
    {
        Email.TypeText(email);
        Password.TypeText(password);
        LoginBtn.Click();
    }
}

Can I do something like this with WebAii?


Solution

  • So here is the approach I have started to take using the WebAii libraries:

    My test code looks like:

    [TestMethod]
    public void Login_inValid_Combination_WebAii()
    {
        Manager.LaunchNewBrowser(BrowserType.Safari);
        ActiveBrowser.NavigateTo(baseUrl + "login.aspx");
    
        LoginPage.Login("[email protected]", "123421343414",ActiveBrowser);
        string expectedMsg = "Email address or password is incorrect.";
        string actualMsg  = LoginPage.GetError(ActiveBrowser);
    
        Assert.IsTrue(actualMsg.Contains(expectedMsg));
    
    
    }
    

    I then have a library:

    using ArtOfTest.WebAii.Controls.HtmlControls;
    using ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;
    using ArtOfTest.WebAii.Core;
    using ArtOfTest.WebAii.ObjectModel;
    using ArtOfTest.WebAii.TestAttributes;
    using ArtOfTest.WebAii.TestTemplates;
    using ArtOfTest.WebAii.Win32.Dialogs;
    
    using ArtOfTest.WebAii.Silverlight;
    using ArtOfTest.WebAii.Silverlight.UI;
    
    namespace WebAIIPageLibrary
    {
        public class LoginPage : BaseTest
        {
    
            public static void Login(string email, string password, Browser passedBrowser )
            {
    
                passedBrowser.Find.ById<HtmlInputText>("UserLogin_UserName").Text = email;
                passedBrowser.Find.ById<HtmlInputPassword>("UserLogin_Password").Text = password;
                passedBrowser.Find.ById<HtmlInputSubmit>("UserLogin_LoginButton").Click();
            }
    
            public static string GetError(Browser passedBrowser)
            {
                ReadOnlyCollection<HtmlDiv> div = passedBrowser.Find.AllByTagName<HtmlDiv>("div");
                string errorMsg = "";
                foreach(HtmlDiv s in div)
                {
                    if (s.CssClass == "error")
                    {
                        errorMsg = s.InnerText;
                        break;
                    }
                }
    
                return errorMsg;         
            }
    
            public static string GetDashboardTitle(Browser passedBrowser)
            {
                return passedBrowser.Window.Caption;
            }
        }
    }
    

    This allows me to abstract the actions on the page from the test code itself.