我有一个AdvancedDataGrid,可以从Web服务加载数据。它只加载顶级内容,然后当您单击箭头时它会获取该数据。
我想要做的就是找出其中一个单元格中是否有某些文字。我最初这样做了:
public static function assertTextInAdg(params:Object):Boolean{
// Gets the ADG
trace('youre in the assertTextInAdg function');
var grid:* = FPLocator.lookupDisplayObject(params);
trace('var grid:* = FPLocator.lookupDisplayObject(params): ' + grid);
// Convert ADG to automation delegate to get an array of column names
var newGrid:* = new AdvancedDataGridAutomationImpl(grid);
trace('var newGrid:* = new AdvancedDataGridAutomationImpl(grid): ' + newGrid);
var datas:AdvancedDataGridTabularData = newGrid.automationTabularData as AdvancedDataGridTabularData;
trace('var datas:AdvancedDataGridTabularData = newGrid.automationTabularData as AdvancedDataGridTabularData: ' + datas);
var columnId:Array = datas.columnNames as Array;
trace('var columnId:Array = datas.columnNames as Array: ' + columnId);
// Convert ADG data to an array of rows
var gridView:HierarchicalCollectionView = grid.dataProvider as HierarchicalCollectionView;
trace('var gridView:HierarchicalCollectionView = grid.dataProvider as HierarchicalCollectionView: ' + gridView);
var gridData:HierarchicalData = gridView.source as HierarchicalData;
trace('var gridData:HierarchicalData = gridView.source as HierarchicalData: ' + gridData);
var gridArrayColl:ArrayCollection = gridData.source as ArrayCollection;
trace('var gridArrayColl:ArrayCollection = gridData.source as ArrayCollection: ' + gridArrayColl);
var gridArray:Array = gridArrayColl.source as Array;
trace('var gridArray:Array = gridArrayColl.source as Array: ' + gridArray);
var validator:String = params.validator;
trace('var gridArray:Array = gridArrayColl.source as Array: ' + validator);
for (var i:int = 0; i < gridArray.length; i++) {
for (var j:int = 0; j < columnId.length; j++) {
if (gridArray[i][columnId[j]] == validator) { return true; }
}
}
throw new Error("Validator not found in ADG.");
}
如果数据是从代码中提供的,那么这是有效的,但是现在我正在尝试从服务器提供的数据,并且跟踪出现如下:
youre in the assertTextInAdg function
var grid:* = FPLocator.lookupDisplayObject(params): companyDashboard.dashboardCanvas.dashboardGrid
var newGrid:* = new AdvancedDataGridAutomationImpl(grid): [object AdvancedDataGridAutomationImpl]
var datas:AdvancedDataGridTabularData = newGrid.automationTabularData as AdvancedDataGridTabularData: [object AdvancedDataGridTabularData]
var columnId:Array = datas.columnNames as Array: @objectName,@customObjectType,@owner,@value0,@value1,@icon1,@value2,@icon2,@value3,@icon3,@value4,@icon4,@value5,@value6,@icon6,empty
var gridView:HierarchicalCollectionView = grid.dataProvider as HierarchicalCollectionView: [object HierarchicalCollectionView]
var gridData:HierarchicalData = gridView.source as HierarchicalData: [object HierarchicalData]
var gridArrayColl:ArrayCollection = gridData.source as ArrayCollection: null
然后它失败了,因为它无法得到消息来源,我想。我对其他策略完全开放,我已经坚持了10天这个问题了。这似乎相对容易。提前感谢任何意见。
**更新**
我一直走的路线略有不同。我现在正试图用光标迭代HierarchicalCollectionView。这似乎有效。但是,当我得到节点时,我无法用它做任何有用的事情......我一直在寻找示例,但到目前为止它们都停在获取节点的位置。这意味着这是我所知道的一个愚蠢的问题。
public static function assertTextInAdg(params:Object):Boolean{
// Gets the ADG
trace('youre in the assertTextInAdg function');
var grid:* = FPLocator.lookupDisplayObject(params);
trace('var grid:* = FPLocator.lookupDisplayObject(params): ' + grid);
var adgData:* = grid.hierarchicalCollectionView;
trace('var adgData:* = grid.hierarchicalCollectionView: ' + adgData);
trace('AdgData.length() = ' + adgData.length);
var cursor:* = adgData.createCursor();
while(!cursor.afterLast) {
var node:Object = cursor.current;
cursor.moveNext();
}
这是trace()输出:
youre in the assertTextInAdg function
var grid:* = FPLocator.lookupDisplayObject(params): testApp.ApplicationSkin2._ApplicationSkin_Group1.contentGroup.Panel5.myADG
var adgData:* = grid.hierarchicalCollectionView: [object HierarchicalCollectionView]
AdgData.length() = 8
node.getData: undefined
constructor: [class Object]
hasRoot: undefined
length: undefined
openNodes: undefined
prototype: undefined
showRoot: undefined
source: undefined
node.getData: undefined
constructor: [class Object]
hasRoot: undefined
length: undefined
openNodes: undefined
prototype: undefined
showRoot: undefined
source: undefined
node.getData: undefined
constructor: [class Object]
hasRoot: undefined
length: undefined
openNodes: undefined
prototype: undefined
showRoot: undefined
source: undefined
答案 0 :(得分:0)
使用selenium和FlexPilot这就是我在检查网格中的文本
的方法selenium.flexAssertProperty("id=MyAppInFlex", "chain=id:userGrid/name:AdvancedListBaseContentHolder*/name:AdvancedListBaseContentHolder*, validator=text|Maria Marcano");
我有一些博客文章,其中包含有关Selenium和FlexPilot的信息 - http://mariangemarcano.blogspot.com/2010/08/selenium-testing-with-flex-pilot.html - http://mariangemarcano.blogspot.com/2010/10/automating-myappinflexswf-useful.html