Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

How can I count the number of testcases in a Testplan using SilkTest?

How can I count the number of testcases in a Testplan using SilkTest?

Treat the Testplan as an external text file and use SilkTest to search for a substring target within each line. This piece of code can easily be adapted to search for other specific items within any text file.

To use this piece of code to count the number of testcases in a Testplan, you will need to edit the information within square brackets before running it, here is an example of what you will need to change;

[ ] sFileName="C:\Program Files\Segue\SilkTest\Projects\Test1\Test1.pln"
[ ] sSubString="testcase:"

Note that for the substring we are using the word testcase followed by a colon ":", this means that it will only search for an instance of testcase as a Testplan Keyword.

[-] testcase CountAllTestcases() appstate none
    [ ] //Name the variables
    [ ] HFILE hFile                  //Handle to the file
    [ ] STRING sFileName       //Filename and path
    [ ] STRING sLine              //Any line within the file
    [ ] STRING sSubString      //Substring to search for within the line
    [ ] FILEMODE fmMode       //FileOpen mode
    [ ] FILESHARE fShare       //Sharing behaviour
    [ ] INTEGER iExist            //If greater than zero then the target is found
    [ ] INTEGER iTotal            //Total number of substring instances
    [ ] 
    [ ] //Set the constants
    [ ] sFileName="[path and filename]"
    [ ] sSubString="[information to search for]"
    [ ] fmMode=FM_READ        //Make the file read-only
    [ ] fShare=FS_EXCLUSIVE  //Deny access to anyone else
    [ ] iTotal=0
    [ ] iExist=0
    [ ] 
    [ ] //Loop through the target file searching for instances of the substring
    [ ] hFile=FileOpen(sFileName,fmMode,fShare)
    [-] while (FileReadLine (hFile,sLine))
        [ ] iExist=0
        [ ] iExist=StrPos(sSubString,sLine)
        [-] if iExist>0  
            [ ] iTotal++
    [ ] FileClose(hFile)
    [ ] print("The total number of [search targets] is: "+ str( iTotal))

If you cannot be certain that the substring target you are searching for will be unique within a line, then you may modify the search loop to look for two or more substrings as follows:-

[ ] //Modified variant to search for two or more unique items within a line
    [ ] //Loop through the target file searching for instances of the substring
    [ ] //When it is found, search the line again for the second substring target
    [ ] //Nest as many inner checks as needed to ensure the correct target is hit
    [ ] hFile=FileOpen(sFileName,fmMode,fShare)
    [-] while (FileReadLine (hFile,sLine))
        [ ] iExist=0
        [ ] iExist=StrPos(sSubString1,sLine)
        [-] if iExist>0
            [ ] iExist=StrPos(sSubString2,sLine) 
            [-] if iExist>0
                [ ] iTotal++
    [ ] FileClose(hFile)
    [ ] print("The total number of [search targets] is: "+ str( iTotal))

Old KB# 21251

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:18
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.