Rational Functional Tester Java jTree relative references

Problem(Abstract)

The recording in IBM® Rational® Functional Tester of a Java™ jTree has a complication. This technote demonstrates a way to use relative paths to access jTree objects.

Symptom

The recording generates the following code.

 


jTree().doubleClick(atPath("F3 - Clients->HUIZINGA, JOHAN->Client Details"));      ​

If the item of HUIZINGA, JOHAN changes, the playback fails.

 

Resolving the problem

The Java method getTreeHierarchy converts the above line of code to the following code.

 


jTree().doubleClick(atPath(getTreeHierarchy(j​Tree(),​​ "Client Details")));​


This code puts the same path as above and does not consider the full hierarchy. The hierarchy can be dynamic. The following code helps you to search a tree for the parent hierarchy.


public String getTreeHierarchy(TestObject treeName, String searchTree) { ​

/**​
 * Description : Search a tree for the parent hierarchy.​
 *   We need to use this within atPath statements with trees​
 *   in the situation where the parents may be DYNAMIC.​
 *   For example, if you had <Client Name> -> Licence where of course​
 *   Client Name is going to change, you simply call​
 *   getTreeHierarchy(jTree(), "Licence") - or similar -​
 *   and it works out the parent(s). In this case you don't​
 *   have to worry.​
 *   This is reproducible, because RFT does not allow you to​
 *   say click on a "child" node, you must specify the full​
 *   path.​
 * ​
 * Parameters  : treeName   - the tree which you want to search ​
 *    you will need () at the end of the tree​
 *   searchTree - the node you are looking for​
 * ​
 * Returns     : Full path of tree as a string.​
 * ​
 */​

//Declare variables for tree​
ITestDataTree  treeToSearch;​
ITestDataTreeNodes  treeToSearchTreeNodes;​
ITestDataTreeNode[] treeToSearchSpecificNode;​
String foundHierarchy = "";​

       //Variables to hold tree data​
treeToSearch = (ITestDataTree) treeName.getTestData("tree");​
treeToSearchTreeNodes = treeToSearch.getTreeNodes();​
treeToSearchSpecificNode =treeToSearchTreeNodes.getRootNodes();​

//Iterate through tree branches; this is a recursive method.​
for ( int i = 0; i < treeToSearchSpecificNode.length; ++i )​
{​
foundHierarchy = searchTree(treeToSearchSpecificNode[i], searchTree, "");​
if (foundHierarchy != "")​
  break;​
}​

return foundHierarchy;​
}​

 private String searchTree(ITestDataTreeNode node, String searchText, String hierarchy) {​
/**​
 * Description : Searches the tree for a specific node​
 *               and calls itself recursively to traverse the tree.​
 *  Called by getTreeHierarchy.​
 * ​
 * Parameters  : node     - the tree node to traverse​
 *    searchText - the node to look for​
 *    hierarchy - current parent hierarchy above this node ​
 * ​
 * Returns     : The tree hierarchy that has been found.​
 * ​
 */​

String nodeSeparator = "->";​
String searchResult  = "";​

// If we are at the top level of the hierarchy, don't prepend nodeSeparator​
if (hierarchy == "")​
hierarchy = node.getNode().toString();​
else​
  hierarchy += nodeSeparator + node.getNode().toString();​

// If we have found our target Node record the current hierarchy ​
  if (node.getNode().toString().startsWith(searchT​ext))​​ {​
  searchResult = hierarchy;​
  }​
  else​
  {​
  // only bother doing this if we havent found our target Node​
// Determine if node has children and if so,​
// 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 ) ​
  {​
  searchResult = searchTree(children[i], searchText, hierarchy);​

if (searchResult != "")​
  break;​
}​
}​

return searchResult;​
}​





COMMENT
Alternatively you can use equalsIgnoreCase in searchTree if startsWith fails.


DISCLAIMER:
All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值