How to use writeToCSVFile() fuction?

by 
 on 06-Dec-2005 07:56 AM.
  in  Test Automation 
Hi,
Can anybody please tell me how to use the function writeToCSVFile().
I was trying to do it by puting a string inside the Data textfiled, but i am getting the following error :
Unable to convert Hi to String[] or String[][]

Please let me know how to use this function and where are the places i can use it(any example?). Can i use this function with getCellValueAt() function? I mean want to get the value using getCellValueAt() and want to write it in the .csv file using writeToCSVFile(). Is it possible? If possible, please let me know how to do it.

Thanks in advance,
Saikat
  • No status

Re: How to use writeToCSVFile() fuction?

by 
 on 06-Dec-2005 08:12 AM
Hi Saikat,
The issue you are facing is due to incorrect construction of array using Python. A sample script illustrating the generation of single dimension array and the use of writeToCSVFile function, is given for your reference.

from jarray import zeros
import java.lang.String as str

result_array=zeros(5,str)
result_array[0]="test"
result_array[1]="test1"
result_array[2]="test2"
result_array[3]="test3"
result_array[4]="test4"
writeToCSVFile("abc",result_array,"true")


A bug in writing of single dimension array to CSV file was found in our side. To solve that download and unzip the csv_write zip file patch under QEngine/jars directory, using the following link.

http://bonitas.adventnet.com/qengine/08Nov2005/csv_write.zip

writeToCSVFile usage example:
1)writeToCSVFile can be used with getCellValueAt after assigning the getCellValueAt result to an array variable as follows:
For e.g:
result=getCellValueAt("S.No",9,9)

from jarray import zeros
import java.lang.String as str

result_array=zeros(1,str)
result_array[0]=result
writeToCSVFile("a.csv",result_array,"true")

2)writeToCSVFile can be directly used with getHTMLTableColumnValues, getAllHTMLTableCells that return a array as follows.

result=getHTMLTableColumnValues("S.No_1",3)
writeToCSVFile("ab.csv",result,"true")


Sorry for the inconveniences caused.
Do get back to us for further support.

With thanks and regards,
Yamini.S
QEngine-Support

Re: How to use writeToCSVFile() fuction?

by 
 on 06-Dec-2005 08:53 AM
waitForPageDownload()
result=getHTMLTableColumnValues(" _3",3)
writeToCSVFile("/home/saikat/WriteToCSV.csv",result,"true")
displayMessage("#########################################################")
displayMessage(result)
displayMessage("#########################################################")

Hi Yamini,
The above code is generating a junk value.
The values its displaying is somthing like this : [Ljava.lang.String;@1c4120e
even though i've kept the CSVWriter.class file inside the jars directory. The CSVWriter.class is inside com/adventnet/qengine/web/server/util dir. I've kept the directory com in the jars dir. Also i've kept the CSVWriter.class inside the jars.

Please look into it and let me know what i should do. And can i give the .csv file path inside the writeToCSVFile() function.

Kind Regards,
Saikat

Re: How to use writeToCSVFile() fuction?

by 
 on 06-Dec-2005 10:05 AM
Hi Saikat,
Please give the csv file name alone and not the complete path in the writeToCSVFile function. By default the .csv file will be created with the specified name under QEngine\projects\suiteName\dataset folder.

E.g.
result=getHTMLTableColumnValues(" _3",3)
writeToCSVFile("WriteToCSV.csv",result,"true")

Regarding the junk value [Ljava.lang.String;@1c4120e you get in the output is not really a junk value. It is the output of getHTMLTableColumnValues as pointer to array. If you want to print the getHTMLTableColumnValues output as a value, use the for loop as follows:
for i in range(0,len(result)):
for j in range(0,len(result)):
displayMessage(str(result[j]))
Hope this would solve your problem.
Do get back to us for further clarifications.
With thanks and regards,
Yamini.S

Re: How to use writeToCSVFile() fuction?

by 
 on 06-Dec-2005 10:34 AM
Hi Yamini,
I have tried the following code
clickLink("View",1)
waitForPageDownload()
result=getHTMLTableColumnValues(" _3",3)
for i in range(0,len(result)):
for j in range(0,len(result[i])):
displayMessage("########################################################")
displayMessage(str(result[i][j]))
displayMessage("########################################################")
writeToCSVFile("WriteToCSV.csv",str(result[i][j]),"true")

But the control is never going the for loop, its not displaying anything and in the .csv file its not writting anything. Will you kindly tell me why we have to use an array. Why i am asking is i want to retrieve a single value from a cell and i want to write it in some .csv file. Is there any other way of doing it?

Thank you very much,
Saikat

Re: How to use writeToCSVFile() fuction?

by 
 on 06-Dec-2005 11:41 AM
Hi Saikat,
The problem with the code is that you had given the writeToCSVFile inside the for loop and passed a string as second argument to the writeToCSVFile function. If you only want to write the values into the file kindly change your code as follows:

result=getHTMLTableColumnValues(" _3",3)
writeToCSVFile("WriteToCSV.csv",result,"true")

The above code will write the TableColumnValues in WriteToCSV.csv file under QEngine\suiteName\dataset folder.

If you want to retrieve a single value from a cell and want to write it in some .csv file use the writeToCSVFile funtion along with the getCellValueAt function as follows.

result=getCellValueAt("S.No",9,9)
from jarray import zeros
import java.lang.String as str
result_array=zeros(1,str)
result_array[0]=result
writeToCSVFile("a.csv",result_array,"true")

As the second argument to the writeToCSVFile is a Array variable. there is no
alternate way of doing the same.
Hope this would solve your problem.
Do get back to us for further support.

With thanks and regards,
Yamini.S
Post Actions
Statistics
  • 5
     Replies
  • 2840
     Views
  • 0
     Followers
Tags for the post
No tags available for this topic.
© 2009 Corp. All rights reserved. Trademarks | Privacy Policy | Site Map | Contact Us | Careers

Edit Link Delete Link

Edit Link Delete Link

LoadingImage