Ask a Question

How to enable/disable multiple assertions in a test Suite via groovy script

SOLVED
mithunbhat
Occasional Contributor

How to enable/disable multiple assertions in a test Suite via groovy script

I need to enable/disable multiple assertions in a test Suite via groovy script 

 

I know how to disable individual assertion via

testSuite.getTestCaseByName("TestCaseName").getTestStepByName("TestStepName").getAssertionByName( "ConciseResponse" ).disabled = true

 

But I would like to enable / disable all the assertions named "ConciseResponse" in a test suite via groovy script. Any help would be appreciated

1 ACCEPTED SOLUTION

Accepted Solutions
nmrao
Community Hero

Re: How to enable/disable multiple assertions in a test Suite via groovy script

@mithunbhat 

Not sure what is happening unless you provide the log. Or it is possible to have an issue with copy paste, sometimes, different characters are pasted. Please look in that front as well.

 

Or you can create a simple project with a test suite and try running it. It should work.

 

Any way, the solution provided is a tested solution.

 

By the way, here is an improved version, to handle test steps that can't have an assertion such as Groovy Script, Properties steps

 

testSuite.testCaseList?.each { kase -> 
	kase.testStepList?.each { 
		if (it.metaClass.respondsTo(it, 'getAssertions')) it?.assertions['ConciseResponse']?.disabled = true 
	} 
}

 

 

 



Regards,
Rao.

View solution in original post

13 REPLIES 13
nmrao
Community Hero

Re: How to enable/disable multiple assertions in a test Suite via groovy script

Where is the above script located? or a screen shot where the above script is currently present in the project?
How are you disabling it? Because that script should not be part of any test case, correct? Just a temporary one.



Regards,
Rao.
nmrao
Community Hero

Re: How to enable/disable multiple assertions in a test Suite via groovy script

@mithunbhat 

Open setup script of test suite and add the following and run it.

Once you verify the assertions are disabled, you take remove the same from setup script as it is no more needed.

 

 

testSuite.testCaseList?.each { kase -> kase.testStepList?.each { it?.assertions['ConciseResponse']?.disabled = true } }

 

 

 

 

 



Regards,
Rao.
HimanshuTayal
Community Hero

Re: How to enable/disable multiple assertions in a test Suite via groovy script

@mithunbhat : You need to loop through each Test case in that Test Suite and write the same code which you have mentioned.

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
mithunbhat
Occasional Contributor

Re: How to enable/disable multiple assertions in a test Suite via groovy script

@nmrao - Tried the script you have posted at the Setup script at the TestSuite level, but i am getting a script error 

mithunbhat_0-1623946343439.png

 

nmrao
Community Hero

Re: How to enable/disable multiple assertions in a test Suite via groovy script

Would you please show screen shot of setup script?

Also try removing ? marks one by one to see if that helps.



Regards,
Rao.
mithunbhat
Occasional Contributor

Re: How to enable/disable multiple assertions in a test Suite via groovy script

@nmrao 

Tried your suggestions of removing ? , but its still erroring out. 

Here is the screenshot of the project. Btw I am using version 3.5.1

 

mithunbhat_1-1623948630830.png

 

nmrao
Community Hero

Re: How to enable/disable multiple assertions in a test Suite via groovy script

Unfortunately, the image isn't clear. What does the error log says?
BTW, all of your test steps have assertions?

What are the different type of test steps that you have and they don't have the assertions.

The ? marks is to handle if no tests or no steps or no assertions.


Regards,
Rao.
nmrao
Community Hero

Re: How to enable/disable multiple assertions in a test Suite via groovy script

BTW, don't run test suite, just try to run only setup script.


Regards,
Rao.
mithunbhat
Occasional Contributor

Re: How to enable/disable multiple assertions in a test Suite via groovy script

Attached is the snapshot of the project. There are multiple test steps under the testcase. and not all the test steps have the assertion 'ConciseResponse'. 

 

The error I am getting while just running the setup script at the TestSuite level is 

com.eviware.soapui.support.scripting.ScriptException: Error in Setup Script of Search Options

cancel
Showing results for 
Search instead for 
Did you mean: