2015-05-12 15 views
1
public class UIRow0jqxGrid1Pane : HtmlDiv 
    { 

     public UIRow0jqxGrid1Pane(UITestControl searchLimitContainer) : 
       base(searchLimitContainer) 
     { 
      #region Search Criteria 
      this.SearchProperties[HtmlDiv.PropertyNames.Id] = "row0jqxGrid1";//This ID will be dynamic. Need to search based on provided InnerText 
      this.SearchProperties[HtmlDiv.PropertyNames.Name] = null; 
      this.FilterProperties[HtmlDiv.PropertyNames.InnerText] = "XXXX"; 
      this.FilterProperties[HtmlDiv.PropertyNames.Title] = null; 
      this.FilterProperties[HtmlDiv.PropertyNames.Class] = null; 
      this.FilterProperties[HtmlDiv.PropertyNames.ControlDefinition] = "id=\"row0jqxGrid1\" role=\"row\" style=\"height: 25px; ;\""; 
      this.FilterProperties[HtmlDiv.PropertyNames.TagInstance] = "696"; 
      this.WindowTitles.Add("Test"); 
      #endregion 
     } 

     #region Properties 
     public HtmlDiv UIALMONDESTATECONSULTAPane 
     { 
      get 
      { 
       if ((this.mUIALMONDESTATECONSULTAPane == null)) 
       { 
        this.mUIALMONDESTATECONSULTAPane = new HtmlDiv(this); 
        #region Search Criteria 
        this.mUIALMONDESTATECONSULTAPane.SearchProperties[HtmlDiv.PropertyNames.Id] = null; 
        this.mUIALMONDESTATECONSULTAPane.SearchProperties[HtmlDiv.PropertyNames.Name] = null; 
        this.mUIALMONDESTATECONSULTAPane.FilterProperties[HtmlDiv.PropertyNames.InnerText] = "XXXX"; 
        this.mUIALMONDESTATECONSULTAPane.FilterProperties[HtmlDiv.PropertyNames.Title] = null; 
        this.mUIALMONDESTATECONSULTAPane.FilterProperties[HtmlDiv.PropertyNames.Class] = null; 
        this.mUIALMONDESTATECONSULTAPane.FilterProperties[HtmlDiv.PropertyNames.ControlDefinition] = "style=\"text-align: left; padding-bottom: 2px; margin- " + 
         "margin-right: 2px; margin- -ms-text-\""; 
        this.mUIALMONDESTATECONSULTAPane.FilterProperties[HtmlDiv.PropertyNames.TagInstance] = "700"; 
        this.mUIALMONDESTATECONSULTAPane.WindowTitles.Add("Test; 
        #endregion 
       } 
       return this.mUIALMONDESTATECONSULTAPane; 
      } 
     } 
     #endregion 

     #region Fields 
     private HtmlDiv mUIALMONDESTATECONSULTAPane; 
     #endregion 
    } 

場景____上面的代碼是從網格中選擇一個項目時生成的。我注意到物品在網格中被標識爲「窗格」。現在針對不同的場景,我必須選擇不同的項目。我所有的輸入值都存儲在一個文件中,我從中獲取一個值並傳遞給測試方法。如何根據搜索到的內文/名稱知道控件ID

我想要什麼____我需要根據我提供的值找到網格的行ID,以便在該行上發生鼠標點擊。

我做了什麼____網格填充數據從數據庫中檢索。所以我不能認爲哪個值會有什麼行ID。我已經改變了InnerText SearchProperty,但隨後回放停止並且測試失敗。

我在HTML ____The HTML結構注意到這是什麼

<grid id="grid1" style="...."> 
    <div>Header Row definition</div> 
    <div> Data Row 
    <div id="gridRow0" style="...">A</div> 
    <div id="gridRow1" style="...">B</div> 
    <div id="gridRow2" style="...">C</div> 
    <div id="gridRow3" style="...">D</div> 
    ....... 
    ...... 
    </div> 
</grid> 

請給一些解決方案...我沒有找到任何線索......

感謝您的時間...

+0

你可以迭代網格中的所有行,並且cmopare到提供的值 - 當找到匹配時將其作爲控件傳遞給mouse.Click(control)方法。以獲得控制使用網格控件上的GetChildren()方法 – barakcaf

回答

0

我會重構你的代碼。您已經獲得了HTML中該行的標識,所以讓我們使用它。 TestBuilder往往會讓事情變得更難以閱讀,並且包含太多的屬性以使搜索更有效率或更有意義。

因此,您的.uitest文件有兩個子類:.designer.cs(您的代碼位於上面)和.cs文件。打開cs文件,並通過執行類似找到您行:

public HtmlDiv gridRow(int index) 
{ 
    HtmlDiv target = new HtmlDiv(browser); 
    target.SearchProperties.Add(HtmlDiv.PropertyName.Id, "gridRow" + index.ToString()); 
    return target; 
} 

然後,在您的測試,如果你想獲得某行,只需調用myMap.gridRow(2)獲得的該HtmlDiv特定行。

然後,如果你已經有了一個超鏈接,例如,該行內,在您的地圖,你會創建對象:

public HtmlHyperlink linkOnRow(int index) 
{ 
    HtmlHyperlink target = new HtmlHyperlink(gridRow(index)); 
    target.SearchProperties.Add(HtmlHyperlink.PropertyNames.[your prop], [your value]); 
    return target; 
} 

不過,如果你想用的innerText,你會只需將PropertyName.Id更改爲PropertyName.InnerText並改爲使用其值。

+0

謝謝瑞安... 與您的意見我使用這個 public HtmlDiv gridRow(string innerText, UITestControl browser) { HtmlDiv target = new HtmlDiv(browser); target.SearchProperties.Add(HtmlDiv.PropertyNames.InnerText, innerText); return target; } public string RowId(HtmlDiv htmlDiv) { string rowID = htmlDiv.GetProperty("Id").ToString(); return rowID; } 謝謝... – rana

+0

很高興工作!如果您滿意,請標記答案:) –

相關問題