Contributions
Re: How to set the value of a test case property from JSON response via Groovy?
{ "status": 200, "code": 2000, "totalCount": 1, "limit": 20, "offset": 0, "data": { "id": 7002, "name": "Test Workspace", "isDisabled": false, "tags": null, "description": "Test Workspace Description", "parsedDescription": { "text": "Test Workspace Description" }, "created": "2019-01-31T18:48:31+0000", "modified": "2019-01-31T18:48:31+0000", "settings": { "logoUrl": null, "setupGuide": { "text": { "intro": null, "settings": null, "forms": null, "members": null, "reports": null } } }, "metadata": { "lastActivity": null, "storageUsed": "0.0000" } } }6.2KViews0likes2CommentsHow to set the value of a test case property from JSON response via Groovy?
I'm using SoapUI open source for REST testing, so I need to do things the hard way via Groovy (no JSON property transfer). I have a test step that places a call to /workspaces, creating a new workspace object and returns an id for said object in the response under data[0].id. I'm using JsonSlurper to parse the response and can easily run asserts on the parsed response. Where I'm having trouble, is figuring out how to set a test case property so that I can pass the id into the endpoint of the next response in the test case, a PUT to /workspaces/{workspace.id}. Here's what I have so far in a Groovy script test step between the two: import groovy.json.JsonSlurper def responseJson = testRunner.testCase.getTestStepByName("Create Workspace").getPropertyValue("response") def slurper = new JsonSlurper().parseText(responseJson) def testCaseProperty = testRunner.testCase.getPropertyValue("workspace_id") testRunner.testCase.setPropertyValue("workspace_id", slurper.data[0].id) This returns the following error message: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer error at line: 7 A little help please?Solved6.3KViews0likes6Comments