Contributions
Write properties to output Excel file
import jxl.* import jxl.write.* file = new File("D:\\soapui-practice\\OutputResult.xls") if(!file.exists()){ log.info "file does not exists create new worksheet headers, and first line of values"; WritableWorkbook workbook1 = Workbook.createWorkbook(file) WritableSheet sheet1 = workbook1.createSheet("Worksheet Number 1", 0) log.info(sheet1.isHidden()) Label label1 = new Label(0, 0, "Header1"); sheet1.addCell(label1); Label label2 = new Label(1, 0, "Header2"); sheet1.addCell(label2); Label valuel = new Label(0, 1, "value1R1C1"); sheet1.addCell(valuel); Label value2 = new Label(1, 1, "value2R1C2"); sheet1.addCell(value2); workbook1.write() workbook1.close() }else{ log.info "file exists open worksheet headers, and update from next rows"; WritableWorkbook book = Workbook.createWorkbook( file, Workbook.getWorkbook(file) ) sheet = book.getSheet( 0 ) newRow = sheet.rows sheet.insertRow( newRow ) def value1 = new Label( 0, newRow, "value1R2C1") sheet.addCell( value1 ) def value2 = new Label( 1, newRow, "value1R2C2") sheet.addCell( value2 ) log.info newRow book.write() book.close() }11 years agoPlace ReadyAPI QuestionsReadyAPI Questions2.2KViews0likes2CommentsData Driven testing Groovy approach
Step-1 create a test case level property "suite_count" step-2 create a groovy step read request "ReadRequest" to read parameterized request. use below code:- import groovy.xml.XmlUtil def xmlParser = new XmlParser() def request = xmlParser.parse("D:/soapui-practice/Request.xml")// configure path of your parameterized(property expension) xml. context.Request = XmlUtil.serialize(request); //pass this ${Request} as a request body of your soap request log.info XmlUtil.serialize(request); step-3 Parse your loaded xml against data set ".xls" file,create first row of headers(used for property expension) and rest rows for testdata values use below code to parse:- import java.io.File; import com.eviware.soapui.support.*; import java.util.*; import jxl.*; import java.lang.*; Workbook workbook = Workbook.getWorkbook(new File("D:/soapui-practice/InputDatasheet.xls")); Sheet sheet = workbook.getSheet("Sheet1"); rowcount = sheet.getRows(); //getting total number of rows colcount = sheet.getColumns(); //getting total number of columns log.info "Rows :"+rowcount+"--Columns:"+ colcount; if(testRunner.testCase.hasProperty( "suite_count" ) && testRunner.testCase.getPropertyValue( "suite_count" ) !="0"){ suite_count = testRunner.testCase.getPropertyValue( "suite_count" ) }else{ testRunner.testCase.setPropertyValue( "suite_count" , "1" ) suite_count = testRunner.testCase.getPropertyValue( "suite_count" ) } suite_count_integer=suite_count.toInteger(); rowcount_integer=rowcount.toInteger(); if(suite_count_integer < (rowcount_integer)) { int count=1; for (tc_col=0; tc_col<colcount; tc_col++) { Cell cell = sheet.getCell(tc_col,suite_count_integer); Cell headers = sheet.getCell(tc_col,0); header = headers.getContents(); value = cell.getContents(); context[header] = value; log.info header+"=="+value; count++; } } else if(suite_count_integer>=rowcount_integer){ log.info "Inside else if condition"; testRunner.gotoStepByName( "Execution Complete"); } Step-4 //After request step loop the data set use below code;- suite_count = testRunner.testCase.getPropertyValue( "suite_count" ) log.info('The counter is : ' + suite_count ); curr_counter = suite_count.toInteger() newcounter = (curr_counter+1); testRunner.testCase.setPropertyValue( 'suite_count', newcounter.toString()); log.info('The new counter is : ' + newcounter ); testRunner.gotoStepByName( "ParseXML"); step-5 //create an "Execution Complete" step to finish the execution log.info "+ve testing completed"; testRunner.testCase.setPropertyValue( 'suite_count', 1.toString());11 years agoPlace ReadyAPI QuestionsReadyAPI Questions3.3KViews0likes3Comments