Hello Guys,
i want to check the content of a textfile.
Which testmethod i can use for it?
In my textfile is written a number. If the number is higher than value x i want to get a bad status back. If the value is below x i want to get the good status.
Can you help me to make it possible?
Thanks,
Malus
Check File Content
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
You need to use Shell Script test with custom made script.
E.g. Custom JavaScript may look like the following:
Start cmd: cmd /c cscript /B /E:JScript %Script% %Params%
Script requires 2 parameters: <path to the file> <max value>
Please note, if file path contain spaces, it shopuld be quoted. E.g.:
"D:\new logs\data.txt" 47
E.g. Custom JavaScript may look like the following:
Code: Select all
statusUnknown = "ScriptRes:Unknown:";
statusOk = "ScriptRes:Ok:";
statusBad = "ScriptRes:Bad:";
var objArgs = WScript.Arguments;
if (objArgs.length!=2) {
WScript.StdOut.Write(statusUnknown + 'Required 2 parameters: <file path> <max val>');
WScript.Quit();
}
fname = objArgs(0);
maxval = parseFloat(objArgs(1),10);
str = '';
try {
var oFS = new ActiveXObject('Scripting.FileSystemObject');
var oFile = oFS.OpenTextFile(fname);
str = oFile.ReadAll();
oFile.Close();
} catch(e) {
WScript.StdOut.Write(statusUnknown + e.message+' ['+fname.replace(/\\\\/g,'\\')+']');
WScript.Quit;
}
var fval = parseFloat(str,10);
if (fval>maxval) {
WScript.StdOut.Write(statusBad + str);
} else {
WScript.StdOut.Write(statusOk + str);
}
Script requires 2 parameters: <path to the file> <max value>
Please note, if file path contain spaces, it shopuld be quoted. E.g.:
"D:\new logs\data.txt" 47