Forum Discussion

NairatAhmad's avatar
NairatAhmad
New Contributor
8 years ago

Comparing file from stores to output file locks both files sometimes

Hi,

 

I have around 300 test cases for a desktop application, each has a saved expected result file in the Files stores.

 

Each test case works as follows :

 

Generates a data table.

Export the data table to a file.

Then : Files.stored_file.check("D:\thing\output_file.txt");

 

so the first time, the file gets exported and saved and compared succesfully, now if you re-run the test case ,, sometimes it works, and sometimes not! no specific steps to reproduce!

 

Reason is that the output file gets locked, and won't get deleted/overwritten unless test complete is closed.
if you reopen test complete it works very well.

 

can you please help me with this?

 

Thanks.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    What it sounds like is your process for exporting the file is somehow locking the file.  Could you post more of your actual code you're using?  Perhaps you're not freeing the file handle appropriately.

    • NairatAhmad's avatar
      NairatAhmad
      New Contributor

      Thanx for the reply,

       

      The main application closes the file well, I even tried to create that csv file using notepad++ and then use test complete to compare with it, sometimes the file gets locked and sometimes not.

       

      there's no much code, just a line of comparison :

       

      assuming the expected output is named stored_file.

      and assuming my target file which is produced by the external app is D:\thing\output_file.txt

       

      I use this line of code as a check point:

       

      Files.stored_file.check("D:\thing\output_file.txt");

       

      shall I do some sort of file.close or something after the check command?

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        So, if it's your application that's doing the file export, is there some indicator on screen in your application that indicates that the export is complete?  What you've described as your problem certainly sounds like some sort of timing issue to me where the file is still in process when TestComplete attempts the comparison. If there is such an indicator, I'd add some sort of "Wait Property" call or some sort of wait until that indicator has changed state to indicate that the file export is complete and THEN do your file check.