How can I properly assert a field that has a value sometimes, other times not?
===

I am using a datasource to drive a test step which sends a SOAP request and gets a SOAP response back.

When I am validating the response, sometimes I expect one of the fields to be have a value (string), other times I expect it to not be initialized to a value (ie. `<message/>` instead of `<message></message>`). Whether or not `<message/>` is any different than `<message></message>` when comparing VS and empty field in Excel (my datasource), I honestly do not know. All I know is that soapUI doesn't like comparing an empty Excel field to `<message/>`.

I want to set up an assertion which is intelligent enough to be able to assert both cases. If I expect an empty result, it will assert that the field should be empty. If I expect a string, it will assert that the string is there.

The default functionality in soapUI Pro does not seem to work when it compares an empty expected result (read in from an Excel spreadsheet) with an empty field (or rather, a field which has no value whatsoever).

---

Example of functioning test:
----------------------------
I am testing an API which creates an account. So, I feed it in the data to create the account:

    <username>username</username>
    <password>password</password>

From that, I expect the following response:

    <code>0</code>
    <resultMessage>Created successfully!</resultMessage>

My datasource (Excel spreadsheet) has the following information: (first two fields are input, second two are expected results)

>username, password, 0, Created successfully!

So, soapUI compares the appropriate fields, and it works fine.

Example of broken test:
-----------------------
Now, say I want to test what happens when the account isn't created:

    <username>bad username</username>
    <password>bad password</password>

From that, I recieve the following response:

    <code>-1</code>
    <resultMessage/>

My datasource (Excel spreadsheet) has the following information: (first two fields are input, second two are expected results, 4th field is **empty**)

>bad username, bad password, -1, 

So this time, I have an empty value to compare against `<resultMessage/>`. Only thing is that it doesn't compare the two empty fields properly.

I receive the following error:

    [Match content of [resultMessage]] XPathContains assertion failed for path [declare namespace ns1='http://website.com/Account/'; //ns1:CreateAccountResponse[1]/resultMessage[1]/text()] : Exception:Missing content for xpath[declare namespace ns1='http://website.com/Account/'; //ns1:CreateAccountResponse[1]/resultMessage[1]/text)()] in Response

Be aware that I am new to groovy, new to soapUI, new (and oblivious) to the concept of nodes.

I figured I would write a script to resolve my problem. The script would check to make sure the expected result is not empty, and then compare `<resultMessage>` with the expected result.

I haven't written anything to handle what to do if the expected result **is** empty.

    import com.eviware.soapui.support.XmlHolder

    def holder = new XmlHolder( messageExchange.responseContentAsXml )
    holder.namespaces["ns1"] = "http://website.com/Account/"
    def node = holder.getDomNode( "//ns1:CreateAccountResponse[1]/resultMessage[1]" )
    def expectedResultMessage = context.expand( '${CreateAccount DataSource#resultMessage}' )

    if (expectedResultMessage != null)
	 assert node == expectedResultMessage

Being new to nodes and Groovy, I am not sure if I am properly comparing the value in `node` to the value in `expectedResultMessage`. Or if there is a proper way to check and compare VS a field which closes itself (ie. `<resultmessage/>`).

I get the following result when running this script:

    [Assert node [resultMessage]] assert node == resultMessage |  |    | |    | null   | ""  |  false <?xml version ="1.0" encoding="UTF-8"?> <resultMessage xmlns:ns1="http://website.com/Account/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"/>

I will probably just have it set up so the response simply returns `<resultMessage></resultMessage>` instead of `<resultMessage/>`, but I would think there is a way to deal with the latter rather than creating a work-around.

Hopefully this wasn't too long-winded, and hopefully it was somewhat clear! Any help would be appreciated! :)