Deal with the same Popup in the project

Best practices, code snippets for common functionality, examples, and guidelines.
c676228
Posts: 176
Joined: Mon Apr 06, 2015 5:40 am

Deal with the same Popup in the project

Post by c676228 » Tue Apr 14, 2015 6:13 pm

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

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3940
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Deal with the same Popup in the project

Post by odklizec » Tue Apr 14, 2015 6:57 pm

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?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Deal with the same Popup in the project

Post by krstcs » Tue Apr 14, 2015 8:06 pm

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.
Shortcuts usually aren't...

c676228
Posts: 176
Joined: Mon Apr 06, 2015 5:40 am

Re: Deal with the same Popup in the project

Post by c676228 » Wed Apr 15, 2015 12:42 am

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();

}

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3940
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Deal with the same Popup in the project

Post by odklizec » Wed Apr 15, 2015 7:42 am

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
Inheritance.png (82.78 KiB) Viewed 954 times
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
Inheritance_2.png (103.84 KiB) Viewed 954 times
Hope this helps?
Last edited by odklizec on Wed Apr 15, 2015 9:15 pm, edited 1 time in total.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

c676228
Posts: 176
Joined: Mon Apr 06, 2015 5:40 am

Re: Deal with the same Popup in the project

Post by c676228 » Wed Apr 15, 2015 9:04 pm

Cool! That's very helpful. :D