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.
Writing array to file using _writeCSVFile()
I'm trying to write the contents of my array to a flat file. However the output is appearing in the file like :
"Q","A"," ","S","I","T","E"," ","8","5","2","4",",","Q","A"," ","C","O","U","R","S","E"," ","8","5","2","4""Q","A"," ","S","I","T","E"," ","2","2","9","8",",","Q","A"," ","C","O","U","R","S","E"," ","2","2","9","8""Q","A"," ","S","I","T","E"," ","6","6","9","2",",","Q","A"," ","C","O","U","R","S","E"," ","6","6","9","2""Q","A"," ","S","I","T","E"," ","1","8","8","3",",","Q","A"," ","C","O","U","R","S","E"," ","1","8","8","3"
instead of :
QA SITE 8524,QA COURSE 8524
QA SITE 2298,QA COURSE 2298
.....
Here's my code ($userCountBegin is a random number):
var $arrWriteSiteCourse = new Array();
for ($i = 0; $i < $noOfUsers; $i++)
{
var $site = "QA SITE" + " " + $userCountBegin;
createSite($site);
// Create course
var $course = "QA COURSE" + " " + $userCountBegin;
createCourse($site,$course);
$arrWriteSiteCourse[$i] = $site + "," + $course;
$userCountBegin++;
}
//_alert($arrWriteSiteCourse[0]);
_writeCSVFile($arrWriteSiteCourse,"C:/sahi/userdata/scripts/sitesCourse.csv");
What am I doing wrong here ?
When I use _alert($arrWriteSiteCourse[0]); for debugging, the alert shows:
QA SITE 8524,QA COURSE 8524
Thanks in advance for your help.
Cheers
Rajeev
"Q","A"," ","S","I","T","E"," ","8","5","2","4",",","Q","A"," ","C","O","U","R","S","E"," ","8","5","2","4""Q","A"," ","S","I","T","E"," ","2","2","9","8",",","Q","A"," ","C","O","U","R","S","E"," ","2","2","9","8""Q","A"," ","S","I","T","E"," ","6","6","9","2",",","Q","A"," ","C","O","U","R","S","E"," ","6","6","9","2""Q","A"," ","S","I","T","E"," ","1","8","8","3",",","Q","A"," ","C","O","U","R","S","E"," ","1","8","8","3"
instead of :
QA SITE 8524,QA COURSE 8524
QA SITE 2298,QA COURSE 2298
.....
Here's my code ($userCountBegin is a random number):
var $arrWriteSiteCourse = new Array();
for ($i = 0; $i < $noOfUsers; $i++)
{
var $site = "QA SITE" + " " + $userCountBegin;
createSite($site);
// Create course
var $course = "QA COURSE" + " " + $userCountBegin;
createCourse($site,$course);
$arrWriteSiteCourse[$i] = $site + "," + $course;
$userCountBegin++;
}
//_alert($arrWriteSiteCourse[0]);
_writeCSVFile($arrWriteSiteCourse,"C:/sahi/userdata/scripts/sitesCourse.csv");
What am I doing wrong here ?
When I use _alert($arrWriteSiteCourse[0]); for debugging, the alert shows:
QA SITE 8524,QA COURSE 8524
Thanks in advance for your help.
Cheers
Rajeev
This discussion has been closed.
Comments
Change
$arrWriteSiteCourse[$i] = $site + "," + $course;
to
$arrWriteSiteCourse[$i] = [$site, $course];
and it will work.
Explanation:
1) When you set $arrWriteSiteCourse[$i] = $site + "," + $course, Sahi got a string where it was expecting an Array. In javascript, you can index through a string to get each character, which is what Sahi got when it accidentally iterated over the string instead of an array.
2)
var $x = is short for
var $x = new Array();
$x[0] = 'a';
$x[1] = 'b';
Regards,
Narayan