cancel
Showing results for 
Search instead for 
Did you mean: 

Automatically storing property file contents.

steventwerd
Occasional Contributor

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

4 REPLIES 4
vinniew
Staff

Re: Automatically storing property file contents.

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
Occasional Contributor

Re: Automatically storing property file contents.

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
Staff

Re: Automatically storing property file contents.

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... ?

 

steventwerd
Occasional Contributor

Re: Automatically storing property file contents.

Hi Vinnie,

 

Apologies, I see I am making this unnecessarily confusing. The property file has to be a text-file (.txt) for other uses. I know I can read data from the property file using the code mentioned previously. I'm just curious if there is another way to read data from a text-file and store it in a variable without having to put that lengthy piece of code at the beginning of every script. Sort of like making it into an environment variable for all scripts to use.

 

Thanks.

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors