Forum Discussion

gentlesea's avatar
gentlesea
Frequent Contributor
14 years ago

Code for removing existing regions (e.g. images) from the store of the current project


Hello, please have a look at the following code:



    var projectPath = aqFileSystem.GetFolderInfo(Project.Path);

    var regionsPath = projectPath.Path + "\Stores\\Regions\\";

    foundFiles = aqFileSystem.FindFiles(regionsPath, "*.png", true);

    if (foundFiles != null)

    {

      while (foundFiles.HasNext())

      {

        aFile = foundFiles.Next();

        var fileToBeDeleted = aFile.Path;

        aqFileSystem.DeleteFile(fileToBeDeleted);

      }

    }

    else 

      Log.Message("No files were found.");





    var fileToBeDeleted = projectPath.Path + "\Stores\\Regions.tcRegions";

    aqFileSystem.DeleteFile(fileToBeDeleted);

    fileToBeDeleted = projectPath.Path + "\Stores\\Stores.tcStores"; 

    aqFileSystem.DeleteFile(fileToBeDeleted);





I tried to remove the regions and store like above. But I do not know how to trigger a refresh of the project or better add a blank store with one blank regions object. Can you help me with this?
  • Hello



    You'd better not try modifying or deleting files of the currently opened project outside from TestComplete, since this may corrupt the project.



    To manage the Regions collection from tests, use the Regions scripting object. For example, to remove all existing images from the Regions collection:



    function ClearRegions()

    {

    var RemoveFromDisk = true;



    while (Regions.Count()>0)

        Regions.Remove(Regions.NameByIndex(Regions.Count()-1), RemoveFromDisk);

    }

  • It would be very helpful if TestComplete provided a mechanism for removing all Regions that are not referred to by any test.  Such regions can easily accumulate in the course of test development and it would be nice to be able to clean them up.
  • Hi Michael,



    This is a good idea. Moreover, it would be handy for every item of the Stores collection. We have registered your request in our database as a suggestion. Thanks a lot.
  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 3 rankChampion Level 3
    Hi Michael,



    The potential risk here is if the name of the Region (file, etc.) is not hardcoded statically but generated dynamically by code during the test run (e.g. for i = 1 to 5 do region.compare('Region#'+i) ).

    Personally I would think thrice before running such cleanup on real project and only after backing it up... :)