0

有没有办法强制 Coded UI Test Builder 使用它已经记录的类?即使在单个录制会话中,它也会创建非常相似的类。

例如,下面生成的两个类中 URL 的唯一区别。我想重用代码——重复这样的代码是没有意义的。除了手动清理还有什么?

public class UISearchResultsOracleDocument : HtmlDocument
{
    public UISearchResultsOracleDocument(UITestControl searchLimitContainer) :
        base(searchLimitContainer)
    {
        #region Search Criteria
        this.SearchProperties[HtmlDocument.PropertyNames.Id] = null;
        this.SearchProperties[HtmlDocument.PropertyNames.RedirectingPage] = "False";
        this.SearchProperties[HtmlDocument.PropertyNames.FrameDocument] = "False";
        this.FilterProperties[HtmlDocument.PropertyNames.Title] = "Search Results : " + EnterSearchedTextParams.UISearchEditText;
        this.FilterProperties[HtmlDocument.PropertyNames.AbsolutePath] = "/project/Pages/results.aspx";
        this.FilterProperties[HtmlDocument.PropertyNames.PageUrl] = "http://my.url.com:123/project/Pages/results.aspx?k=Oracle";
        this.WindowTitles.Add("Search Results : Oracle");
        #endregion
    }
 // ...

}

//而且几乎是重复的

public class UISearchResultsOracleDocument1 : HtmlDocument
{
    public UISearchResultsOracleDocument1(UITestControl searchLimitContainer) :
        base(searchLimitContainer)
 {
     #region Search Criteria
     this.SearchProperties[HtmlDocument.PropertyNames.Id] = null;
     this.SearchProperties[HtmlDocument.PropertyNames.RedirectingPage] = "False";
     this.SearchProperties[HtmlDocument.PropertyNames.FrameDocument] = "False";
     this.FilterProperties[HtmlDocument.PropertyNames.Title] = "Search Results : Oracle";
     this.FilterProperties[HtmlDocument.PropertyNames.AbsolutePath] = "/project/Pages/results.aspx";
     this.FilterProperties[HtmlDocument.PropertyNames.PageUrl] = "http://my.url.com:123/project/Pages/results.aspx?k=Oracle&start1=1";
     this.WindowTitles.Add("Search Results : Oracle");
     #endregion
 }
// ...
}

因此,问题是如何消除重复?有什么提示可以减少 UIMap 中新类的数量吗?

谢谢

尤里

4

1 回答 1

0

尝试去下面的链接..

http://blogs.msdn.com/b/gautamg/archive/2009/12/18/why-is-coded-ui-test-generated-code-not-a-straight-line-code.aspx

http://blogs.msdn.com/b/gautamg/archive/2009/12/21/understanding-the-code-generated-by-coded-ui-test-part-2.aspx

从上面的链接:

我们提出的代码生成指南(一些基于收到的反馈)是 -

Encourage reusability of the test code. This is both for productivity

和更好的维护。让数据驱动等常见场景的代码定制更容易。完全控制代码以进行高级操作。

您始终可以编写相同的代码。但比记录它要复杂得多。

于 2011-01-08T18:25:27.097 回答