Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

SOATEST - How to assert on blank values

Testuser
Testuser Posts: 41

I am using SOATest (9.9) and in my JSON response I am asserting on an element (status) which can have a value or null value. I am trying to assert this against my datasource column 'status'.
I added the below assertions in this case and did the below:
1) Added a Value Assertion for the element 'status' and parameterized it to refer to the data source spreadsheet column.
2) Added another Fixed Value Assertion for the element 'status' and added value as blank and saved it.
3)Added a Conditional assertion and added the Assertion #2 to my "If Assertion" section and then Assertion #1 to "Then Assertion" section and saved it.
When I run the test its ignoring this above assertion and passing my test everytime no matter what I give in the status column in my datacolumn spreadsheet.
Am I doing something wrong here ?

Tagged:

Answers

  • Michael Thomas
    Michael Thomas Posts: 8 admin

    Hi Testuser,

    Does an empty element represent a null value or no element in the response? If no element in the response in the response represents a null value, you want to use Occurrence Assertion. If no value in the element represents a null value, you want to use Has Content Assertion. Please let me know if this helps.

  • Testuser
    Testuser Posts: 41

    In my response the element comes back with no value against it . Something like as below:
    {
    "clientTypeCode": "ORG",
    "status": ""
    }
    I used 'Has Content Assertion' and parameterized it to refer to the data source spreadsheet column 'status' and after running it gives me an error as below:

    Has Content Assertion../status could not be located or did not contain text content.

    This is the error I was getting when I was using value Assertion too.

  • jakubiak
    jakubiak Posts: 795 admin

    Hmm that's strange. I'm able to use the Has Content Assertion parameterized against a column that has the values true or false, and it does what I expect.

  • Michael Thomas
    Michael Thomas Posts: 8 admin

    Hi Testuser,

    What is your build id and full version?
    To get version and build id:

  • Testuser
    Testuser Posts: 41

    Build id # 2016-06-01-2046
    Version : 9.9.5.20160601

  • Testuser
    Testuser Posts: 41

    Hi jakubiak,
    My datasource column 'status' has a valid (non null) value for first row/ scenario.
    For the second row/scenation the column has blank value. This is where SOATEST is failing with "Has Content Assertion../status could not be located or did not contain text content."

  • Testuser
    Testuser Posts: 41

    Just to clarify I am getting the error "Has Content Assertion../status could not be located or did not contain text content." whenever the response looks like this:
    {
    "clientTypeCode": "ORG",
    "status": ""
    }
    Whenever the response has a valid value for 'status' element like as below,then my assertion is not an issue.:
    {
    "clientTypeCode": "ORG",
    "status": "PEND"
    }
    I want to know which assertion to use to assert for blank/null values in the response .

  • Testuser
    Testuser Posts: 41

    Does anyone has any update on my question? Appreciate your help!

  • Ireneusz Szmigiel
    Ireneusz Szmigiel Posts: 227 ✭✭✭
    edited March 2017

    Hi Testuser,

    could you post your Xpath from JSON Assertor?
    I have tested it with Parasoft Virtualize and SOAtest and I see expected behavior with your example:

        {
        "clientTypeCode": "ORG",
        "status": ""
        }
    

    gives me:
    Has Content Assertion: Element "../status" was expected to have content

    Could you also publish your tst file?
    Just attach it to this thread.

  • Testuser
    Testuser Posts: 41

    Hi Ireneusz,
    My scenario is I am expecting blank value for 'status' element for one of my scenario and I expect my test not to fail if it returns blank value and how do I handle through assertion? So I am asserting my 'status' element in the response against 'status' column in my datasource sheet and this datasource sheet has 2 rows/scenarios. For the first scenario, 'status' (expected value for 'status element) column has a value 'PEND' and when SOATest runs this scenario then the test passes as the 'status' element comes back with 'PEND" value . For the second scenario,'status' column has no value in the datasource sheet and when SOATest runs this scenario then the test fails saying '"Has Content Assertion../status did not contain text content." because the response had blank value for 'status' element. How can I have an assertion against an element which will work for both null/blank and non blank values ?

  • Ireneusz Szmigiel
    Ireneusz Szmigiel Posts: 227 ✭✭✭
    edited March 2017

    Could you check if following assertion works for one of your cases?

    Do not parametrize it at the beginning.
    Has Content assertion expects to get true or false, so in your data source you have to add column which contains true or false for particular case, and then parametrize it in JSON Assertor.

  • Testuser
    Testuser Posts: 41

    I tried it so , now it shows the below error for both the scenarios
    DataSource: Models (row 1): Has Content Assertion1: Element "../status" was expected to be empty
    DataSource: Models (row 2): Has Content Assertion1: Element "../status" was expected to be empty

    My response was as below for row 1 and row 2 respectively:
    Response for row1:
    {"clientTypeCode":"IP","status":"PEND"}
    Response for row2:
    {"clientTypeCode":"ORG","status":""}

  • Ireneusz Szmigiel
    Ireneusz Szmigiel Posts: 227 ✭✭✭

    If you want to create assertion to check content and also validate the content itself, you have to add Compound Assertion.
    i.e. check if status is not empty AND you have expected string/value

  • Testuser
    Testuser Posts: 41

    Well this compound assertion will work for my my first scenario where my element has a non blank value but it will fail for the second scenario where my element doesn't have a content/ or comes back blank.

  • Ireneusz Szmigiel
    Ireneusz Szmigiel Posts: 227 ✭✭✭

    Then use Conditional Assertion.

  • Testuser
    Testuser Posts: 41

    I used Conditional Assertion in the first place. Below are the steps I followed (am copy pasting the steps from my initial question in this thread):
    1) Added a Value Assertion for the element 'status' and parameterized it to refer to the data source spreadsheet column.
    2) Added another Fixed Value Assertion for the element 'status' and added value as blank and saved it.
    3)Added a Conditional assertion and added the Assertion #2 to my "If Assertion" section and then Assertion #1 to "Then Assertion" section and saved it.
    When I run the test its ignoring this above assertion and passing my test everytime no matter what I give in the status column in my datacolumn spreadsheet.

  • Ireneusz Szmigiel
    Ireneusz Szmigiel Posts: 227 ✭✭✭
    edited March 2017

    But I think you have to check Has Content assertion in IF then check the value.
    Has Content should be set with data source as true or false.
    The column which you want to use in parametrization in Has Content should contain true/false.
    Could you please attach your tst in this thread?

  • Testuser
    Testuser Posts: 41

    Conditional assertion doesn't work for me as its simply ignoring the Then and is always passing my test, which is what I have said in my intial question. :(

  • Testuser
    Testuser Posts: 41

    I think its a bug with Conditional Assertion in SOATEST where its passing the assertion always without looking at the Set if and Then Clause.

  • Ireneusz Szmigiel
    Ireneusz Szmigiel Posts: 227 ✭✭✭
    edited March 2017

    According to documentation

    Conditional Assertion: Enforce an assertion only if a condition is met (where
    the condition is a combination of previously-defined assertions).

    I have simple test with JSON Assertor:



    and used data source

    Works as expected.

    See attached tst ( unzip it first and then import into SOAtest v9.9.5)

  • Testuser
    Testuser Posts: 41

    Thanks Ireneusz. I had already tried this approach but the problem here is , its not actually asserting for non blank values properly. So in your example, for the value of test column 'My' if response has 'xyz' then also my test is passing , which shouldn't be the case. I agree Conditional assertion is taking care of not failing when its coming across blank values for 'status' in the response but at the same time its not truely asserting on the right value . For ex: if you change value of 'test' column for row#1 to '123444' and then run the test it will still pass. I hope am not confusing you.

  • OmarR
    OmarR Posts: 233 admin

    Hellooo Testuser,

    It would extremely helpful if you could provide a sample .tst file to demonstrate where your current hurdle lies. Please attach a sample .tst file so that we can reproduce the behavior and give you some additional insight. Save the traffic in the traffic viewer!
    :p

  • Ireneusz Szmigiel
    Ireneusz Szmigiel Posts: 227 ✭✭✭

    Hi Testuser,

    I have changed row#1 and have expected result:
    DataSource: Values (row 1): Conditional Assertion: For element "../status", actual value: My,
    should equal expected value: 123444 with case sensitivity enforced

    As OmaR said, please share tst and we will help you with your case.

  • Testuser
    Testuser Posts: 41

    I have posted my comment but it says it will appear after its approved. Dont know what does that mean :(

  • Testuser
    Testuser Posts: 41

    Attaching the tst file

  • Testuser
    Testuser Posts: 41
    edited March 2017

    The only reason I was hesitant to share the tst file was because I had framed the scenario/question in simplistic way than what actually the real tst file is doing.
    Anyways I've attached the sample tst file and the excel sheet which its using in the Data source .
    Also in my tst file, I am trying to assert on 'statusCode' element(referred to Status in the earlier contexts) for different values of 'ExpectedIPList' column(maps to 'name' element in the response) .Also I have Status column as suggested by you which has 'true' value.
    Just to make it clear In my Data sheet my row#1 has 'ExpectedStatus' column value as '123' and in the response its coming back as 'PEND' as below but still it passes:
    Response looks like as below:
    {"clientTypeCode":"IP","statusCode":"PEND","statusName":"Pending Approval","id":0,"name":"Auto_OZ_IP"}.
    For row#2, 'ExpectedStatus' column value as '' value and in the response 'statusCode' is coming back as '' as below and response looks like as below:
    {"clientTypeCode":"IP","statusCode":"","statusName":"","id":241,"name":"Auto_CES_IP","displayName":"Auto_CES_IP","description":"Auto_CES_IP","typeCode":"PRED","typeName":"Predictive"}
    Hope this helps to understand my problem better.

  • Testuser
    Testuser Posts: 41

    Sorry about the multiple posts with the same thing :(. I was getting approval messages when I was submitting my initial post and submitted multiple times without knowing it did submit multiple times. Please excuse me

  • Thomas Moore
    Thomas Moore Posts: 82 admin

    Hi Testuser,

    No problem :) I approved the original post, but when I saw that you added in the stuff in two separate posts, I deleted the original. No harm done!

  • Ireneusz Szmigiel
    Ireneusz Szmigiel Posts: 227 ✭✭✭
    edited March 2017

    Hi Testuser,
    I have attached slightly changed tst.
    I have changed xpath used to extract values from response.
    It works in my environment as I'm using column requestUrl to iterate over your datasource.
    I think that we have misunderstanding in this case as I think you expecting to use assertion with parametrization for any request ( let's say without order).
    In my example I expecting that when I execute test I will get two requests with response order like this:
    1.Response
    {"clientTypeCode":"IP","statusCode":"PEND","statusName":"Pending Approval","id":0,"name":"Auto_OZ_IP"}
    2.Response
    {"clientTypeCode":"IP","statusCode":"","statusName":"","id":241,"name":"Auto_CES_IP","displayName":"Auto_CES_IP","description":"Auto_CES_IP","typeCode":"PRED","typeName":"Predictive"}

  • Testuser
    Testuser Posts: 41

    So the only change you did in your attached zip file was to change the xpath query. I followed the same and did that change to remove parameterization from my Xpath (like you did ) and then ran and still it passed instead of failing for ExpectedStatus value as '123'. Also I anyways have to use parameterization to assert for the statusCode for a particular ExpectedIPList column value. I am not sure where am going wrong.

  • Ireneusz Szmigiel
    Ireneusz Szmigiel Posts: 227 ✭✭✭

    In Traffic Viewer you should have a response from server with JSON for both request.
    Compare that responses with Xpath.
    I have examples working. If you have valid service contract ask for help on support@parasoft.com

  • Testuser
    Testuser Posts: 41

    Thanks, I created a case # 00061565 in the support site.

  • Ramiro Martinez
    Ramiro Martinez Posts: 53 admin
    edited March 2017

    Hi guys,

    Please make sure that the XPath for "has content" assertions point to an element and not to the value of the element.
    Example:

    XPath:/root/a[1]/text()
    Would return 123
    while
    Xpath:/root/a[1]
    Would return the entire element "a"
    Has Content assertion expects an element not a value.

  • dlab
    dlab Posts: 1

    Did you got a proper response to your problem? I am trying to do the same.

    How can we assert against a datasource blank value and make sure the response has a blank value?

    The provided solution only assert a value if it is not blank but does not confirm that that expected value is blank.

  • dgoedh
    dgoedh Posts: 63

    Hi, I wonder if the problem in this discussion thread has already been solved in SOAtest 9.10.x, since I am currently validating a CSV file, which also contains some empty elements. I get the following error when an empty value is encountered:
    Error Message:
    DataSource: CSV Datasource (row 17): Has Content Assertion Value 13: Element "../value[13]" couldnot be located or did not contain text content

    Additional Details:
    Element "../value[13]" could not be located or did not contain text content,

    Thus even with the "Has Content Assertion" expected outcome set to 'false'.

    I also tried to create a custom assertion, to skip empty fields, but that does not work either yet.

    Any suggestions?

    Thanks in advance.

    Regards,

    Daniel

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited August 2019

    In the next release, default xpaths generated from the UI are now appended with /string() instead of /text() when creating Value Assertions, String Comparison Assertions and Regular Expression Assertions, so that empty string values would be supported out of the box. The Assertor tools were also updated to handle XPaths that return a string and not a Node. When the XPath ends with "text()" the XPath will fail to match anything if the element does not have a text node (an empty element). In contrast, the string() function will return an empty string in that case.

    In the current release, you could consider manually adjusting XPaths used in extractions to use the string() function. Using string() function in Assertor tools won't work until next release.

Tagged