您需要使用调试信息编译您的应用程序,以便 TestComplete 的 Debug Info Agent 可以为该工具提供对所有本机方法和控件属性的访问。一旦 TestComplete 可以找到调试信息,您就可以通过以下方式访问树项:
procedure Test;
...
w := p.frmOpts;
tvw := w.VCLObject('ElTree1');
tvw.Items.Item(1).Checked := true;
end;
在Debug Info Agent 帮助主题中查找有关如何正确编译带有TestComplete 调试信息的Delphi 应用程序的详细信息。单击与您的 Delphi 版本对应的链接以获取步骤。
此外,您可以在 this survey 中投票支持您的控件在未来版本的 TestComplete 中的高级支持。
更新:
尽管 TestComplete 不像其他一些广泛使用的树视图控件那样对 TElTreeView 控件提供扩展支持,但可以创建脚本例程以在高级别的控件上工作.这些例程将使用 TestComplete 的 Open Application 功能通过其本机方法和属性与树控件一起工作。下面的示例脚本演示了如何做到这一点。
function getTreeNode(tree, nodeName); forward;
function clickTreeNode(tree, node); forward;
procedure test;
var
tree;
nodeName;
node;
begin
tree := Sys.Process('ElTreeTest').VCLObject('Form1').VCLObject('ElPanel1').VCLObject('ElTree1');
nodeName := 'Item B|Item BB|Item BBA';
node := getTreeNode(tree, nodeName);
if node <> nil then
Log.Message(node.Caption)
else
begin
Log.Error('Node "' + nodeName + '" not found');
Runner.Stop;
end;
node.MakeVisible;
node.Checked := not node.Checked;
clickTreeNode(tree, node);
end;
function clickTreeNode(tree, node);
var
x, y;
begin
node.MakeVisible;
x := (node.TextRect.Left + node.TextRect.Right) / 2;
y := (node.TextRect.Top + node.TextRect.Bottom) / 2;
tree.Click(x, y);
end;
function getTreeChildNode(rootNode, nodeName);
var
i;
item;
nodeCaption;
begin
result := nil;
if rootNode = nil then
exit;
nodeCaption := aqString.GetListItem(nodeName, 0);
for i := 0 to rootNode.ChildrenCount - 1 do
begin
item := rootNode.Children(i);
if item.Caption = nodeCaption then
begin
result := item;
break;
end;
end;
if aqString.GetListLength(nodeName) > 1 then
result := getTreeChildNode(result, aqString.DeleteListItem(nodeName, 0));
end;
function getTreeNode(tree, nodeName);
var
rootNodeCaption;
item;
i;
begin
aqString.ListSeparator := '|';
rootNodeCaption := aqString.GetListItem(nodeName, 0);
result := nil;
for i := 0 to tree.Items.Count - 1 do
begin
item := tree.Items.Item(i);
if item.Parent = nil then
begin
if item.Caption = rootNodeCaption then
begin
result := item;
break;
end;
end;
end;
if aqString.GetListLength(nodeName) > 1 then
result := getTreeChildNode(result, aqString.DeleteListItem(nodeName, 0));
end;