Page 1 of 1

dismiss unexpected popups

Posted: Tue Jan 12, 2016 8:24 am
by sivakumaran
Hello expert,
we are in the process of ranorex evaluation.
we want to dismiss unexpected popup during our test automation and so we tried a sample code by referring the code of PopupWatcher to dismiss Trend Micrsoft officeScan client window.
Following is the code snippet.
REpository Item created: /form[@title~'^Trend\ Micro\ OfficeScan\ Re']/button[@text='OK']

private void Init()
{
PopupWatcher myPopupWatcher= new PopupWatcher();
myPopupWatcher.Watch(repo.TrendMicroOfficeScanRealTimeMonitor,CloseUpdateCheckDialog);
// Your recording specific initialization code goes here.
myPopupWatcher.Start();
}

public static void CloseUpdateCheckDialog(Ranorex.Core.Repository.RepoItemInfo myInfo, Ranorex.Core.Element myElement)
{
myElement.As<Ranorex.Button>().Click();
}

public static void CloseUpdateCheckDialog(Ranorex.Core.RxPath myPath, Ranorex.Core.Element myElement)
{
myElement.As<Ranorex.Button>().Click();
}
but somehow, none of the callbacks were getting called.
Please help.

Regards,
Siva

Re: dismiss unexpected popups

Posted: Tue Jan 12, 2016 4:04 pm
by Support Team
Hello Siva,

Basically, the user code sample looks good and should work.

May I ask where exactly you run the Init() method, which starts the PopupWatcher?

Generally, I would recommend starting the PopupWatcher in the setup region of the test suite. The setup region could be used to prepare the test case run. Therefore, the PopupWatcher will be valid for the whole test suite. More information about setup and teardown regions can be found in the user guide.

In the following sample a code module is used to initialize the PopupWatcher.
start_popup_watcher.png
Sincerely,
Johannes

Re: dismiss unexpected popups

Posted: Tue Jan 12, 2016 5:28 pm
by krstcs
Also, make sure that ALL RanoreXPaths are correct, especially the path for the trigger element. If the trigger element's path is not found, the PopupWatcher will never kick off.

Re: dismiss unexpected popups

Posted: Wed Jan 13, 2016 7:18 am
by sivakumaran
Hello Johannes, Hello krstcs,

Thanks for your replies.
The Init() method belongs to one of the testcase's usercode.cs
It works now.

Additionally, I have few more questions,
I am planning to wrap this PopupDialogWatcher into a custom class of my own and I want to implement that class as Singleton class.
And I will initialize and start and stop everything inside the Program.cs
So with respect to my test suite all kind of popups, I want to handle here in Program.cs
Is this approach fine?

Re: dismiss unexpected popups

Posted: Wed Jan 13, 2016 12:32 pm
by Support Team
Hello Siva,

Great to hear that you could solve the issue.

Implementing a Singleton class, which is initialized in Program.cs, is basically a good approach. Therefore, the PopupWatcher is valid during the whole test execution.

If you need further assistance, please do let me know.

Sincerely,
Johannes

Re: dismiss unexpected popups

Posted: Wed Jan 13, 2016 1:12 pm
by sivakumaran
Hello Johannes,

My intention was to close all the popup from other processes other than the process or AUT(Application under test)
because of that following is the code.
I highlighted those lines that did not work.

public void ClickButtonOnDialog(Ranorex.Core.Repository.RepoItemInfo repoItemInfo, Ranorex.Core.Element element)
{
Ranorex.Report.Screenshot();
//Let's say this is the Microsoft Officescan client.
var processId = element.GetAttributeValue("processid"); => this step is not working
//I want to get the application under test
System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("Siemens.Automation.Portal.*"); => this step too is not working
Form formForProcessId = Host.Local.FindSingle(repoItemInfo.Path);

//if the popup is from some foreign process, i want to close that
Host.Local.CloseApplication(Convert.ToInt32(processID));
//element.As<Ranorex.Button>().Click();
}

Please suggest how could this be processed?

best regards,
Siva

Re: dismiss unexpected popups

Posted: Wed Jan 13, 2016 3:01 pm
by Support Team
Hi Siva,

Concerning the first issue
If you use the following code, please make sure that the corresponding repository item points to the form directly (e.g. "/form[@title~'^Trend\ Micro\ OfficeScan\ Re']").

Code: Select all

var processId = element.GetAttributeValue("processid");
Host.Local.CloseApplication(Convert.ToInt32(processId));
Instead of the previous approach you could simply pass the Element directly to the CloseApplication method.

Code: Select all

Host.Local.CloseApplication(element);
Concerning the second issue
If the following code doesn't find any processes, it seems like the process name is not correct.
Note that this method doesn't consider wildcards such as *.

Code: Select all

System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("Siemens.Automation.Portal.*"); 
More information about this method can be found in the Microsoft Documentation.

Sincerely,
Johannes