【问题标题】:Using JTree with C# and Test Complete将 JTree 与 C# 结合使用并完成测试
【发布时间】:2022-06-16 00:51:37
【问题描述】:

我正在编写一个通过测试完成和 C# 访问 JTree 的测试。我附上了一张图片。不幸的是,为了公司机密,我不得不把一些文字涂黑。但基本上是这样的:

路由规则

  • 2 级分支
    • 3 级选择

我将 JTree 放入 C# var(称之为“树”)。我可以通过这样做轻松展开和折叠

tree["DblClickItem"]("Routing Rules");  // expand/collapse top branch
tree["DblClickItem"]("Routing Rules|Level 2 branches");  // expand/collapse second-level
tree["ClickItem"]("Routing Rules|Level 2 branches|level 3 selections") // select item

效果很好。但是当我试图确定某些东西是否被扩展时,就像这样

var expanded = tree["wExpanded"]("Routing Rules");

这给出了一个例外

  •   _innerException {"Unable to find the object wExpanded(\"Routing Rules\"). See Details for additional information.\r\n<html><body><p>The object with the specified attributes does not exist.</p><p style=\"margin-top: 12px;\"><a href=\"aqa-help://2202\">Possible causes of the error</a></p></body></html>"} System.Exception {System.Runtime.InteropServices.COMException}
    

这似乎是这个网站所说的:

https://support.smartbear.com/testcomplete/docs/app-objects/specific-tasks/standard/tree-view/checking-item-state.html#Expanded

我做错了吗?或者我可以不将值分配给“var”并且必须在 if() 语句中使用它吗?

【问题讨论】:

    标签: c# jtree testcomplete


    【解决方案1】:

    C#Script(不是 C#)被描述为专为弃用功能而设计的“传统语言”,是 not recommended for new projects

    wExpanded”属性已过时,仅包含在 TestComplete 中以实现向后兼容性。此外,它专为 win32TreeView 对象而非 JTree 对象设计。

    最好使用 Item 对象 - 它被设计为跨各种应用程序工具包的通用接口,并且它具有“Expanded”属性在 C#Script 中如下所示;

    // Setting items within the tree using wItem->Item 
    var routingRules = tree["wItems"]["Item"]("Routing Rules");
    // Lower level objects use wItems->Item->Items->Item
    var L2Branches = routingRules[Items][Item]("Level 2 branches");
    Log["Message"](routingRules["Expanded"]); // returns True or False 
    var isExpanded = routingRules["Expanded"];
    Log["Message"]("value of isExpanded",isExpanded);
    

    或者在 Javascript 中;

    // Setting items within the tree using wItem->Item 
    var routingRules = tree.wItems.Item("Routing Rules");
    // Lower level objects use wItems->Item->Items->Item
    var L2Branches = routingRules.Items.Item.("Level 2 branches");
    Log.Message(routingRules.Expanded); // returns True or False 
    var isExpanded = routingRules.Expanded;
    Log.Message.("value of isExpanded",isExpanded);
    

    TestComplete 文档有更多关于"wExpanded" Property"Item" Object interfaceJTreeItem Properties 的信息,包括“扩展”。

    【讨论】:

      猜你喜欢
      • 2012-11-08
      • 1970-01-01
      • 2020-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-26
      • 2011-08-19
      • 1970-01-01
      相关资源
      最近更新 更多