如何在Rational Functional Tester中获取树的所有节点?我使用getTestdata()
尝试过但无法解决问题?
代码段:
ITestDataTree iTreeData =(ITestDataTree)businessObj.smi_LocTreePricingRules().getTestData("tree");
ITestDataTreeNodes iNodes = iTreeData.getTreeNodes();
System.out.println("node count:"+iNodes.getNodeCount());
ITestDataTreeNode[] rootNodes = iNodes.getRootNodes();
// System.out.println(iNodes.getNodeCount());
// ITestDataTreeNodes nodes= tree.getTreeNodes();
System.out.println(rootNodes.length);
for(int i = 0; i < rootNodes.length; i++) {
genericObj.showTree(rootNodes[i]); //This showTree method is present in another GenericLib class. public void showTree(ITestDataTreeNode node)
{
//Recursive method to print out tree nodes with proper indenting.
//Determine number of tabs to use - to properly indent tree
//Print out node name + number of children
//System.out.println( node.getNode() + " (" + node.getChildCount() + "children)" );
//Determine if node has children; recursively call this same
//method to print out child nodes.
ITestDataTreeNode[] children = node.getChildren();
int childCount = ( children != null ? children.length : 0 );
for ( int i = 0; i < childCount; ++i )
showTree(children[i]);
String synb = node.getNode().toString();
System.out.println( node.getNode() + " (" + node.getChildCount() + "children)" );
}
但是这段代码给了我root节点的直接子节点。我怎样才能得到像孩子一样的所有节点?
答案 0 :(得分:0)
getTestData("tree")
API应该能够实现树节点的遍历。
你可以分享你试图获取树的所有节点的代码片段吗?
如果您需要一个代码段,可以使用下面的代码:
public printTreeNodes(){
//Declare variables for tree
ITestDataTree cdTree;
ITestDataTreeNodes cdTreeNodes;
ITestDataTreeNode[] cdTreeNode;
//Variables to hold tree data
//tree_mytree() is the tree object you want to traverse
cdTree = (ITestDataTree)tree_mytree().getTestData("tree");
cdTreeNodes = cdTree.getTreeNodes();
cdTreeNode = cdTreeNodes.getRootNodes();
//Print out total number of nodes
System.out.println ("Tree Total Node Count: " + cdTreeNodes.getNodeCount());
System.out.println ("Tree Root Node Count : " + cdTreeNodes.getRootNodeCount());
//Iterate through tree branches; this is a recursive method.
for (int i = 0;i<cdTreeNode.length;++i)
showTree(cdTreeNode[i], 0);
}
void showTree(ITestDataTreeNode node, int indent)
{
//Recursive method to print out tree nodes with proper indenting.
//Determine number of tabs to use - to properly indent tree
int tabCount = ( indent < tabs.length() ? indent :
tabs.length() );
//Print out node name + number of children
System.out.println(tabs.substring(0, tabCount) + node.getNode() + " (" + node.getChildCount() + "children)" );
//Determine if node has children; recursively call this same
//method to print out child nodes.
ITestDataTreeNode[] children = node.getChildren();
int childCount = ( children != null ? children.length : 0 );
for ( int i = 0; i < childCount; ++i )
showTree(children[i], indent+1);
}
//String of tabs used to indent tree view
final String tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";