18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
Verifying contents of a text file
Hi,
How to verify contents of a text file
Example:
I have a log file abc.txt
When ever I do any operations on UI, this file will be updated. Please provide me the code to verify that the file contains the required content or not.
Scenario: I have created a user. The log file will contain an entry "<Time_Stamp> user "abc" is created by "admin user".
Thanks,
Samsirsameer
How to verify contents of a text file
Example:
I have a log file abc.txt
When ever I do any operations on UI, this file will be updated. Please provide me the code to verify that the file contains the required content or not.
Scenario: I have created a user. The log file will contain an entry "<Time_Stamp> user "abc" is created by "admin user".
Thanks,
Samsirsameer
Comments
_readFile will help you in this case.
http://sahi.co.in/w/_readfile
If you need further help you can give the log file and the required assertions. we will try to work out the solution
Regards,
Pankaj
My file contents
***************************************SOME MESSAGES***************************************
***************************************SOME MESSAGES***************************************
***************************************SOME MESSAGES***************************************
***************************************SOME MESSAGES***************************************
[ 0, 3, 7, 235] 04-07-2009 11:51:25.557 INFO xgEnterpriseProxy: Device registered with server https://192.168.161.7/eMessage: model: 1Nowkiya_Connector, serial number: 1Nowkiya_Device2
[ 0, 3, 7, 235] 04-07-2009 11:51:25.557 INFO xgEnterpriseProxy: Device registered with server https://192.168.161.7/eMessage: model: 1Nowkiya_Connector2, serial number: 1Nowkiya_Device3
[ 0, 3, 7, 235] 04-07-2009 11:51:25.557 INFO xgEnterpriseProxy: Device registered with server https://192.168.161.7/eMessage: model: 1Nowkiya_Connector2, serial number: 1Nowkiya_Device4
[ 0, 3, 36, 896] 04-07-2009 11:54:57.258 INFO xgAPMProxy: New policy received from Samsir Policy Server for model: 1Nowkiya_Connector, serial number: 1Nowkiya_Device2
Above is my log file named 'xGate.log'.
In my application, I have some policies, if I update any policy, the following entries are displayed in th e log file at the end
[ 0, 3, 36, 896] 04-07-2009 11:54:57.258 INFO xgAPMProxy: New policy received from Samsir Policy Server for model: 1Nowkiya_Connector, serial number: 1Nowkiya_Device2
In above example, I have updated policy for device '1Nowkiya_Device2
Whenever I update the policy, the above mentioned entries are displayed in log file.
I need to verify whether the above properties are displayed or not
you can use this approach: just try on these lines and see if it helps.
Regards,
Pankaj.
but my entry will not go at the last of log file.
But it will be 2 or 3 (or more than that) lines above the end of the file.
Could you please provide the code to test this.
Thanks for your King Support!
Thanks,
Samsirsameer.
var $fileContents = _readFile("C:\\xGate.log");
will put the entire content of the file into the $fileContents variable. If you are not sure on which lines you will have the required text then you can use the pattern matching on the entire content of the file.
eg. see if this helps or you can make your use case more clear.
Regards,
Pankaj.