Ask a Question

TestRunListener.beforeStep eventHandler is not triggering TestStep execution

nicolaspwc
New Contributor

TestRunListener.beforeStep eventHandler is not triggering TestStep execution

I have the same script as a Groovy Script and it does execute that TestStep. But it does nothing when I put it on TestRunListener.beforeStep eventHandler. Any idea why?

Thanks

 

testRunner.runTestStepByName( "GetSchemaDefinition")

nicolaspwc_1-1620397583807.png

 

 

 

8 REPLIES 8
nicolaspwc
New Contributor

Re: TestRunListener.beforeStep eventHandler is not triggering TestStep execution

I just noticed that , that specific eventHandler I'm using is only trigger when I RUN tests at test case level.

When doing it I'm getting this warning message:

 

WARN: Unable to find the test step [GetSchemaDefinition] in the test case [/api/aaa/bbb]

 

I now need to figure out how access to look for TestStep "GetSchemaDefinition" on a different TestCase.
Any help is appreciated,

Thanks

HimanshuTayal
Community Hero

Re: TestRunListener.beforeStep eventHandler is not triggering TestStep execution

Yes, EventHandler will run before each and every Test Step and if your described Test Step isn't there then your script will get failed

 

In order to achieve this you can write this login into Setup Script of that Test Case where Test Step is placed.


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



Thanks and Regards,
Himanshu Tayal
nicolaspwc
New Contributor

Re: TestRunListener.beforeStep eventHandler is not triggering TestStep execution

Hi, thank you for your answer. At the moment I actually need this script to be run literally before every testStep.


I'm near to solve it with below code, but I'm facing two new issues:

def tCase = testRunner.testCase.testSuite.testCases["getSchema"]
def porp = new com.eviware.soapui.support.types.StringToObjectMap()
runner = tCase.run(null, false);

1. The script run in a loop and it never ends. How can I run it only once?

 

2. I actually need to run a testStep from a different suite, not current one. I tried with below code and it didn't work, any suggestion?

testRunner.testCase.testSuite.testSuite.testCases["getSchema"]

 

nmrao
Community Hero

Re: TestRunListener.beforeStep eventHandler is not triggering TestStep execution

Not all variables available in all the contexts.
Have a look at the right top corner of the script editor to see what variables available.

What are you trying to achieve, by the way?


Regards,
Rao.
nicolaspwc
New Contributor

Re: TestRunListener.beforeStep eventHandler is not triggering TestStep execution

Hi, can you share a screenshot please?

nmrao
Community Hero

Re: TestRunListener.beforeStep eventHandler is not triggering TestStep execution

Not at pc.
Open groovy script and look the editor's right corner of title bar.
You would notice context, log, test runner etc.,
Similarly you can notice wherever one can script such as the events, teardown, setup script for test case, suite, project etc.,

So one can only use those variables in that script. Other than those will lead to error. That's the reason if some script works in test step, but not in the event in your case.


Regards,
Rao.
nmrao
Community Hero

Re: TestRunListener.beforeStep eventHandler is not triggering TestStep execution

Please find the available variables in color coded in below screen shots

 

If a script is copied from groovy script to other places such as events, test suite tear down or any other place, they may not as is. May have to tweak a bit to make them work.

 

nmrao_0-1620536870351.png

 

nmrao_1-1620536989547.png

 

nmrao_2-1620537017459.png

 



Regards,
Rao.
nmrao
Community Hero

Re: TestRunListener.beforeStep eventHandler is not triggering TestStep execution

If you look at the screen shot, you will now understand why your script is not working.

testRunner.runTestStepByName('GetSchemaDefinition')

Here are couple of reasons
- there is no testRunner available in Events listener script
- the groovy script is present in test case, where there is step with the provided name. However, in the listener, they don't aware of those data.
- your case is not valid for events


If you explain the details of your case, what you are trying to achieve and the context then probably that would be helpful.


Regards,
Rao.
cancel
Showing results for 
Search instead for 
Did you mean: