Hi Jared,
thank you for your answer. This solution was my first try too, but it does not solve my problem. Maybe I should have been more precise.
Here is an example testitem structure and the result of the script:
1. Test (enabled)
2. Group (enabled)
2.2. Test (enabled)
2.3. Test (enabled)
2.4. Subgroup (enabled, but empty)
3. Group (enabled, but empty)
Result: Items: 5 Groups: 3 Enabled: 5
The empty groups are getting counted as tests too. Those Groups are placeholders right now, and are going to be filled during expansion.
I reorganized your script a little bit and found the following solution working for me. Right now neither disabled groups nor their childs are getting counted, because those tests are not running and not of interest (for me). Maybe in the future those will be added with additional counters.
function GetTestItemsInfo(testItems);
var
i, testItem;
itemsInfo : array [0..2]; // groupsCount, itemsCount, enabledItemsCount
childItemsInfo : array [0..2]; // groupsCount, itemsCount, enabledItemsCount
begin
itemsInfo[0] := 0;
itemsInfo[1] := 0;
itemsInfo[2] := 0;
for i := 0 to testItems.ItemCount - 1 do
begin
testItem := testItems.TestItem(i);
if (testItem.ItemCount = 0) then
begin
if (nil = testItem.ElementToBeRun) then
begin
itemsInfo[0] := itemsInfo[0] + 1; // Group++
end
else
begin
itemsInfo[1] := itemsInfo[1] + 1; // Test++
if testItem.Enabled then
begin
itemsInfo[2] := itemsInfo[2] + 1; // Enabled++
end;
end;
end
else
begin
if testitem.Enabled then
begin
itemsInfo[0] := itemsInfo[0] + 1; // Group++
childItemsInfo := GetTestItemsInfo(testItem);
itemsInfo[0] := itemsInfo[0] + childItemsInfo[0]; // Group
itemsInfo[1] := itemsInfo[1] + childItemsInfo[1]; // Test
itemsInfo[2] := itemsInfo[2] + childItemsInfo[2]; // Enabled Tests
end;
end;
end;
Result := itemsInfo;
end;
procedure CountTestItems();
var itemsInfo : array [0..2]; // groupsCount, itemsCount, enabledItemsCount
begin
itemsInfo := GetTestItemsInfo(Project.TestItems);
Log.Message('TestItems Information',
'Groups: ' + VarToStr(itemsInfo[0]) + #13#10
+ 'Tests: ' + VarToStr(itemsInfo[1]) + #13#10
+ 'Enabled Test: ' + VarToStr(itemsInfo[2]));
end;
P.S.: Code tags or tags for preformated text would be helpful for the forum.
Dirk
----
TC Standard 7.50 (DelphiScript)