I have an AdvancedDataGrid that loads data from a web service. It only loads the top level stuff and then as you click the arrows it gets that data.
All I want to do is to find out if some text is in one of the cells. I originally did this:
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.");
}
This works if the data is provided from the code, but now I am trying the same thing with the data being provided from a server and the traces come out like this:
youre in the assertTextInAdg function
var grid:* = FPLocator.lookupDisplayObject(params): com开发者_运维百科panyDashboard.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
And then it fails, because it can't get the source, I think. I am completely open to other strategies and I have been stuck on this problem for 10 days now. This seems like it would be relatively easy. Thanks in advance for any input.
** UPDATE **
I have been going down a slightly different route. I am now trying to iterate through the HierarchicalCollectionView with a cursor. This seems to work. But, when I get the node I can't do anything useful with it... I have been looking for examples but so far they all stop at the point of getting the node. Which means this is a stupid question I know.
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();
}
This is the trace() output:
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
Using selenium and FlexPilot this is how I am checking for a text in a grid
selenium.flexAssertProperty("id=MyAppInFlex", "chain=id:userGrid/name:AdvancedListBaseContentHolder*/name:AdvancedListBaseContentHolder*, validator=text|Maria Marcano");
I have some blog post with information about Selenium and FlexPilot - http://mariangemarcano.blogspot.com/2010/08/selenium-testing-with-flex-pilot.html - http://mariangemarcano.blogspot.com/2010/10/automating-myappinflexswf-useful.html
精彩评论