cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically changing UnexpectedWindows handling

Occasional Contributor

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

 

 

3 REPLIES 3
Community Hero

Re: Dynamically changing UnexpectedWindows handling

Your second case statement seems to contain a lot of unnecessary logic.  In the code to be executed with each "if" statement, there really is no major difference in the logic with the exception of a difference in one parameter of your DevLogMessage call.  I would reorganize your code a little bit to reduce the number of calls and if logic statements.  This reduces the number of "includes(Stringx)" calls and simplifies the code a bit.  Not sure how much performance improvement this will bring but the less logic included, usually the better the performance.

 

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(String2)) 
				  DevLogMessage("The text of the popped up window: " + TrimMessage(message),false);
			  else 
				  DevLogMessage("The text of the popped up window: " + TrimMessage(message),true);
              myApp.dlgMyApp.btnYes.ClickButton();
              break;
        }
}

Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Occasional Contributor

Re: Dynamically changing UnexpectedWindows handling

Sorry, my example was not correct, please check the .ClickButton() methods :

 

 

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.btnNO.ClickButton();
                    break;
              }
} else if(message.includes(String3)) {
DevLogMessage("The text of the popped up window: " + TrimMessage(message),true);
myApp.dlgMyApp.btnOK.ClickButton();
break;
}
}

As you can see, I have to handle them differently because each of them has different button as well... Smiley Sad

Therefore your reorganized code would cause failure. Sorry for giving bad example.

 

Highlighted
Community Hero

Re: Dynamically changing UnexpectedWindows handling

Again, just checking... there are two "if" statements including String3... is that correct? And your brackets are off somewhere in there, too... so... 

Without having accurate code, I can't give an accurate suggestion.  But... thinking "out loud" here...

There might be a way of doing a logical check of the string once without having to check it 4 different times or there might be a methodology that is better, performance wide, than "includes".  

 

Perhaps you could also create an array or matrix or dictionary of the three string segments and associated "parameters".  Something like

 

"String1", "true", "btnYes"

"String2", "false", "btnYes"

"String3", "true, "btnNo"

 

And so on... then you can just call one routine that checks which row to reference and then utilize the expected parameters.

 


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
New Here?
Join us and watch the welcome video:
Watch the new interview
Top Kudoed Authors