2012-02-16 41 views
1

幾天前,我收到了爲我的Windows應用程序(框架2.0)創建自動化UI測試用例的需求。在使用白色UI框架的窗體上找不到DataGrid

我決定使用白色作爲測試UI框架。現在,一切都很正常,除了我似乎無法找到的DataGrid控制其顯示3條記錄(注:這是不是DataGridView中)使用白色框架

我用VisualUIAVerify應用軟件來驗證確實DataGrid的是在窗體上,它是UI項目類型「」,我定義了使用正確的AutomationId控件,但仍然沒有運氣。

如前所述,我可以找到除DataGrid以外的窗體上的所有控件。難道我做錯了什麼 ?或者是白色根本不支持DataGrid。

任何幫助將是偉大的。由於

鮑比

回答

1

在年底不得不升級我的應用程序使用的DataGridView控制,而然後使用數據網格。這似乎解決了這個問題,因爲白似乎不支持DataGrid

1

我需要從白訪問一個dataGrid,還沒有找出爲什麼白不會工作(我有源,如果我有時間和挖通過它),但是,我已經寫了一些基本的代碼來提取網格數據到一個數組。謝天謝地,White框架提供了對AutomationElement的訪問。

下面的代碼沒有優化......它被LinqPad敲在一起!

// The first few lines use White 
var application = Application.Attach("AppName"); 
var window = application.GetWindow("The Window Title"); 
var datagrid = window.Get<White.Core.UIItems.TableItems.Table>("dataGridAutomationId").AutomationElement; 

// Now it's using UI Automation 
var headerLine = datagrid.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Header)); 
var cacheRequest = new CacheRequest { AutomationElementMode = AutomationElementMode.Full, TreeScope = TreeScope.Children }; 
cacheRequest.Add(AutomationElement.NameProperty); 
cacheRequest.Add(ValuePattern.Pattern); 
cacheRequest.Push(); 
var gridLines = datagrid.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom)); 
cacheRequest.Pop(); 

Console.WriteLine (headerLine.Count + " columns"); 
Console.WriteLine (gridLines.Count + " rows"); 

var gridData = new string[headerLine.Count, gridLines.Count]; 

var headerIndex = 0; 
foreach (AutomationElement header in headerLine) 
{ 
    gridData[headerIndex++, 0] = header.Current.Name; 
} 

var rowIndex = 1; 
foreach (AutomationElement row in gridLines) 
{ 
    foreach (AutomationElement col in row.CachedChildren) 
    { 
    // Marry up data with headers (for some reason the orders were different 
    // when viewing in something like UISpy so this makes sure it's correct 
    headerIndex = 0; 
    for (headerIndex = 0; headerIndex < headerLine.Count; headerIndex++) 
    { 
     if (gridData[headerIndex, 0] == col.Cached.Name) 
     break; 
    } 

    gridData[headerIndex, rowIndex] = (col.GetCachedPattern(ValuePattern.Pattern) as ValuePattern).Current.Value; 
    } 
    rowIndex++; 
} 
0

我不知道,如果你有完全相同的問題,因爲我,因爲我沒有足夠的代碼,但我是用一個WPF應用程序,我試圖訪問同樣的事情掙扎一個DataGrid,它實際上被編寫爲一個住在ListView中的GridView項目。

我的問題的解決方案是告訴白得到一個ListView項(即TestStack.White.UIItems.ListView)而不是表,然後它的一切工作。