cancel
Showing results for 
Search instead for 
Did you mean: 

Script challenge for Groovy DataSource - API Summer 2018

Highlighted
Community Leader

Script challenge for Groovy DataSource - API Summer 2018

Hi @Olga_T

 

I have developed a code for Groovy DataSource, hope this will meets the need of Question.

 

import jxl.*

def groovyUtils1 = new com.eviware.soapui.support.GroovyUtils(context)
def projectPath = groovyUtils1.projectPath
projectPath = projectPath.replace("\\","/")
def dataFile = projectPath + "/DataFile.xls"

def f = new File(dataFile)
def wk = Workbook.getWorkbook(f)
def s1 = wk.getSheet(0)
def rows = s1.getRows()
def cols = s1.getColumns()
def flag = 0
for(def i=1;i<rows;i++)
{	
	for(def j=0;j<cols;j++)
	{
		//For placing null
		for(def k = 0; k < 5; k++)
		{
			//Get Header Row Column Cell
			def c1 = s1.getCell(k, 0)
			//Get Value Row Column Cell
			def c2 = s1.getCell(k, i)
			testRunner.testCase.getTestStepByName("Properties").setPropertyValue(c1.getContents().toString(), "null")
		}
		//for placing value in front on particular iteration
		if(flag == j)
		{
			def c3 = s1.getCell(j, 0)
			def c4 = s1.getCell(j, 1)			
			testRunner.testCase.getTestStepByName("Properties").setPropertyValue(c3.getContents().toString(),c4.getContents().toString())
		}
		flag = flag + 1
	}
	testRunner.testCase.getTestStepByName("Properties").setPropertyValue("Counter",i.toString())	
}

Do Like and Accept if you find it as Solution.

 

Thanks,

Himanshu Tayal

 


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



Thanks and Regards,
Himanshu Tayal
Tags (1)
2 REPLIES 2
Highlighted
Moderator

Re: Script challenge for Groovy DataSource - API Summer 2018

Good job, @HimanshuTayal! Thanks for sharing your script.

 

I have split it into a new topic so that others can easily find it, and I have also added the TechCorner label to it, so this topic gives you now 2 points to your score in  API Summer 2018 Smiley Wink

 


Olga Terentieva
SmartBear Assistant Community Manager

Highlighted
Community Leader

Re: Script challenge for Groovy DataSource - API Summer 2018

Hi @Olga_T,

 

Thanks for the appriciation and for the Label too. Smiley Happy

 

Regars,

Himanshu Tayal


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



Thanks and Regards,
Himanshu Tayal
New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Compete with community members in the TechCorner Challenge and get into the Leaderboard!

Rank Participant Points Earned
1 msiadak 12
2 nmrao 8
3 HimanshuTayal 3
Top Kudoed Authors