开发者

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

I am evaluating a couple of d开发者_开发技巧ifferent 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?


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("test@roger.com", "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.


Telerik Testing Framework (formerly called WebAii) does not include any recording capabilities. To get full recording and automatic Page class abstraction the way I think you want it you need to purchase a license to Test Studio (or Test Studio Express which comes with Ultimate Collection).

If you want to hand code your own abstractions, you are welcome to do so following the Find Expression documentation. Also (not currently documented, but we're working on it) is the [Find()] attribute you can use along with Find Expressions. This attribute replaces the old FindParam attribute. The FindParam attribute only work on HTML elements while the new Find attribute works on both HTML and XAML elements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜