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.

How should I debug the _readFile function failure?

ilovepumpkinilovepumpkin Members
edited November -1 in Sahi - Open Source
I have two files a.txt and b.txt and they have different contents. _readFile can return content of a.txt but not for b.txt - looks like the content of b.txt breaks the _readFile function. There is no error and exception but just got NULL. I tried to look for log files of Sahi but there is no .log files under Sahi home directory. I found log.properties file under userdata directory and it points the log files to /tmp but I still cannot see the log files. So I specify '-Djava.util.logging.config.file' for java command and again I still cannot get log files. Could you please let me how should I troubleshoot this problem? Thanks.

Comments

  • I think I have found the root cause - _readFile cannot handle the file containing '%'. Where can I report this bug? Or you will help to record this bug?
  • Hi ilovepumpkin,

    I tried using % in the file and it works fine for me.

    Could you please let me know how you are using _readFile() API for both the files.

    Also, could you post the content of the txt file here to help us reproduce the behaviour?

    Regards
    Sumitra
  • ilovepumpkinilovepumpkin Members
    edited December 2011
    Here is my code:

    var content=_readFile(filePath);
    if(content==null){
    _log("Cannot load content from "+filePath,"error");
    }

    And the file content is just: name=test % test . The file encoding is UTF-8 -- I am not sure if it does matter or not.

    Thank you for looking into this. I am using the latest open source version.
  • Hi ilovepumpkin,

    The code should be:

    var $content=_readFile($filePath);
    if($content==null){
    _log("Cannot load content from "+$filePath,"error");
    }

    Check if this solves your issue.

    Also, even if the file encoding is UTF-8 Sahi will read % character from a file.

    Regards
    Sumitra
  • Unfortunately this does not solve my problem. Are you using Sahi V3.5 '(Build:2011-07-19) released'? This is what I am using.
  • Hi ilovepumpkin,

    Yes,i m using the Sahi V3.5 version.

    Could you please check if you are placing the file in non accessible directory?

    Are a.txt and b.txt in the same directory?

    Also, the following code works fine for me :
    var $filepath = "C:\\sahi-2011-07-19\\userdata\\testReadFile.txt";
    var $content=_readFile($filepath);
        if($content!=null){
        _log("File contents is: " + $content,"INFO");
    }
    

    The testReadFile.txt contains : test % name

    Regards
    Sumitra
  • First of all, thanks a lot for your time to spend on this issue. Now I know how to reproduce it. My .sah file is below -- to reproduce this issue, you need to invoke the _readFile function in <browser> tag. It works fine indeed if _readFile is invoked outside of <browser>. Please let me know if you could reproduce it now.

    =======================
    <browser>
    function readFileTest(){
    var $filepath = "/tmp/testReadFile.txt";
    var $content=_readFile($filepath);
    if($content!=null){
    _log("File contents is: " + $content,"info");
    }else{
    _log("Failed to read file","error");
    }
    }
    </browser>

    _call(readFileTest());
  • Hi ilovepumpkin,

    Yes, even i am able to reproduce the same.

    If you want to read a file which is on server you can use _readURL() API or else use _readFile() API.

    Regards
    Sumitra
  • ilovepumpkinilovepumpkin Members
    edited December 2011
    Thanks. My requirement is to read a local file (my testcases and proxy server are running on the same machine) so _readURL() API does not apply for my case. And I found _readURL() API is not shown in http://sahi.co.in/w/all-apis , but looks like it just takes a URL as a parameter. For now, I have to delete all the occurrences of '%' in the files and fortunately this won't impact my program much except one more step is needed before reading the files. Will you fix this bug in the next version? When will your next version be released?
Sign In or Register to comment.