使用Telerik的WebAii框架测试分页

时间:2011-06-23 20:22:53

标签: c# unit-testing telerik anchor webaii

我需要找到具有特定ID的HtmlAnchor内的每个Span

<span id="ctl05_dpIncidentFailures">
<span>1</span> // page 1
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=2">2</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=3">3</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=4">4</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=5">5</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=6">6</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=7">7</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=8">8</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=9">9</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=10">10</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=11">11</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=12">12</a>
    <a href="/DesktopDefault.aspx?ptabindex=7&ptabid=31&tabindex=14&tabid=214&pageid=13">13</a>
</span>

我怎么能用WebAii做到这一点?这就是我现在所尝试的:

IList<Element> allbtns = Find.AllByAttributes("href=~pageid"); // not working

var _pagingList = Find.ById<HtmlSpan>("~dpIncidentFailures"); // not working either

1 个答案:

答案 0 :(得分:1)

我已经解决了我的问题:

    [TestMethod]
    public void TestPagingCauseFailure()
    {
        // act
        OpenPage(true);

        // get the hidden fields on this page
        IList<HtmlInputHidden> _hiddenFieldsList = Find.AllByAttributes<HtmlInputHidden>("~hfFailureID");

        IList<HtmlAnchor> _pageIndexes = Find.AllByAttributes<HtmlAnchor>("href=~pageid");

        // there are 12 pages (not including page 1)
        Assert.IsTrue(Equals(12,_pageIndexes.Count));

        // goto last page
        _pageIndexes.Last().Click();

        //get the hidden fields on this page
        IList<HtmlInputHidden> _hiddenFieldsList2 = Find.AllByAttributes<HtmlInputHidden>("~hfFailureID");

        string value1 = _hiddenFieldsList.Last().ID;
        string value2 = _hiddenFieldsList2.Last().ID;

        //compare the two last items in boths lists
        Assert.IsFalse(Equals(value1, value2));

    }