Forum Discussion

Oric706's avatar
15 years ago

Disable/Enable Assertion Based on DataSource Property

Hello All,
I have a spreadsheet with all my test data in it. I have created a test case with the following steps:

Test Steps:
1. DataSource -> Loads the data from my spreadsheet
2. Groovy Script -> Going to be used to enable and disable an assertion based on some data from DataSource
3. SubmitCheck-Base -> This a SOAP request test step. I have two assertions I need to dynamically turn on and off based on the data from the DataSource.
4. Result Property Transfer -> This transfers the response from the request to the DataSink
5. DataSink -> Write the entire response payload to a second sheet in my spreadsheet.
6. DataSource Loop -> Goes back to the Groovy Script step as long as there is still data in DataSource rows

In my DataSource spreadsheet I have a column (property) called Assertion. This column is either "accept" or "error". When this value in this column for whatever row the test is on is equal to "accept" then I want my "NoFaultAssertion" to be enabled on the SubmitCheck-Base and I want my "FaultAssertion" to be disabled in the the SubmitCheck-Base. And likewise, if the value in the DataSource is "error" I want "FaultAssertion" enabled and "NoFaultAssertion" disabled.

When I compile this script I get numerous errors. Thoughts?

WsdlTestRequestStep step = ((WsdlTestRequestStep)testRunner.testCase.getTestStepByName("submitCheck-Base"));
WsdlMessageAssertion noFault = ((WsdlMessageAssertion)step.getAssertionByName(NoFaultAssertion))
WsdlMessageAssertion fault = ((WsdlMessageAssertion)step.getAssertionByName(FaultAssertion))

if (${DataSource#Assertion} = "accept") {
noFault.setDisabled(true)
fault.setDisabled(false)
} else if (${DataSource#Assertion} = "error") {
noFault.setDisabled(false)
fault.setDisabled(true)
} else {
noFault.setDisabled(false)
fault.setDisabled(false)
}

2 Replies

  • Hi there!

    I haven't time at the moment to look at your groovy code but I will get back to you.

    In the meantime let me ask you this question:
    Is it feasible to divide your source spreadsheet into two sheets or two separate spreadsheets? First one would have Assertion column all equal to "accept". Second one would have all "error"
    Then have two separate test cases in soapui. One does only "NoFaultAssertion", the other does only "FaultAssertion"?
  • Ok, briefly tried to figure this one out on my own, but then decided to just search.

    https://www.eviware.com/forum/viewtopic.php?t=859

    Using info from above post...change your script to something like:


    step = testRunner.testCase.testSteps["submitCheck-Base"]
    noFault = step.assertions["NoFaultAssertion"]
    fault = step.assertions["FaultAssertion"]

    if (${DataSource#Assertion} == "accept") {
    noFault.disabled = true
    fault.disabled = false
    } else if (${DataSource#Assertion} == "error") {
    noFault.disabled = false
    fault.disabled = true
    } else {
    noFault.disabled = false
    fault.disabled = false
    }


    Or, more concise (perhaps not as efficient):

    step = testRunner.testCase.testSteps["submitCheck-Base"]
    noFault = step.assertions["NoFaultAssertion"]
    fault = step.assertions["FaultAssertion"]

    noFault.disabled = false
    fault.disabled = false
    if (${DataSource#Assertion} == "accept") noFault.disabled = true
    if (${DataSource#Assertion} == "error") fault.disabled = true