Dynamically changing UnexpectedWindows handling
Hi,
There are a lot of unexpected windows/dialogboxes with different messages poping up in my application during test runs.
Since the text of the popup windows changes dynamically I'm not able to tell which appears when so I'm not able to tell if it's an actual error or just a popup window.
I figured out the following solution:
function ProjectEvents_OnUnexpectedWindow(Sender, Window, LogParams) { Window.Activate(); myApp = Aliases.MyApp; var String1 = "The last "; var String2 = "Number of"; //..orders/days/items var String3 = "There are"; //..1/2/3/4/5/6..orders! or Validation failed! There are ....orders! switch(Window.MappedName) { case "Aliases.MyApp.frmMain": Log.Warning("MyApp was handled as 'Unexpected' window"); break; case "Aliases.MyApp.dlgApp": var message = myApp.dlgMyApp.Child(myApp.dlgMyApp.ChildCount - 1).Name; if(message.includes(String1)) { DevLogMessage("The text of the popped up window: " + TrimMessage(message),true); myApp.dlgMyApp.btnYes.ClickButton(); break; } else if(message.includes(String2)) { DevLogMessage("The text of the popped up window: " + TrimMessage(message),false); myApp.dlgMyApp.btnYes.ClickButton(); break; } else if(message.includes(String3)) { DevLogMessage("The text of the popped up window: " + TrimMessage(message),true); myApp.dlgMyApp.btnYes.ClickButton(); break;
} }
This is not the whole script just a snippet but you can imagine more else if cases..
This is a working solution and unexpected/popup windows will be handled as I want them.
BUT it is a bit slow and since there are a tons of times this event is going to be activated this slowness adds up and the test execution time grows.
I know it is mostly because of the (message.includes(String)) statement, everytime it has to check the whole Message if it includes the given string even if the first part of it is different. But it is kind of a must have way because I don't know which part of the dialogbox's message will contain the string which helps me to decide which button to Click on.
I hope you can understand the problem and why it is solved like this.
If you have a better idea/way to solve this problem please feel free to tell me
Anything useful is truly appriciated
Thank you