If a window appear on the screen, close it

Ranorex Studio, Spy, Recorder, and Driver.
romainb25
Posts: 15
Joined: Mon May 09, 2016 2:31 pm

If a window appear on the screen, close it

Post by romainb25 » Thu Jun 23, 2016 1:58 pm

Hi community,

In a test case, i have to fill a form
When i try to validate it, sometimes i get a form with an error message due to bad formatting, sometimes i have no error message.

I would like to do the following in my script:

//validate form
repo.FormBro.BitBtnOK.Click("35;13");

while(repo.Warning.Self.Active==true|repo.Error.Self.Active==true)
{
repo.Warning.ButtonOK.Click("35;13");
repo.Error.ButtonOK.Click("35;13");
}

while the error or warning form is active on the screen and on the foreground, close it in clicking the OK button.

My part of script doesn't work, how can i do?

Thanks
Romainb25

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

Re: If a window appear on the screen, close it

Post by odklizec » Thu Jun 23, 2016 2:11 pm

Hi,

I would suggest to use code for handling unexpected dialogs, as described here:
http://www.ranorex.com/support/user-gui ... html#c4678
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
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: If a window appear on the screen, close it

Post by krstcs » Thu Jun 23, 2016 2:15 pm

You can't try to click on both buttons, as one will always fail due to the logic of your test.

In addition, the while loop will skip completely if Ranorex gets there before your SUT has displayed the dialogs.

Try this instead:

Code: Select all

repo.FormBro.BitBtnOK.Click("35;13");

if (repo.Warning.SelfInfo.Exists(15000)) { //15000ms search override
    repo.Warning.ButtonOK.Click("35;13");
} else if (repo.Error.SelfInfo.Exists(15000)) { //15000ms search override
    repo.Error.ButtonOK.Click("35;13");
}
Shortcuts usually aren't...

romainb25
Posts: 15
Joined: Mon May 09, 2016 2:31 pm

Re: If a window appear on the screen, close it

Post by romainb25 » Fri Jun 24, 2016 8:45 am

I tried to use this :

while(repo.Avertissement.SelfInfo.Exists(1000)) //search 1 second
{
Keyboard.Press("{Enter}");
}

because sometimes i have two warning forms so i want to close the two form at once
It close the first form but not the second form . Why ? :?

Thanks
Romainb25

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

Re: If a window appear on the screen, close it

Post by krstcs » Fri Jun 24, 2016 1:29 pm

Do not use a WHILE loop, your logic is wrong for it, and it isn't really what you want.

The Exists() method tries to find the element for the timeout given, so it will wait for you until the element exists or the timeout is hit, so just use an IF like I did in my code.

As for two popups, since I don't know your system I can't really help.


My suggestion for you is to get some beginner's C# training, either formal, online or books (there are even some Android apps that are pretty good as well). You seem to not understand the basic logic of the syntax, and you need to if you are going to code your own test steps.
Shortcuts usually aren't...