Search code examples
groovyautomated-testsassertionkatalon-studiodata-driven-tests

Katalon Posibble to assert response = data?


I store json test data in excel file. Make use of apache POI to read the json data and parse it as request body, call it from katalon.

Then I write many lines of assertion (groovy assert) to verify each line response = test data.

Example: Assert test.responseText.fieldA == 'abc' Assert test.responseText.fieldB == 'xyz' And so on if I have total of 20 fields.

I'm thinking of there is better way to make use of the json data stored in data file. To assert the response = test data. So I can save alot of time to key in each line and modify them is the test data changed.

Please advise if this can be achieved?


Solution

  • Here is an example: you have two excel sheets - current values and expected values (values you are testing against).

    Current values:

    No. | key | value
    ----+-----+------
    1     a     100
    2     b     6
    3     c     13
    

    Expected values:

    No. | key | value
    ----+-----+------
    1     a     100
    2     b     6
    3     c     14
    

    You need to add those to Data Files:

    enter image description here

    The following code will compare the values in the for loop and the assertion will fail on the third run (13!=14):

    def expectedData = findTestData("expected")
    def currentData = findTestData("current")
    
    for(i=1; i<=currentData.getRowNumbers(); i++){
        assert currentData.getValue(2, i) == expectedData.getValue(2, i)
    }
    

    Failure message should look like this:

    2020-07-02 15:16:40.471 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/table comparison FAILED.
    Reason:
    Assertion failed: 
    
    assert currentData.getValue(2, i) == expectedData.getValue(2, i)
           |           |           |  |  |            |           |
           |           14          3  |  |            13          3
           |                          |  com.kms.katalon.core.testdata.reader.SheetPOI@5aabbb29
           |                          false
           com.kms.katalon.core.testdata.reader.SheetPOI@72c927f1