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.

Writing test results into an Excel file

devdev Members
edited November -1 in Sahi - Open Source
Following code;
was working fine (write "SUCCESS" value into excel sheet)when scripts was successfully run.
Issues is when the scripts get fail, it not writing anything into the excel sheet

here is the code;
$sets = _scriptStatus()
db.update("update [Sheet1$] set Results= '" + $sets + "' where TC_ID='001'");

Comments

  • Hi dev,

    If you want to write into excel sheet when the script is failed then you will have to use javascript try catch blocks.

    For more Details:

    http://sahi.co.in/w/exception-handling

    Eg: You can try the below script on http://sahi.co.in/demo and creating an excel file in D folder.
    var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver","jdbc:odbc:Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=D:\\trial.xlsx;readOnly=false", "", "");
    var $status = "SUCCESS";
    try{
    _click(_link("Link Test"));
    _click(_link("Back"));
    _click(_link("Blank Page"));
    _navigateTo("/demo/index.htm");
    db.update("update [Sheet1$] set Status='" + $status + "',Age=21 where Name='Raju'");
    }
    catch(f){
    $status = "FAILURE";
    _logExceptionAsFailure(f);
    db.update("update [Sheet1$] set Status='" + $status + "',Age=21 where Name='Raju'");
    }
    

    Check if this helps you to solve your issue.

    Regards
    Sumitra
  • devdev Members
    Hi Sumitra,

    Thanks for the help, it's works.

    One small thing, how can I write error message or error details into an Excel sheet when the test scripts got failed.
  • Hi dev,

    In catch(f),the f itself contains the error message.

    You can now write these error message to the excel sheet.

    Here is the example :
    var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver","jdbc:odbc:Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=D:\\trial.xlsx;readOnly=false", "", "");
    var $status = "SUCCESS";
    try{
    _click(_link("Link Test"));
    _click(_link("Back"));
    _click(_link("Blankv Page"));
    _navigateTo("/demo/index.htm");
    db.update("update [Sheet1$] set Status='" + $status + "',Age=21 where Name='Raju'");
    }
    catch(f){
    $status = "FAILURE";
    var $exception = f.message;
    _logExceptionAsFailure(f);
    db.update("update [Sheet1$] set Status='" + $status + "',Age=21, Exception='" + $exception + "' where Name='Raju'");
    }
    

    Hope this solves your issue.

    Regards
    Sumitra
  • devdev Members
    Hi Sumitra,

    Thanks for the help, it's works.
This discussion has been closed.