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 to write a value in a specific cell in the .CSV file?

GayathriGayathri Members
edited January 2013 in Sahi - Open Source
I have all my script names ordered in a column (in a .CSV file). After successful execution of the first script, I want my main script to write a value as 'Passed' in the next column (on the same row against my script name). Similarly, for subsequent rows.
ie, I am trying to create the overall test execution report for each scripts.
My .CSV should read as below with two columns as 'ScriptName' and 'ExecutionStatus'.

ScriptName ExecutionStatus
Script1.sah Success
Script2.sah Failure
Script3.sah Success

Currently, I am able to read my script name from the first column. After Script1 execution, how do make the main script to update the status in the next column, against the script name ?

Please help.

Answers

  • gaveyomgaveyom Members
    edited January 2013
    Hi Gayathri,


    we need to pass 2 dimensional array for "writeCSVFile()" method, below is the example code

    
    "writeCSVFile($array, "CSVFileName.csv")" method
    

    array[$i][$j], $i represents row and $j represents column


    Below is the code to write a data into specific cell of csv file, hope this code will help for u
    
    
    var $writeData = [];
    
    try {
    
    	for(var $cnt_Row=0; $cnt_Row<10; $cnt_Row++) {
    	
    		$writeData[$cnt_Row] = [];
    		for(var $cnt_Clm=0; $cnt_Clm<10; $cnt_Clm++) {
    
    			$writeData[$cnt_Row][$cnt_Clm] = $cnt_Row +", "+ $cnt_Clm;
    		}
    	}
    }catch($e) {
    	_logExceptionAsFailure("Exception: "+ $e);
    }
    
    _writeCSVFile($writeData, "csv_write.csv", true);
    
    


  • The above code writes the data in each cell as an array. However, I want to write a specific value in any cell (in the .CSV file).

    For example, I want to write the text 'Success' in cell 'D1'. Similarly, my script should write specific values in the required column.

    Please help.
  • Team,

    This is still not answered completely. Please open up the loop.
  • Naveen,

    Are you trying to answer my question? I guess this response to be a wrong post.
  • You can try to use sahi call back functions, onScriptFailure(), onScriptError(), onScriptEnd()
  • narayannarayan Administrators
    Hi Gayathri,

    As gaveyom mentioned, you need to read the csv file into a 2D array, change the particular array item value and then write it back.

    For example,
    // Read the data in to array
    var $data = _readCSVFile("my.csv");
    // Set the value where required
    $data[0][3] = "myvalue"; // 0 is row 1, 3 is column D
    // Write back the data
    _writeCSVFile($data , "my.csv");
    

    Having said this, Sahi Pro already has the ability to take a CSV file as a suite, execute it, and update the file along with a link to output.

    Regards,
    Narayan



Sign In or Register to comment.