Forum Discussion

davecoleman's avatar
davecoleman
Contributor
6 years ago
Solved

Groovy assert using Datasource value always returns false when correct

Hi,

we have the following script pulling data from our DataSource excel to validate the response of the Status in the Response.

The actual value is passed out (seen in the Datasink) and the input value is also correct. as per the attached image both values look correct but fails the assertion.

What am I doing wrong?

 
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
//def row = messageExchange.modelItem.testSteps["DataSource"].currentRow
def expectedHTTPResponse = context.expand('${DataSource#code}' )

def ActualHTTPResponse = messageExchange.modelItem.testStep.testCase.testSteps["StepName"].testRequest.response.responseHeaders["#status#"]
//#status# is the name of the header you want to extract
//Read this value into a parameter - writes the header value into the Properties test step
groovyUtils.setPropertyValue("StatusCodeParse", "status",ActualHTTPResponse[0])
//compare the 2 values and if not the same throws an error
assert expectedHTTPResponse == ActualHTTPResponse
 
  • The data isource might be having value as "[HTTP/1.1 200 OK]" which includes the square brackets. is it?

    Then remove them ("[", "]") in the data source.

    Also, use below statement to assert

    assert trim(expectedHTTPResponse) == messageExchange.response.responseHeaders['#status#'][0]

    Or

    //define in source value as 200; say as below this makes life more easier
    def expectedHTTPStatusCode = '200'
    assert expectedHTTPStatusCode == messageExchange.response.responseHeaders['#status#'][0].split(' ')[1]