Forum Discussion

steventwerd's avatar
steventwerd
Occasional Contributor
4 years ago

Automatically storing property file contents.

Hi,

I was curious, I know there are ways to read files like text files and xml files from a script test, I wanted to ask if there was a way to automatically read from the file and store its contents elsewhere in TestComplete so that I wouldn't have to get/read the file at the beginning of every script test? (The property file in question will simply hold a key-value pair).

Thanks

  • Hi steventwerd 

     

    Hope you are well. 

     

    Does the key-value pair change often? 

     

    You could check out using stores 

     

    see https://support.smartbear.com/testcomplete/docs/testing-with/checkpoints/stores/files/index.html

     

    You could also look at parametrization of your tests and call the required pair values at execution 

     

    https://support.smartbear.com/testcomplete/docs/testing-with/parameterizing/about.html

     

    Let me know if this could work

     

    KR 

    Vinnie

    • steventwerd's avatar
      steventwerd
      Occasional Contributor

      Hi Vinnie,

       

      I'm going on the scenario that the key-value pairs do change often or the values at least do.

      The problem with Stores is that it seems to only involves checking and comparing and updating the contents of the file, I just want to use (not check or change) the data in UI tests, similarly to a data-driven loop using Excel but with a text file containing key-value pairs.  

      The problem with parametrization is that I would have to manually change the data for every test to run with the desired info, I would much rather the variables/data be in a text-file to read from for efficiency.

       

      What I want is to not have to have this long line of code at the beginning of ever script test to get a variable:

      function ReadFile(AFileName)
      {
        const ForReading = 1;
        const ForWriting = 2;
        const ForAppending = 8;
        let FS = getActiveXObject("Scripting.FileSystemObject");

        let F = FS.OpenTextFile(AFileName, ForReading);
        while(! F.AtEndOfStream){
          let s = F.ReadLine();
          Log.Message(s);
        }
        F.Close();
      }

      • vinniew's avatar
        vinniew
        Staff

        Hi Steven 

         

        Thanks for that, 


        I am not well phrased on how to work around your scripted workaround. 

         

        Could the data in the text file be phrased/formatted as a table? then look at using maybe a table variable via Data loop? 

         

        If then, choosing only the top row, (1 record from the range) specifying that file and then if the pair values change we update the file instead of the test, would that work or would the effort editing the file still cause issues... ?