Forum Discussion

MrMax's avatar
MrMax
Occasional Contributor
16 years ago

Groovy Script + Assertions

Hi,

Does anyone know how to add assertions to a groovy script.

This is my scenario:

I want to take data from a .csv file from developers.

The CSV file contains 100 users with there information ie. age,height, date of birth,
I want to take this data and loop/automate with a script so soapUI takes the data and then runs a groovy script then outputs the data to me

So far dunno what the best way is, I have a small script in groovy but limitation is when this is run I cannot see output or attach a assertion so that it lets me know if the test has failed or passed.

Any comments will be helpful

Regards
Max

4 Replies

  • Hi,

    You can use the statement

    assert <first value> == <second value>

    in your groovy script.

    Other that this, you can also add assertion to the test request under script assertion.
    Hope it helps.

    Regards,
  • MrMax's avatar
    MrMax
    Occasional Contributor
    This works but it stops my script from running once the assertion fails.

    I still need it to loop for the rest of the contents of the .csv file.

    Do I need insert a try and catch to the groovy script?

    Also a onscreen error is displayed when the assertion fails, can this be logged to a notepad file etc.

    Thanks for you replies

    MAX
  • Beno_Iskratel's avatar
    Beno_Iskratel
    Frequent Contributor
    in your testCase you have "Fail on error" option.
    make sure it's empty.

    regards,
    beno
  • Hi,

    To continue the test case execution if any assertion fails, right click on the test case.
    In the options, uncheck the checkbox with label "Abort on error."

    To write the error message in a notepad, you can add a line or two in ur assertion script itself.

    Alternate way is to export the test suite log to a note pad. The failed assertions are logged with details of value etc in the test case or test suite log.

    Hope it helps.

    Regards,