Ranorex command prompt causes IE browser to lose focus

Ask general questions here.
hporter
Posts: 35
Joined: Wed Jan 23, 2013 4:49 pm

Ranorex command prompt causes IE browser to lose focus

Post by hporter » Wed Feb 06, 2013 10:06 pm

My test app runs in an IE browser. If I build my test as a console app, the resulting command prompt obscures the browser (specifically, the first button that gets pressed), and the test fails. Is there any way to a) minimize that command prompt entirely by default, or b) ensure that my browser has immediate focus? I suppose I could put in a mouse-click somewhere else on the page, for a first action, but I'd rather not introduce needless clicks if I can help it. Thanks!

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Ranorex command prompt causes IE browser to lose focus

Post by Ciege » Wed Feb 06, 2013 10:24 pm

Couple things you can do/try.
1) Send a .EnsureVisible to the IE element at the beginning of your tests.
2) (as you said) click the IE element as a first step.
3) Use a minimize all code snippet at the beginning of your tests (before you launch IE) to verify all windows are minimized. I use this method. Here is the code that does that:

Code: Select all

//Minimize All Windows
// First we get the type from the Shell.Application
Type typeShell = Type.GetTypeFromProgID("Shell.Application");
// Next we create the object "objShell" from the type "typeShell"
Object objShell = Activator.CreateInstance(typeShell);
// Finally we Invoke "MinimizeAll" to show the desktop
typeShell.InvokeMember("MinimizeAll", System.Reflection.BindingFlags.InvokeMethod, null, objShell, null);
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

hporter
Posts: 35
Joined: Wed Jan 23, 2013 4:49 pm

Re: Ranorex command prompt causes IE browser to lose focus

Post by hporter » Thu Feb 07, 2013 12:07 am

Thanks so much, Ciege - that method did the trick! I have a recording module called OpenBr that opens the browser, and I copied the code snipped into the Init() method of the UserCode.cs for that module. Is that the accepted way of using this code, or is there a more elegant approach I should adopt? Also, am I correct in understanding that you are adding this method as a matter of course to any tests you write?

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Ranorex command prompt causes IE browser to lose focus

Post by Ciege » Thu Feb 07, 2013 12:15 am

You are very welcome...

Since I don't use recorded tests or the Ranorex testsuite methodology I can't answer the question about the "accepted" way of doing things for you. But if it works for you then...

And yes, this code snippet is a part of my setup method in my framework that is called by each and every test I develop. So it is called and used by all of them.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

hporter
Posts: 35
Joined: Wed Jan 23, 2013 4:49 pm

Re: Ranorex command prompt causes IE browser to lose focus

Post by hporter » Thu Feb 07, 2013 3:35 pm

OK, thanks again for the assistance!