Forum Discussion

HimanshuTayal's avatar
HimanshuTayal
Community Hero
7 years ago

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

 

  • Olga_T's avatar
    Olga_T
    SmartBear Alumni (Retired)

    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 :smileywink:

     

    • HimanshuTayal's avatar
      HimanshuTayal
      Community Hero

      Hi Olga_T,

       

      Thanks for the appriciation and for the Label too. :smileyhappy:

       

      Regars,

      Himanshu Tayal