OnUnexpectedWindow event sometimes not working for windows Appliction
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OnUnexpectedWindow event sometimes not working for windows Appliction
Hi,
In my .Net Test Application, sometime I get error with our Messagebox. On this Case I have to run a procedure.
Sometimes TC gets this messagbox as unexpected window and sometimes ignore it as unexpected window. I have read the log, the messagebox is not registered as Error or unexpected window.
How can I solve this Problem, I want to get always this Messagebox as unexpected window.
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can You show us some code?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes,
def EventSendToBugReport(Sender = None, Window= None, LogParams= None):
if Objects_WAWi.BugAuftreten_Form.Exists:
Objects_WAWi.BugAuftreten_btnSend.Click()
if Tools.WaitForAvailablity(Objects_WAWi.BugZusatzinformationSenden):
Objects_WAWi.BugZusatzinformationSenden_AchtungSign.Click()
Objects_WAWi.BugZusatzinformationSenden_btnZusatzinformationenSenden.Click()
Tools.WaitForAvailablity(Objects_WAWi.AdditionalInformation_Form)
Objects_WAWi.AdditionalInformation_Txt.Keys("TestComplate Meldung!! Für mehr info rufe Mo an. Fehler Codes is unkown!")
Objects_WAWi.AdditionalInformation_btnOK.ClickButton()
Tools.WaitForAvailablity(Objects_WAWi.SendError_Progressbar)
try:
while Objects_WAWi.SendError_Progressbar.WaitProperty("Visible", True, mBase.cBase.GetTimes('SmallTime')):
Delay(mBase.cBase.GetTimes('SmallTime'))
except Exception as exp:
Log.Message('Oh lalala, I crashed')
finally:
Tools.MessagboxManager()
Tools.MessagboxManager()
Objects_WAWi.BugAuftreten_btnOK.ClickButton()
mBase.cBase.TestResult('AQC of WAWi says: I crashed. BugInfo discoverd.',TypeOfResultObject = 'Bug')
if Objects_WAWi.Absturz_btnSchlie_en.Exists:
Objects_WAWi.Absturz_btnSchlie_en.ClickButton()
Log.Message('WAWi Absturz')
mBase.cBase.TestResult('AQC of WAWi says: Ich absturz. WAWi wird neuegestarten.',TypeOfResultObject = 'Bug')
Delay(mBase.cBase.GetTimes('SmallTime'))
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It happens to me sometimes also.
I consider this is just a weakness of TC and try to always have a second level of detection (active detection instead of event).
TC install hook on Windows message queue but we cannot be guaranteed that whenever it peek message on it, it successfully grab all.
OS and software environment are becoming so complex so i don't blame TC for it.
Un sourire et ça repart
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Many thanks for your comment,
but how can I use Active Detection, Can you please give me more elaboration?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Event means that you let system warn you when the event occurs.
Active detection is you specifically search for the element.
Your problem is: could you determine conditions or places/times when the message box appears ?
- If yes then you could use one of the WaitNNN methods to wait for the message box.
- If no then you must rely on Event... Houston we've got a problem... If you are good enough in development, perhaps create your own Event listener to catch on your apps only the message box. Something like this:
https://docs.microsoft.com/en-us/windows/win32/winauto/uiauto-howto-implement-event-handlers
Un sourire et ça repart
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you sure you have to use this inside the event function?
Objects_WAWi.BugAuftreten_Form.Exists
If you are looking for a particular window, use it inside the main unit function.
As a parameter, you have a window object. And this is what you are currently looking for.
There is no need to look for something specified in the function, which is used to manage unexpected events.
Read also @tristaanogre solution about .exist:
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
OnUnexpectedWindow event is triggered in TestComplete when some modal window (application or system) prevents your test code to interact with UI elements out of this modal window. Examples of such interactions are clicks, setting focus and sending keys sequences. Exactly like it looks like for the human user.
Note, that if your test code does not interact with UI but operates on tested application's methods/properties, then modal window will not block such interactions and thus the OnUnexpectedWindow event will not be triggered.
For example, <inputField>.SetText('blah') will always succeed as it uses direct property assignment and does not interact with the <inputField> element via GUI. On the contrary, <inputField>.Keys('blah') will trigger the OnUnexpectedWindow event if the form with the field is blocked by some other modal message window.
The good approach to get a reliable test code in the cases like this is to use .Activate for forms/windows and .Focus methods for controls before interaction with them to ensure that forms/controls are not blocked.
E.g.:
<form>.Activate;
<form>.<inputField>.Keys('blah');
<form>.<inputField2>.Keys('blah')
...
/Alex [Community Champion]
____
[Community Champions] 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 Champions]
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 Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
One more thing:
@MadGrb wrote:def EventSendToBugReport(Sender = None, Window= None, LogParams= None): [...] try: while Objects_WAWi.SendError_Progressbar.WaitProperty("Visible", True, mBase.cBase.GetTimes('SmallTime')): Delay(mBase.cBase.GetTimes('SmallTime')) except Exception as exp: Log.Message('Oh lalala, I crashed') finally: [...]
I see very little reason to use try/catch here.
The case is that try/catch are the means of the programming language to handle runtime exceptions. Those like division by zero or thrown by purpose programmatically.
In your case, <object>.WaitProperty() statement is absolutely safe and cannot trigger runtime exception.
Yes, logical failure will occur if, for example, you try to wait for some non-existent property. But this will not be a runtime exception and thus it will not be handled by the catch clause. It will be a logical TestComplete'e error that will trigger the OnLogError event and can be handled there.
/Alex [Community Champion]
____
[Community Champions] 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 Champions]
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 Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As quick answer yes. I have check is she msgbox or other window.
