0

enter image description hereenter image description hereenter image description hereI am trying to get the Property value and Set it with different value in SoapUI's "REST Request Properties" (NOT the custom properties). It just gives me NULL value

Here is what I did:
1. Get test step object
2. get the property value with name of the property => It is giving me null value.

I know I am getting the correct object as I was able to rename the same Test Step name with following code

def restRequest = testRunner.testCase.getTestStepByName("Test");
def a = restRequest.getPropertyValue("Method")

log.info(a) // this gives null

restRequest.setName("Test1") // This works
ktmrocks
  • 361
  • 1
  • 5
  • 18
  • `.getPropertyValue()` reads only the "custom properties". I am not sure if you can get at the metadata. See: https://support.smartbear.com/readyapi/apidocs/soapui/index.html?com/eviware/soapui/model/testsuite/TestStep.html – SiKing Jun 25 '18 at 21:24
  • Are you able to manually modify the same? – Rao Jun 26 '18 at 11:15
  • And which property value are you trying to modify? – Rao Jun 26 '18 at 11:38

1 Answers1

1

In the step object, there is another object called testRequest from which you can get all those required properties.

For example if you want to get all the properties

log.info step.testRequest.metaClass.methods*.name

For example if you want to know the get methods

log.info step.testRequest.metaClass.methods*.name.findAll {it.startsWith('get')}

Similarly you can get the methods to set the value as well.

For instance, you want to modify Pretty Print from true to false:

step.testRequest.setPrettyPrint(false)
log.info step.testRequest.properties['prettyPrint']

Similarly, you can find the required property name, find the right method to modify the value as per your needs.

Rao
  • 20,781
  • 11
  • 57
  • 77
  • Thank you! I was able to get all the get and set methods using your code. I wanted to update the "Resource" property of the "REST Request Properties" for this particular test. – ktmrocks Jun 26 '18 at 16:42
  • You could use appropriate method. Are you able to do? – Rao Jun 26 '18 at 16:49
  • Thank you! I was able to get all the get and set methods using your code. I wanted to update the "Resource" property of the "REST Request Properties" for this particular test. testStep.getResource() // gave me current resource value Now I want to update the resource name just for this specific test case. testStep.setPath("/testing/123"); Is there a way to set the resource of the Test Request Properties for a individual test case. I can update the resource path in different way, but it updates for the entire project which I don't want. – ktmrocks Jun 26 '18 at 17:05
  • I have added the screen shot. – ktmrocks Jun 26 '18 at 17:17
  • The screen shot of rest request step, mark where to update. Sorry for not being clear earlier. – Rao Jun 27 '18 at 03:15
  • I have added the screen shot and circled by red ink for the value where I want to update – ktmrocks Jun 27 '18 at 17:04
  • @ktmrocks, thank you. Would you please add why do you want to update the resource value or what is your use case? By the way, resource is read only, so you can set new value. But if you tell the use case, there can be alternatives. – Rao Jun 28 '18 at 10:57
  • The Resource contains variables which I need to change dynamically during run time. I do not want to add resources for each method in UI and paramertize there. My thinking is it will be much easier, cleaner and easy to maintain if I can change that resource from UI dynamically. I found a way to update the resource by groovy, but it updates the entire project's resource https://stackoverflow.com/questions/49495443/how-to-update-resource-value-in-readyapi-soapui-dynamically-by-groovy – ktmrocks Jun 29 '18 at 15:34
  • Use case with an example helps. – Rao Jun 29 '18 at 15:47
  • Example : Following is my Resource Use case 1 # Endpoint/testapi/electronics/category/order/123 Here I want to change value for electronics and 123 dynamically. – ktmrocks Jun 29 '18 at 17:35
  • 1
    Simple case. Thanks for the example. You Need to use template type parameter in the service definition. And use property expansion in the test cases. And easily have different values. – Rao Jun 29 '18 at 22:44
  • Thank you. I was looking to update the resource with groovy so I have more control over it, but your solution is very helpful as well. – ktmrocks Jul 10 '18 at 03:09
  • Of course, you can use custom property to update the value from groovy script. However, the key is to use template parameter in any case. – Rao Jul 10 '18 at 08:54
  • Got it. Thank you Rao. – ktmrocks Jul 12 '18 at 05:49