cancel
Showing results for 
Search instead for 
Did you mean: 

How to get all the data on my data source using groovy script assertion

SOLVED
Highlighted
Contributor

How to get all the data on my data source using groovy script assertion

From the below code i was able to get the 1st column data from my excel data source file.

	def data = context.expand( '${DataSource#data}')
	log.info data

But there are more data available on my source file.

How am i going to access them using groovy script assertion .

 

Its like get all the data from the above datasource.

1 ACCEPTED SOLUTION

Accepted Solutions
Contributor

Re: How to get all the data on my data source using groovy script assertion

Thanks.

 

I was able to get all the data by using below code.

def fs = new FileInputStream("C:\\Users\\cja\\Documents\\Book1.xlsx")
def wb = new XSSFWorkbook(fs)
def ws = wb.getSheet("data1")
def r = ws.getPhysicalNumberOfRows()

for(def i=0; i<r; i++)
{
def row = ws.getRow(i)
def c = row.getPhysicalNumberOfCells()

for (def j=0;j<c;j++)
{
def cell = row.getCell(j)
log.info cell.getStringCellValue()

}
}

 

3 REPLIES 3
Regular Contributor

Re: How to get all the data on my data source using groovy script assertion

Hi @chathurad,

 

As far as i know, DataSource Step only contains 1 Row Data, if you want to get data Data from each and every row of your excel sheet then you can write your own groovy code.

 

Go through this Post.

 

Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

 

Thanks and Regards,

Himanshu Tayal


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal
Contributor

Re: How to get all the data on my data source using groovy script assertion

Thanks.

 

I was able to get all the data by using below code.

def fs = new FileInputStream("C:\\Users\\cja\\Documents\\Book1.xlsx")
def wb = new XSSFWorkbook(fs)
def ws = wb.getSheet("data1")
def r = ws.getPhysicalNumberOfRows()

for(def i=0; i<r; i++)
{
def row = ws.getRow(i)
def c = row.getPhysicalNumberOfCells()

for (def j=0;j<c;j++)
{
def cell = row.getCell(j)
log.info cell.getStringCellValue()

}
}

 

Regular Contributor

Re: How to get all the data on my data source using groovy script assertion

Hi @chathurad,

 

That's great, can you accept it as solution so that it will help others to find solution.

 

Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

 

Thanks and Regards,

Himanshu Tayal


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal
New Here?
Join us and watch the welcome video:
SmartBear + Cucumber