Forum Discussion

Twiceme's avatar
Twiceme
New Contributor
6 years ago

Handling "Unexpected" events

Hello!

 

I have some questions regarding TestComplete. We have been using it for a few months and it is working great but we ran into a problem and I would like to ask your help in regard. 

 

We are testing a pretty big application with hundreds of windows, so we are searching for an universal solution. So to get to the problem: Sometimes when we are clicking on a window, dialog boxes pop up with different text with different buttons(yes,no,ok,cancel...). The problem is that these dialog boxes does not show up every time and they can appear where we did not expected them. We ran into these problem during regresion test (but we will have these problem later on too), where we simply open the window, a form shows up then we close the form. The earlier mentioned dialog boxes can show up after we click the window, or after we close the form, so it is pretty random. Our first solution was that we hard coded in a code like:

 

if(dialogbox.Exists)

{

dialogbox.btnOk.ClickButton();

}

 

But after we realised how big the application is, we started to work on another approach. We created an unexpected window event handler, so if there is an unexpected window, it searches if it is a predefined window and if so: do something. Do something like this:

 

UnexpectedWindowEventHandler(Window,Sender,LogParams)

{

var Dialogtext="Test";

switch(Window.MappedName)

{

case "application.dialogbox":

if(Window.Text==Dialogtext)

{

application.dialogbox.btnOK.ClickButoon();

}

etc...

}

}

 

In the begging it worked well, we did not had to hardcode anything and it handled pretty much everything (a little bit slower than the hardcoded version, but this universal approach made our work much faster).

 

Then we started to get some problems with it: Sometimes after we open a window more than 1 dialogbox appears and the eventhandler can handle the first one but gets in trouble with the second one (we think it might think that the form we wanted to open is the unexpected window and not the dialogbox). 

 

The other problem is when the dialog boxes pop up after we close the form it does not close the dialog boxes(there are more script after the close and we get an error so the problem is not that we want to finish a test with an event) The simple version of the code is like:

 

ToolStripmenu.Click("Test");

TestForm.Close();

//(and here come the dialog boxes)

Toolstripmenu.Click("Test2");

etc...

 

If we write after the TestForm.Close() statement that we want to activate the window(TestForm.Activate()), it handles the dialog boxes, but then we get an error in the log that the window is destroyed so it can not be activated (In reality after we close the form the dialog boxes come up, but the form stays in the background so the exists property is true but the focus property is false cause of the dialog boxes, but after we pressed okay on the last dialog box, the dialog box and the form also disappears. So we get why we get an error but we do not know how to deal with it).

 

The other problem is, sometimes when we click the window and the dialog shows up like this:

 

ToolStripmenu.Click("Test");

//(and here come the dialog boxes)

TestForm.Activate();

TestForm.Close();

 

TestComplete clicks on the Test window, waits and tries to activate and close it(we get an error here because the form is invisible) then it handles the dialog boxes because of the event handler, but does not close the form, just continues the script. We do not know why it tries to activate it and close it when there is an unexpected window and that event has to run first.

 

We tried to solve this with the LogError event handler, where we basically call the unexpected window handler. With this approach it handled the problem, but every time there is an error, TestComplete checks if the dialog box exists(obviously because we wrote that in LogError) and if not it logs the error. The problem is that it slows down the process very much, because every time there is an error there is minimum 5-10 sec delay, and we are worried if we put more more forms to check it will slow it down even more.

 

So basically to the question. Is there a way to handle these "unexpected" windows smoothly, but with universal solution? Thank you for your answer!