Forum Discussion

lydeeea's avatar
lydeeea
Occasional Contributor
3 years ago

Ready API Data Driven Tests

Is there any way to set assertions for each row in my data source?

 

For example, my excel has 10 rows each with different data inputs.  I want to create different assertions for each of my 10 rows.

 

Thanks

  • Hi,

     

    You can put whatever you want in your datasource file.

     

    If one of things you want to assert is the same for every row, you don't need to put it in the datasource. E.g. status code should equal 200.

     

    But, say, you want to check invalid responses as well as valid, then the datasource could be your mate.

     

    For example.  Say you have a getCustomerDetailsById service...

     

    CustomerId ExpectedStatusCode ExpectedSurname ExpectedForename
    1 200 Lennon John
    2 200 McCartney Paul
    3 200 Harrison George
    4 200 Starkey Richard
    99 200 <null> <null>
    ninetynine 500 <null> <null>

     

    You can then have three assertions against your test step and dynamically compare expected result with the response.

     

    You don't have to put your expected results in your datasource, this is just my favoured approach.

     

  • ChrisAdams's avatar
    ChrisAdams
    Champion Level 3

    Hi,

     

    In my datasources, for each row, I tend to include the expected result(s) along with the values I intend to pass to an API call.  That way, I can pull the expected values from the row into the steps assertion or a Groovy script to assert/check response against the expected result.

    • lydeeea's avatar
      lydeeea
      Occasional Contributor

      Thanks!

       

      My expected results are not part of my input so will this still work?  I can have a column in my data source called results with what I'm expecting for that row?

       

       

      • ChrisAdams's avatar
        ChrisAdams
        Champion Level 3

        Hi,

         

        You can put whatever you want in your datasource file.

         

        If one of things you want to assert is the same for every row, you don't need to put it in the datasource. E.g. status code should equal 200.

         

        But, say, you want to check invalid responses as well as valid, then the datasource could be your mate.

         

        For example.  Say you have a getCustomerDetailsById service...

         

        CustomerId ExpectedStatusCode ExpectedSurname ExpectedForename
        1 200 Lennon John
        2 200 McCartney Paul
        3 200 Harrison George
        4 200 Starkey Richard
        99 200 <null> <null>
        ninetynine 500 <null> <null>

         

        You can then have three assertions against your test step and dynamically compare expected result with the response.

         

        You don't have to put your expected results in your datasource, this is just my favoured approach.