18 January 2026:


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

SamsirsameerSamsirsameer Members
edited November -1 in Sahi - Open Source
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

Comments

  • Anybody Please reply.........
  • Hi Samir,

    _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
  • Hi,

    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
  • Please reply....
  • Hi,

    you can use this approach:
    var $fileContents = _readFile("C:\\xGate.log");
    var $lines = $fileContents.replace(/\r/g, '').split("\n");
    //i assume that your new entry goes to the last line in the file 
    var $data = $lines[$lines.length - 1];
    var $x = $data.match(/serial number:  1Nowkiya_Device2/);//or you can match the entire pattern.
    
    just try on these lines and see if it helps.

    Regards,
    Pankaj.
  • Hi Thanks for teh reply.

    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.
  • Please Reply..........
  • Any1 please reply...
  • Hi,

    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.
    var $fileContents = _readFile("C:\\xGate.log"); 
    var $fileContents = $fileContents.replace(/\r/g, ''); 
    var $x = $fileContents.match(/serial number:  1Nowkiya_Device2/);//change the pattern to your required one.
    
    see if this helps or you can make your use case more clear.

    Regards,
    Pankaj.
Sign In or Register to comment.