Page 1 of 1

Deal with the same Popup in the project

Posted: Tue Apr 14, 2015 6:13 pm
by c676228
Hi,

In my project, there is a native window popup occasionally in different test cases.
If the test cases need to create a file and the file is created in the folder already.
"The file exists already. Do you want to overwrite it?
yes no "

My question is if I want the method for handling this popup in a class which can be called in every test case instead of dealing with it in each test case's user code repeatedly.

It seems that I need to created a specific code module to handling it. Can you tell me how to make methods callable in code module from each test case or recording module?

Thanks,
Betty

Re: Deal with the same Popup in the project

Posted: Tue Apr 14, 2015 6:57 pm
by odklizec
Hi,

Check out this example how to deal with popup dialogs...
http://www.ranorex.com/support/user-gui ... html#c4678

Additionally, you can find this topic discussed (and some more examples) by searching this forum for "popup" word.

As for creating methods accessible from any recording/code module, search for "inheritance" or reusable words. Hope this helps?

Re: Deal with the same Popup in the project

Posted: Tue Apr 14, 2015 8:06 pm
by krstcs
I would submit that if you already know when/if the popup SHOULD be displayed (i.e. when the file already exists, in this case) then the popup watcher is not the best (or even correct) way to handle it. It should be handled as an intentional part of the test.

The PopupWatcher class is intended for unexpected popups such that the tester has no control over the issue being notified about (like network errors or slowness that is out of the tester's control), but the tester knows they might "popup" at times. Also, any truly unexpected popups should cause test errors/failures because they are a bug in either the SUT or test (where the test doesn't account for a popup correctly).

In this instance, from what Betty said, she knows when/if the popup will be displayed, because she knows if there is a file already existing. This can be checked during the test run, if needed, or can be passed in as a data point that tells the test whether there should be a popup or not, and then what to do about it.

Betty, I would suggest that you create a module that handles the dialog such that you can drop the module in the test suite where you need it to be handled.

You can create the module either:

1. Such that it doesn't know anything about the file, where you pass it only the information about the popup and button to click (e.g. pass in variables $IsPopupExpected and $ButtonLabel) and then validate the popup and click the button, or

2. Such that it checks for the existence of the file and then validates the state of the popup, and finally clicks the passed-in button (e.g. pass in variable $ButtonLabel).

There would need to be user-code, but the module would be easy to manage based on data and could be dropped wherever you need to use it. And, once you have the module you wouldn't need to re-code this part of the test again.

Re: Deal with the same Popup in the project

Posted: Wed Apr 15, 2015 12:42 am
by c676228
hi Pavel,

Do you mean code module could be added to test cases just like any recording modules?
If so I can create a code module say "PopupHandler" with the following code in the run method.
So I just insert PopupHandler code module in wherever the regular class method in user code is needed.
Is it possible to insert PopupHandler.ClassMethod1, PopupHandler.ClassMethod2... in test cases if I have multiple methods inside the code module?



void ITestModule.Run()

{

var confirmSaveAs = repo.ConfirmSaveAs;
if (confirmSaveAs.Self.Active)
confirmSaveAs.ButtonYes.Click();

}

Re: Deal with the same Popup in the project

Posted: Wed Apr 15, 2015 7:42 am
by odklizec
Hi,

Yeah, you can use Code Modules in TCs like Recording modules (I would recommend to watch this screencast).

And yes, the code module can have multiple methods inside and you can make them accessible from recordings. To make the code module methods accessible from recording modules, you need to make the recordings to inherit the code module, by adding the colon followed by (path)name of the codemodule to the recording module User Code.
Here is an example...
Inheritance.png
As you can see, my Login recording inherits Common.cs (located in CodeModules folder). Now if I add new User Code action to Login recording, I can access all methods from common.cs...
Inheritance_2.png
Hope this helps?

Re: Deal with the same Popup in the project

Posted: Wed Apr 15, 2015 9:04 pm
by c676228
Cool! That's very helpful. :D