简体   繁体   English

将 JTree 与 C# 结合使用并完成测试

[英]Using JTree with C# and Test Complete

I am writing a test which accesses a JTree via test complete and C#.我正在编写一个通过测试完成和 C# 访问 JTree 的测试。 I have attached an image.我附上了一张图片。 Unfortunately, for company confidentiality I had to black out some of the text.不幸的是,为了公司机密,我不得不把一些文字涂黑。 But it is basically the following:但基本上是这样的:

Routing Rules路由规则

  • Level 2 branches 2级分支机构
    • level 3 selections 3级选择

I get the JTree into a C# var (call it "tree").我将 JTree 放入 C# var(称之为“树”)。 I can easily expand and collapse by doing我可以通过做轻松扩展和折叠

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

that works fine.效果很好。 But when I try to determine whether something is expanded or not, like this但是当我试图确定某些东西是否被扩展时,就像这样

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

this gives an exception这给出了一个例外

  •  _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}

this appears to be how this web site says to do it:这似乎是该网站所说的这样做:

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

Am I doing something wrong?难道我做错了什么? Or can I not assign the value to a "var" and must use it in an if() statement?或者我可以不将值分配给“var”并且必须在 if() 语句中使用它吗?

C#Script (which is not C#) is described as a "legacy language" specifically designed for deprecated functionality and is not recommended for new projects . C#Script(不是 C#)被描述为专为弃用功能而设计的“遗留语言”, 不推荐用于新项目

The " wExpanded " property is obsolete and only included in TestComplete for backward compatibility. wExpanded ”属性已过时,仅包含在 TestComplete 中以实现向后兼容性。 Furthermore it is designed specifically for win32TreeView objects and not JTree objects.此外,它专为 win32TreeView 对象而不是 JTree 对象设计。

It would be better to use the Item object - it's designed to be a generic interface across a variety of application toolkits, and it has an " Expanded " property which would look as follows in C#Script;最好使用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);

Or in Javascript;或者在 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);

The TestComplete documentation has further information on the " wExpanded " Property ,the " Item " Object interface and the JTreeItem Properties to which it gives access, including " Expanded ". TestComplete 文档包含有关wExpanded ”属性Item ”对象接口和它提供访问权限的JTreeItem 属性的更多信息,包括“ Expanded ”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM