cancel
Showing results for 
Search instead for 
Did you mean: 

Update result to data source cell?

Highlighted
Contributor

Update result to data source cell?

Hi all,

I'm using a data source to drive my testing. Is it possible to write results to designated cells inside my data source?

Thanks in advance,
Testranger
6 REPLIES 6
Highlighted
Frequent Contributor

Re: Update result to data source cell?

yes,you would store the values in form of key-value, if need, along with data source loop step to save your data multitimes.by the way, also make sure of property step instead of data source to save data.Actually, there are more approach to set or get values through properties of different level,anyway, you would select what you think the best and comply with the current test scenarios.



Thanks,
Aaron
Highlighted
Contributor

Re: Update result to data source cell?

Thanks, can you provide sample code for this. Fyi, i'd like to update to an xls file.
Regards,
Testranger
Highlighted
Frequent Contributor

Re: Update result to data source cell?

I have not definitely made sense of your expected result. if you just want to update data to datasource step only.I don't think you should do it like this.I mean both the data source step and data source loop step will help you implement loop. assuming that there is such test scenario:
1.data source (to store a series of values)
2.test request (to make use of these values)
3.data sink (to save the updated values)
4.data source loop (associate with data source step to implement loop)

as for xls file, if you want to use script to write updated values to external xls file, maybe you need to import jxl.jar first and then make use of groovy script to implement it. if need, later I will share with you.


thanks,
Aaron
Highlighted
Contributor

Re: Update result to data source cell?

Hi,

I'm using a datasource connected to an XLS file, to run my test. There is a Result column in my XLS file. I'd like to populate the result of the test into this column, i.e. PASS or FAIL.
I've seen this done before in other automation tools. If soapui can do this it would be the most complete tool ever for WS testing - but I'm not seeing any evidence of this. (i can image the fact that the data source may be locked for reading and writing may not be logically possible)


Regards,
Testranger
Highlighted
Frequent Contributor

Re: Update result to data source cell?

here is a way which using script to read data from xls and write data to xls:

ReadExcel:

//Need to import jxl.jar to %SOAP UI%\ext folder first
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public static String readExcel(File file) {
StringBuffer sb = new StringBuffer();
Workbook wb = null;
try {
wb = Workbook.getWorkbook(file);
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (wb == null){
return null;
}
Sheet[] sheet = wb.getSheets();
if (sheet != null && sheet.length>0){
for (int i = 0; i<sheet.length;i++){
int rowNum = sheet[i].getRows();
for (int j=0;j<rowNum;j++){
Cell[] cells = sheet[i].getRow(j);
if (cells != null && cells.length>0){
for (int k = 0;k<cells.length;k++){
String cellValueString = cells[k].getContents();
sb.append(cellValueString+"\t");
}
}
sb.append("\r\n");
}
sb.append("\r\n");
}
}
wb.close();
return sb.toString();
}

def file = new File ("C:"+File.separator+"hello.xls")
log.info readExcel(file)


WriteExcel:

import jxl.Workbook;
import jxl.write.WritableWorkbook;
import jxl.write.WritableSheet;
import jxl.write.Label;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

public static void writeExcel(String fileName){
WritableWorkbook wwb = null;
try {
//declare object of Workbook
wwb = Workbook.createWorkbook(new File(fileName));
} catch (IOException e) {
e.printStackTrace();
}
if(wwb!=null){
WritableSheet ws = wwb.createSheet("sheet1", 0);

for(int i=0;i<10;i++){
for(int j=0;j<5;j++){

Label labelC = new Label(j, i, "This is"+(i+1)+"Row,"+(j+1)+"Column");
try {
ws.addCell(labelC);
} catch (RowsExceededException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
}

}
}

try {
wwb.write();
wwb.close();
} catch (IOException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
}
}
}

def file = new File ("C:"+File.separator+"hello.xls")

log.info writeExcel("C:/hello.xls")
Highlighted
Contributor

Re: Update result to data source cell?

Thanks for that I tried it and it worked just as I expected.
Much appreciated.

Regards,
TestRanger
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors