Forum Discussion

masteriti's avatar
masteriti
New Contributor
6 years ago

Data Driven Tests with variable Assertion

Hello,

 

I'm creating data driven tests and ran into the following scenario: For each test case, I need to test for the presence of a specific elements in a list.  The issue is that for some cases I'm looking for a single element, for others I have 2 or more elements to test.  I could seperate out test cases that have 1, 2 etc. assertions, but I'm wondering if theres a way to run all these test in a single test case.  For example, is there a way to activate an assertion if there is a value present in my data file?

 

Thanks!

  • Thanks for the reply, I think that could work but I just realized when asserting for content (Contains) if I leave the field blank in my data source, it will work (I guess testing for an empty tag?).  So for a small set it would be practicle to setup additional columns in my data source (value1, value2, value 3, etc) and have those columns populated with the required values if present.  This would avoid having to create a specific groovy script for the assertion by the testers.

     

    Thanks!

  • nmrao's avatar
    nmrao
    Champion Level 3

    Let us say, here is the data:Considering the elements that needs to be verifed.

    Also assuming that the list is fixed. Say, [Value1, Value2, Value3, Value4]

    Use a groovy script to make the assertions

    Test, ExpectedValues

    1, "Value1"

    2, "Value2, Value3"

     

    In the assertion, I assume you wold able to get the expected values for the respective row.

    Split it by command and trim the spaces and see if those values are from the above expected list.

     

    Does it sound ok?

    • masteriti's avatar
      masteriti
      New Contributor

      Thanks for the reply, I think that could work but I just realized when asserting for content (Contains) if I leave the field blank in my data source, it will work (I guess testing for an empty tag?).  So for a small set it would be practicle to setup additional columns in my data source (value1, value2, value 3, etc) and have those columns populated with the required values if present.  This would avoid having to create a specific groovy script for the assertion by the testers.

       

      Thanks!

      • sonya_m's avatar
        sonya_m
        SmartBear Alumni (Retired)

        Happy to hear that the issue is resolved:smileyhappy: 

        Thanks for sharing the solution with the Community.