cancel
Showing results for 
Search instead for 
Did you mean: 

compare property names with data in excel file

SOLVED
Highlighted
Contributor

compare property names with data in excel file

Hi,

 

I want to get the property name from properties at test step level. I have an excel which has 1st column as property names and 2nd value as property value. The property name which I get from soapui needs to be compared with the property names present in the 1st column of excel and get the corresponding value and assign it to the value of property in soapui.

 

Please help me with this

3 ACCEPTED SOLUTIONS

Accepted Solutions
Super Contributor

Re: compare property names with data in excel file

Then you can get the list of properties present inside the Properties TestStep and then compare :-

def testStep = testRunner.testCase.testSteps["Properties"]
if (testStep.getPropertyCount() > 0){
 for (prop in testStep.getPropertyList()){
  log.info(prop.getName() +" "+ prop.getValue())
 }
}

View solution in original post

Highlighted
Contributor

Re: compare property names with data in excel file

Hi,

 

Thank you. It helped me to get the properties.

View solution in original post

Highlighted
Super Contributor

Re: compare property names with data in excel file

Ok, you are getting error at line 20. Actually setPropertyValue("", Val) always accepts String. Try to store prop.getName to a String value and then pass there. Like this - 

 

def testStep = testRunner.testCase.testSteps["Properties"]
if (testStep.getPropertyCount() > 0){
for (prop in testStep.getPropertyList()){
for(int i=0;i<size;i++){
Cell f=sheet1.getCell(0,i)
field=f.getContents()
Cell f1=sheet1.getCell(1,i)
value=f1.getContents()
String propName = prop.getName()
log.info propName
if(prop.getName()==field){
testRunner.testCase.testSteps["Properties"].setPropertyValue(propName, value)
}
else{
log.info "Not Found"
}
}
}
}

View solution in original post

16 REPLIES 16
Highlighted
Super Contributor

Re: compare property names with data in excel file

First, get the properties value from test Steps using this code :-

 

def code = testRunner.testCase.testSteps['Properties'].getPropertyValue("Code")

Where, Code is the property name in Properties Step.

And after that, Use DataSource expansion code

def code = context.expand( '${DataSource#Code}' )

Where, code is the column in Excel.

 

And, if you are not using paid version of soapui, then you need to write excel connection code using java/groovy and fetch the particular row and column value and then do assert logic.

And, finally,  do assertEquals logic,

Highlighted
Contributor

Re: compare property names with data in excel file

Hi,

Thanks for the response.

What I am trying to acheive is , suppose my properties step has 4 properties named a,b,c,d. I want to get the names of those properties and serach for their values which are already present in an excel file.

 

Appreciate your help in advance.

Super Contributor

Re: compare property names with data in excel file

Then you can get the list of properties present inside the Properties TestStep and then compare :-

def testStep = testRunner.testCase.testSteps["Properties"]
if (testStep.getPropertyCount() > 0){
 for (prop in testStep.getPropertyList()){
  log.info(prop.getName() +" "+ prop.getValue())
 }
}

View solution in original post

Highlighted
Contributor

Re: compare property names with data in excel file

Hi,

 

Thank you. It helped me to get the properties.

View solution in original post

Highlighted
Super Contributor

Re: compare property names with data in excel file

If it really helped you.. Don't forget to accept as solution. so, that other members will get benefitted.

Highlighted
Super Contributor

Re: compare property names with data in excel file

Please accept the solution.. that worked for you. Not the reply.

Highlighted
Contributor

Re: compare property names with data in excel file

Hi,

 

Could you please also help me with searching for a word in an excel and get the position of the word if located.

Appreciate your help in advance

Highlighted
Super Contributor

Re: compare property names with data in excel file

This is quite simple. You can follow this link and there are many solution on internet. Go through that :-

 

https://stackoverflow.com/questions/9049995/java-poi-how-to-find-an-excel-cell-with-a-string-value-a...

Highlighted
Contributor

Re: compare property names with data in excel file

Hi,

 

I'm looking for the solution in groovy script. Trying to automate my test cases. Below is the code which I wrote.

This code checks if the property is present in the excel it takes the value which is present on the right side of the location obtained. I'm not a developer. Please bear with me if there are any blunders.

import com.eviware.soapui.support.XmlHolder
import jxl.*
import jxl.write.*
import org.apache.poi.hssf.usermodel.*
def myTestCase = context.testCase
def counter,next,previous,size
Workbook workbook1 = Workbook.getWorkbook(new File("C://eprimo/TestData/input.xls"))
Sheet sheet1 = workbook1.getSheet(0)
size= sheet1.getRows().toInteger()
def testStep = testRunner.testCase.testSteps["Properties"]
if (testStep.getPropertyCount() > 0){
for (prop in testStep.getPropertyList()){
for(int i=0;i<size;i++){
Cell f=sheet1.getCell(0,i)
field=f.getContents()
Cell f1=sheet1.getCell(1,i)
value=f1.getContents()
log.info(prop.getName())
if(prop.getName()==field){
prop.setPropertyValue(prop.getName(), value)
}
else{
log.info "Not Found"
}
}
}
}

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