Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can you assert a null tag in a response?
    primarykey
    data
    text
    <p>I am using a datasource to drive a test step which sends a SOAP request and gets a SOAP response back.</p> <p>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. <code>&lt;message/&gt;</code> instead of <code>&lt;message&gt;&lt;/message&gt;</code>). Whether or not <code>&lt;message/&gt;</code> is any different than <code>&lt;message&gt;&lt;/message&gt;</code> 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 <code>&lt;message/&gt;</code>.</p> <p>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.</p> <p>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).</p> <hr> <h2>Example of functioning test:</h2> <p>I am testing an API which creates an account. So, I feed it in the data to create the account:</p> <pre><code>&lt;username&gt;username&lt;/username&gt; &lt;password&gt;password&lt;/password&gt; </code></pre> <p>From that, I expect the following response:</p> <pre><code>&lt;code&gt;0&lt;/code&gt; &lt;resultMessage&gt;Created successfully!&lt;/resultMessage&gt; </code></pre> <p>My datasource (Excel spreadsheet) has the following information: (first two fields are input, second two are expected results)</p> <blockquote> <p>username, password, 0, Created successfully!</p> </blockquote> <p>So, soapUI compares the appropriate fields, and it works fine.</p> <h2>Example of broken test:</h2> <p>Now, say I want to test what happens when the account isn't created:</p> <pre><code>&lt;username&gt;bad username&lt;/username&gt; &lt;password&gt;bad password&lt;/password&gt; </code></pre> <p>From that, I recieve the following response:</p> <pre><code>&lt;code&gt;-1&lt;/code&gt; &lt;resultMessage/&gt; </code></pre> <p>My datasource (Excel spreadsheet) has the following information: (first two fields are input, second two are expected results, 4th field is <strong>empty</strong>)</p> <blockquote> <p>bad username, bad password, -1, </p> </blockquote> <p>So this time, I have an empty value to compare against <code>&lt;resultMessage/&gt;</code>. Only thing is that it doesn't compare the two empty fields properly.</p> <p>I receive the following error:</p> <pre><code>[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 </code></pre> <p>Be aware that I am new to groovy, new to soapUI, new (and oblivious) to the concept of nodes.</p> <p>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 <code>&lt;resultMessage&gt;</code> with the expected result.</p> <p>I haven't written anything to handle what to do if the expected result <strong>is</strong> empty.</p> <pre><code>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 </code></pre> <p>Being new to nodes and Groovy, I am not sure if I am properly comparing the value in <code>node</code> to the value in <code>expectedResultMessage</code>. Or if there is a proper way to check and compare VS a field which closes itself (ie. <code>&lt;resultmessage/&gt;</code>).</p> <p>I get the following result when running this script:</p> <pre><code>[Assert node [resultMessage]] assert node == resultMessage | | | | | null | "" | false &lt;?xml version ="1.0" encoding="UTF-8"?&gt; &lt;resultMessage xmlns:ns1="http://website.com/Account/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"/&gt; </code></pre> <p>I will probably just have it set up so the response simply returns <code>&lt;resultMessage&gt;&lt;/resultMessage&gt;</code> instead of <code>&lt;resultMessage/&gt;</code>, but I would think there is a way to deal with the latter rather than creating a work-around.</p> <p>Hopefully this wasn't too long-winded, and hopefully it was somewhat clear! Any help would be appreciated! :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload