0
votes

I am new to SoapUI tool. I am using SoapUI version 5.3.0 My Application have a couple of RESTful APIs. I am sending multiple request to a WebService in the form of a json request as below:

{
   "app_key":"i8gAVDwcAq40n2kAv6Ox+w==",
   "targetDB":"${#TestCase#TARGET_DB}",
   "createNew": "true"
}

The response from the WebService is as follows:

<StartDataExtractResult xmlns="http://schemas.datacontract.org/2004/07/AriaTechCore" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
   <StatusCode>1</StatusCode>
   <StatusText>success</StatusText>
   <RequestNumber>101</RequestNumber>
</StartDataExtractResult>

I am using a Groovy Script to generate a dynamic name for "targetDB" as follows:

def targetdb = ((context.expand('${#TestCase#TARGET_DB}') ?: 100) as Integer) + 1
log.info "Target db for current request : ${targetdb}"
context.testCase.setPropertyValue('TARGET_DB', targetdb.toString())

I have designed my Test data in such a way that passing the name of the 'targetdb' as "101" in the Request will result in creating 101 tag in the response. The Load Test is executing fine.

Now I want to add some assertions to each of the Load Test Responses to check if the StatusCode tag contains "1", StatusText tag contains "success" & RequestNumber tag contains the value of the variable "${#TestCase#TARGET_DB}" (sent in Request json) . To achieve that I wrote a Script Assertion as follows:

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(messageExchange.responseContent)
holder.namespaces["ns1"] = "http://schemas.datacontract.org/2004/07/AriaTechCore"

def nodeStatusCode = holder.getNodeValue("//ns1:StatusCode")
assert nodeStatusCode != null
if(nodeStatusCode=="1")
{ log.info "Pass" }
else
{ log.info "Fail"}

def nodeStatusText = holder.getNodeValue("//ns1:StatusText")
assert nodeStatusText != null
if(nodeStatusText=="success")
{ log.info "Pass" }
else
{ log.info "Fail"}

def nodeRequestNumber = holder.getNodeValue("//ns1:RequestNumber")
assert nodeRequestNumber != null
if(nodeRequestNumber=="${TARGET_DB}")
{ log.info "Pass" }
else
{ log.info "Fail"}

But I am getting an error as:

No such Property: TARGET_DB for class: Script 53

Can anyone help me out please?

Here is the screenshot of my project: Assertion

1
not clear what the question is ? Have you added the mentioned assertions, and not working? or you do not aware how to add them? Please clarify. - Rao
I want to create assertions for each of the 10 Request/Response from the WebService (which is being generated by the Load Test Suite) to validate if StatusCode is "1", StatusText is "success" & match the value "101". I have added assertions for single Request/Response. But now I want to do it for all the Request/Response. - DebanjanB
Well, you can put the mentioned assertions for request step (which is 2nd one in your case). When you run the load test, those will be run each time, so that you do not have to do later. - Rao
@Rao Sir I had been trying to create these types of Assertions in the Load Test Suite since yesterday but unable to find a clue. All I can find is the Load Test specific Assertions like 'Max Errors', 'Step Average', 'Step TPS', 'Step Maximum' & 'Step Status'. Does that essentially means that the Functional Test Assertions cannot be implemented in Load Test suite? - DebanjanB
As I said you have to add those assertions for 2nd step. Not at load test level. - Rao

1 Answers

0
votes

I have got an answer for this query from another forum. Here is the answer to the question:

  1. We need to create a Step as Properties and add a property to that as "databaseName"
  2. We need to add another Groovy Script for the Property as follows:

    String testString = '${#TestCase#TARGET_DB}'

    testRunner.testCase.setPropertyValue( "databaseName", testString )

    def getLocalPropValue = testRunner.testCase.getPropertyValue("databaseName")

    log.info(getLocalPropValue)

    testRunner.testCase.testSteps["Properties"].setPropertyValue( "databaseName", testString )

  3. Finally we can have the Script Assertion as follows:

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

    def holder = groovyUtils.getXmlHolder(messageExchange.responseContent)

    holder.namespaces["ns1"] = "http://schemas.datacontract.org/2004/07/AriaTechCore"

    def nodeStatusCode = holder.getNodeValue("//ns1:StatusCode")

    assert nodeStatusCode != null

    if(nodeStatusCode=="1")

    { log.info "Pass" }

    else { log.info "Fail"}

    def nodeStatusText = holder.getNodeValue("//ns1:StatusText")

    assert nodeStatusText != null

    if(nodeStatusText=="success") { log.info "Pass" }

    else

    { log.info "Fail"}

    def nodeRequestNumber = holder.getNodeValue("//ns1:RequestNumber")

    assert nodeRequestNumber != null

    if (nodeRequestNumber == context.expand('${#TestCase#TARGET_DB}'))

    { log.info "Pass" }

    else

    { log.info "Fail"}

@Rao thanks a lot for your valuable suggestions & comments.