Taz's avatar
2 years ago
New Idea

Make Smart Assertion more useful with added features

Smart Assertions are very useful when having lots of data that need to be asserted.  However currently there are a few issues that make it more difficult then it needs to be: 


1. No Search Facility that allows quickly to jump to an item. 

2. No conditional flow where assertions can be managed depending on some response details.

3. No facility to deal with lists that are unsorted and can be in a different order each time.

4. No facility to convert the Smart Assertions to Groovy Script which would make it useful as a tool to get a basic script with all the assertions that can be further edited to deal with special cases.


Our responses contain hundreds of pieces of data that need to be evaluated. The Smart Assertions are great for quickly generating the assertions of a response but since we have many lists which don't arrive in a specific order, this does not work very well for us.  If the Smart Assertions could recognise lists and pre-order them before assertion this would solve this problem and save us a lot of time.  


We also have an issue with repeated properties like for example version numbers that we only want to change once and then have it used in many places.  However using a property only works as long as the data doesn't change.  When data changes and we have to make a "Load from Transaction" again, those properties have to be added again.  It would be nice to have something like an "Update from Transaction" that notices changes but doesn't overwrite existing items that haven't changed and preserves the properties being used.  A differential dialog might be useful here when updating where we can see the changes, modify them if necessary or have them applied.


Another great feature would be a conversion from Smart Asserts to Script.  Other test applications that we use for desktop applications already can do this and it would be nice if SmartAPI also would be able to generate a script from the Assertions.  This would help with situations where we need to have lots of special flows , loops and transformations of data but don't want to always have to write each assert from scratch.  




  • shyne's avatar
    Occasional Contributor

    Heartily agree! Smart Assertions are cool and I want to like them but not advanced enough and need improving.

    Maybe if there was an export and import would make it easier to edit the valid values (e.g. find and replace Property Expansions)?


    Here are some the Groovy script work arounds we use, if of any use?


    //Assert Date comparison
    expectedDateString = "2023-01-16T18:43:34.3210487"
    returnedDateString = "16/01/2023"
    expectedDate = Date.parse("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS", expectedDateString)
    returnedDate = new Date().parse("dd/MM/yyyy", returnedDateString)
    assert expectedDate > returnedDate
    assert expectedDate < returnedDate.plus(365)

    //Assert Mapping comparison
    expectedMapValue = "Hazel"
    returnedMapValue = "Ha"
    def genderMap = [
    assert genderMap.get(expectedMapValue) == returnedMapValue

    //Assert RegEx comparison
    expectedRegExValue = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+[.][a-zA-Z]{2,}\$"
    returnedRegExValue = "no-reply@abc.co.uk"
    assert returnedRegExValue =~ expectedRegExValue

    //Assert conditional comparison
    expectedValue = "123"
    dependantValue = true
    if (dependantValue == true) {
    assert expectedValue == "123"
    } else {
    assert expectedValue == "ABC"

    //Assert Contains
    expectedListValues = ["animal", "vegetable", "mineral"]
    returnedListValue = "animal"
    assert expectedListValues.contains(returnedListValue)

    //Out of order simple array
    expectedArray = ['FET','SOL']
    returnedArray = ['SOL','FET']
    returnedArraySorted = returnedArray.sort()
    assert expectedArray == returnedArraySorted

    //Out of order object array
    import groovy.json.*
    returnedObjArrayString = """
    "user_identifier" : [
    "value" : "10000571",
    "id_type" : {
    "value" : "BARCODE",
    "value" : "atzejr-dnkuifa",
    "id_type" : {
    "value" : "OTHER_ID_1",
    returnedObjArray = new JsonSlurper().setType(JsonParserType.LAX).parseText(returnedObjArrayString)
    //directAccessAValue = returnedObjArray.user_identifier[0].value
    for (row in returnedObjArray.user_identifier) {
    if (row.id_type.value == "BARCODE") {
    assert row.value == "10000571"
    if (row.id_type.value == "OTHER_ID_1") {
    assert row.value == "atzejr-dnkuifa"


    We also have a Groovy script that's a for-loop in a for-loop, for when we can auto match the sent JSON to the returned JSON and assert the values.

  • nastester's avatar
    Regular Contributor

    Came here to open a feature request for this. 

    I wish there was a way to filter on fields in a Smart Assertion you have 'active' instead of scrolling which is quite tedious.