Ask a Question

How to feed data from an excel to an array?

ChethanMS
Not applicable

How to feed data from an excel to an array?

Hi,

Can anyone please let me know how can I pass values to an array?
I have a requirement where a set of values occur more than once. The number of times the set occur differs for each request. Please help me to automate this scenario.

Thanks,
Chethan
6 REPLIES 6
JKambli
Staff

Hi,

You can add a DataSource test step, add excel file as DataSource and add a groovy script test step, add a loop.
So lets assume that you have a DataSource property "number" which you want to add in array. Create a test case property "main_array".

DataSource
Groovy Script test step
Data Source loop (DataSource > Groovy Script test step)

In the groovy script test step add,

if( context["array"] == null ) context["array"] = []

context["array"] << context.expand( '${DataSource#Number}' )

//log.info context["array"]
// Set the array in testcase property named main array
testRunner.testCase.setPropertyValue( "main_array", context["array"])



This should work!

Thanks,
Jeshtha

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Gareth
New Contributor

Hi,

 

I have the same problem but the solution proposed does not work.

 

I get this error when running the Groovy script:

 

groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.WsdlTestCasePro.setPropertyValue() is applicable for argument types: (java.lang.String, java.util.ArrayList) values: [modelOptions, [W5]] Possible solutions: setPropertyValue(java.lang.String, java.lang.String), getPropertyValue(java.lang.String) error at line: 7

 

It seems the code is attempting to set a property with an array (java.util.ArrayList) but the method only works setting a string (java.lang.String). I have searched the forums for a solution to this i.e. setting a property with an array - but have not found it.

 

Can you please advise how to take a list of values (e.g. in Excel) and then convert that to an array (JSON in this case) to set in a Request.

Convert the array to string since testCase properties can only save strings, you can reconvert it to array when you wish to reuse it.

 

Thanks


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Gareth
New Contributor

Thanks for your response - however can you please provide a specific example of how to do this?

 

I have a REST service with a JSON payload. Whenever I refer to the Property, it formats its as a String rather than an Array.

 

i.e. I need this:                                   modelOptions: ["A3", "B2", "C5"]

 

but what I always get is this              modelOptions: "["A3", "B2", "C5"]"

 

...which is invalid JSON syntax.

 

I have also tried returning the "result" of the Groovy script directly rather than using a Property. I return an array, however, this is still converted to a String as above.

 

So, can you please provide some specific step by step approach to set a JSON array programatically (based on Excel data or any data source). Asserting that something can be done is not sufficient for someone asking how it can be done.

 

Thanks.

I also got the same error. It seems like old post. Any one have solution for this?

 

groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.WsdlTestCasePro.setPropertyValue() is applicable for argument types: (java.lang.String, java.util.ArrayList) values: [cbiIds, []] Possible solutions: setPropertyValue(java.lang.String, java.lang.String), getPropertyValue(java.lang.String) error at line: 7

Hi @Rama16 ,

 

You are replying on a very old post can you please submit new topic and also attach a snipet of your code where you are getting error.

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
cancel
Showing results for 
Search instead for 
Did you mean: