Ask a Question

Distinguish tests from groups

DHB
Occasional Contributor

Distinguish tests from groups

Hello, 


I am trying to measure the number of testitems (enabled/disabled) in my project for statistical purposes, to compare different testruns.


While iterating through Project.TestItems.TestItem, i did not find a way to distinguish tests from (sometimes empty) groups. I  tried to use the ElementToBeRun Property, but had no success. Testitems and folders seem to be handled identical.


Any suggestions to solve this?


Thank you,


Dirk


----


TC Standard 7.50 (DelphiScript)



TC 7.52/8.70/9.20 Standard, DelphiScript

2 REPLIES 2
YMinaev
Staff

Hi Dirk,



Try using the following script:



function GetTestItemsInfo(testItems);

var i, testItem;

var itemsInfo : array [0..2]; // groupsCount, itemsCount, enabledItemsCount

var 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 (nil = testItem.ElementToBeRun) then

begin

itemsInfo[0] := itemsInfo[0] + 1;

end;

if (testItem.ItemCount <> 0) then

begin

childItemsInfo := GetTestItemsInfo(testItem);

itemsInfo[0] := itemsInfo[0] + childItemsInfo[0];

itemsInfo[1] := itemsInfo[1] + childItemsInfo[1];

if testItem.Enabled then

begin

itemsInfo[2] := itemsInfo[2] + childItemsInfo[2];

end;

end

else

begin

itemsInfo[1] := itemsInfo[1] + 1;

if testItem.Enabled then

begin

itemsInfo[2] := itemsInfo[2] + 1;

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 + 'Items: ' + VarToStr(itemsInfo[1]) + #13#10 + 'Enabled Items: ' + VarToStr(itemsInfo[2]));

end;



Is this what you need?



------
Yuri
TestComplete Customer Care Engineer

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
DHB
Occasional Contributor

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)


TC 7.52/8.70/9.20 Standard, DelphiScript

cancel
Showing results for 
Search instead for 
Did you mean: