Forum Discussion

mkliba's avatar
mkliba
Occasional Contributor
16 years ago

How to remove assertions on a Groovy by type or name?

Hi:

On a previous post I found that to remove assertions we can use:
def assertionsList = testRunner.getTestCase().getTestStepByName("Test Request").getAssertionList()
for( e in assertionsList){
  testRunner.getTestCase().getTestStepByName("Test Request").removeAssertion(e)
}

Is there any way we can remove the assertions by assertion type and/or assertion name? Ex: Remove all type "XPath Match", or with name "My XPath Match"?

Thanks.

5 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    Not by type, but by name;

    def testStep = testRunner.getTestCase().getTestStepByName("Test Request")
    testStep.removeAssertion( testStep.getAssertionByName( "... ") )

    or

    testStep.removeAssertion( testStep.assertions["... "] )

    regards!

    /Ole
    eviware.com
  • mkliba's avatar
    mkliba
    Occasional Contributor
    Hi:
    Thanks Ole, that's perfect for what I was looking for. Thanks again.
    Michel
  • TheWarden's avatar
    TheWarden
    Occasional Contributor
    Hi,
    Can you disable an assertion in the same fashion?

    TheWarden
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    sure, please try

    def testStep = testRunner.getTestCase().getTestStepByName("Test Request")
    testStep.getAssertionByName( "... ").disabled = true|false

    regards!

    /Ole
    eviware.com