Forum Discussion

smartTest's avatar
smartTest
Contributor
13 years ago

Replacement of Namespace Prefixes

Is there any easy way I can turn off the automatic amendment of namespace prefixes in SoapUI Pro? We have to provide examples of tested requests and its not good when they query the change from the approved schemas.

Can this be done? All my messages are having ns and ns1 replacing approved code.

I added the above to the non-Pro forum back in Aug 2011 and got no response, so i thought I would add it in here with more info found today...........

When creating Script Assertions I use the Get Data option and each defined line shows the 'replaced' namespace definitions rather than those in the Schema. However, when a development colleague uses my SoapUI 4.0.1 project the script assertion is failing due to the difference in namespace definitions.

The issue is occuring whilst using code I found on this forum for checking that particular nodes are not empty as below:

//SCRIPT ASSERTION TO ENSURE A NODE IS NOT EMPTY ON RESPONSE
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
holder = groovyUtils.getXmlHolder( messageExchange.responseContentAsXml )
assert holder["//m:getSessionResponse[1]/gen:EDS_GeneralRS[1]/@TransactionIdentifier"] != null


As you can see, no namespaces are defined. I have used this many times in the past and have not come across this issue before. I am basically writing a Script Assertion to ensure that nodes are not empty within the response, but not checking the actual data contained within these nodes. Sometimes I look for single and sometimes multiple nodes in the same script.

Can anyone help?
thanks

5 Replies

  • RJanecek's avatar
    RJanecek
    Regular Contributor
    Hi,

    you can do this assertion without namespace prefixes

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

    assert holderResponse.getNodeValue( "/*[local-name()='elementName' and namespace-uri()='yourNameSpaceUri']") != null


    also in assertion script you can do this easier: def response = context.expand( '${nameOfTestRequest#Response# //*[local-name()="elementName" and namespace-uri()="yourNameSpaceUri"]}' )
    and I am not sure that this can return null so you should also assert:
    assert response != null && !response.isEmpty()
  • Thanks for the update, I'll give that a go.

    I still have the issue however, of a developer seeing completely different namespaces when using the same test project. I create it and link to an external schema, but he is seeing namespaces as defined in the schema, and I am seeing replacements (ns, ns1, etc). Is there a way of turning this off so we are always all seeing the same namespace. Is this a bug? We both have the same properties settings from what i can see.

    thanks again
    Diana
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    You could use:

    holderResponse.namespaces["m"] = "...."


    to define namespace prefix and use it with holder. Namespace prefix should not matter but definition they are pointing should be correct.
    You can not turn off replacing ns, ns1, it is done by design.

    robert
    /Smartbear
  • Robert, thanks for your response.

    Its a shame that this namespace change is done automatically as our developers use my tests to assist with building their Unit and CI tests. Visual Studio does not recognise the namespaces that SoapUI gives, even though the definition is correct, as it is not compliant with the associated schemas.

    Is there a way I can make this into a feature request? It would be useful to have a choice between replacing the namespaces or not.

    thanks
    Diana