Knowledge Base Article

Function to Read the text file and compare with the Baseline

This function will help to read the text file and compare it with Baseline text string.

Use Case would be like it will help to read the Logs or any Text File and than compare with the Baseline or any expected Text output in the file.

//function is to find Text in the Text File and compare with the Baseline
function CompareTextLine(filePath,stringid, baseline)
{
var read, line, result, nores;
//open and read text file
read = aqFile.OpenTextFile(filePath, aqFile.faRead, aqFile.ctANSI); //set the ANSI UTF or any other format of Text File
read.Cursor = 0;
nores = 0;

//Searching each line for the identifying key string
while(! read.IsEndOfFile())
{
line = read.ReadLine();
result = aqString.Find(line, stringid);

if (result != -1)
// -1 indicates occurrence not found
{
Log.Message("The key string identifier was found in this line = " + line + "; the baseline to compare = " + baseline);
if (baseline == line)
{
Log.Checkpoint("The string found matches the baseline");
return;
}
else
{
Log.Warning("The value is not correct. Actual = " + line + "; Expected = " + baseline);}
nores = 1;
}
}
read.Close();
//Log error if string was not found
if (nores == 0)
Log.Error("String was not found in any of the text lines.");
}




Updated 3 years ago
Version 2.0

Was this article helpful?

No CommentsBe the first to comment