Ask a Question

same kind of event handlers for different events

SOLVED
mustafayol
Occasional Contributor

same kind of event handlers for different events

Hi, 

Here is the imaginary scenario that resembles the issue that I have in a simpler explanation.

1) I created a desktop test, it has Test1, Test2 and Test3. Each test case handles different tasks.

2) When there is an unexpected window that pops up at any of these tests, I want to be informed by email.

So I created 3 different event handlers as EventControl_Test1, EventControl_Test2 and EventControl_Test3.

3) Then for each event handler, I added the general events: OnUnexpectedWindow. 

Until here, you can see the explanation in picture 1.

4) After adding the general events: OnUnexpectedWindow, respective test scripts had the eventHandler functions at the bottom of the test scripts.

 

As a result, for each separate test case, I created a separate event handler (EventControl_Test1_OnUnexpectedWindow,EventControl_Test2_OnUnexpectedWindow, EventControl_Test3_OnUnexpectedWindow), which is expected to be triggered in case of having unexpected windows.

I added an email sending function into each eventHandler function. 

You can see the explanation in Picture 2. This picture is for test1 but, it is also the same for test2 and test3, only handlers and test cases are different. 

 

Expected result: When I run test1 and when I encounter an unexpected window, I would expect  "EventControl_Test1" to be triggered and the respective email to be sent.

 

Actual Result: When I run test 1 and encounter an unexpected window, all of the EventControl_OnUnexpectedWindow handlers are triggered.

I mean even if I have an unexpected window while running test1, unexpected window event handlers of test2 and test3 are also triggered.

The stranger part is, this happens even when I do only run test1, and get an unexpected window, event handlers of test2 and test3 are all triggered, then send emails. This can be seen in Picture 3.

 

Is this a bug, or should I make another assignment? Or is the way I try to implement it wrong?

 

 

Picture1:

 

mustafayol_0-1643378825870.png

 

Picture 2

 

mustafayol_1-1643378905675.png

 

Picture 3

 

mustafayol_2-1643380317168.png

 

 

7 REPLIES 7
Marsha_R
Community Hero

Since it's all the same response, I would use one event handler for all three.  I think that will get you one response per test and only from the tests that are running.

 

I don't believe that TestComplete understands that you mean those three event handlers to line up with the tests.  It is just seeing an unexpected window and oh look here are the events I need to do when that happens and you get three messages no matter what.


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
sonya_m
SmartBear Alumni (Retired)

Thank you, Marsha!

Hi @mustafayol, does this help?


Sonya Mihaljova
Community and Education Specialist

mustafayol
Occasional Contributor

It is not a solution, but yes answer is enough for me, I will try to find another workaround, thank you Marsha,

 

Regards

Mustafa 

It is a solution, just maybe not the one you hoped to get.  


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
mustafayol
Occasional Contributor

Your answer has really enlightened me and provided a basic idea of what I can or can't do with Test Complete.

I really appreciate that. But that is really not a solution for me, but again thank you for your answer.

 

Ps: There are still things that I could not understand about test complete event handlers. 

If Test Complete can add different unexpected windows handlers to different units, where each unit is a test case, which means each test case has its own individual unexpected windows handler. Basically, if I run test unit 1 and get an unexpected window through this test case, I would expect only the handler in test unit 1 to be triggered. But in reality, all other unexpected window handlers are being triggered.

There is no point in triggering the unexpected window handlers in test units 2 and 3 and so on... If one "unexpected window" triggers all the event handlers, what is the point of having more than one event handler? And why is test complete capable of adding several event handlers to several units. Even with different names. 

That is what I observed. Next week I will try to examine more if I have a chance.

cheers...

 

 

Regards

Mustafa 

Hi Mustafa,

 

Basically, as Marsha wrote...

Honestly, I never tried to create more than one event handler of same type per project and thus it was interesting to get to know from your post that this is possible and how it works.

I never tried the above just because, as it is documented, event handlers in TestComplete are per-project entities, but not per-unit/keyword test/BDD feature/etc. ones. This means, that created event handler is registered for the project and is triggered by TestComplete engine when any test entity of this given project is executed. Event handling routine (i.e. the code that is bound to event handler and that is executed when event handler is triggered) can be located within any script unit of test project. There is no requirement to have event handling routine within the same script unit where the (startup) code for the test itself is located. Similarly, TestComplete makes no assumptions to the fact of whether startup code for the test and event handling code are located within the same script unit or not.

 

Hope, this will make things a bit more clear.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
mustafayol
Occasional Contributor

Hi Alex,

Thanks for the clarification and your time,

Best Regards

Mustafa

 

cancel
Showing results for 
Search instead for 
Did you mean: