Strange behavior when entering text

Ask general questions here.
jackrabbit
Posts: 47
Joined: Wed Mar 18, 2015 10:06 pm

Strange behavior when entering text

Post by jackrabbit » Wed Jun 10, 2015 9:37 pm

I need to write a Ranorex test to launch and application from the VmWare console. Basically, what I do, is to select a VM, open its WmWare console, make sure the Desktop is already visible and launch an application by pressing Windows+R followed by my command followed by a RETURN.

I am experiencing strange behaviors when using some characters in my command. It looks like when I enter any character formed using the SHIFT, CTRL, ALT, WINDOWS key, I must manually reset those keys after each character, otherwise I get junk, other characters of nothing in some cases.

Here is an example, I attempt to run the script "C:\Temp\hello.bat":

Code: Select all

// Set focus to the WmWare Console windos
MyRepo.MyForm.MyScreen.Self.Click();

// Press the WINDOWS+R sequence to open the EXECUTE box in Windows
Keyboard.Down(System.Windows.Forms.Keys.LWin, Keyboard.DefaultScanCode, true);
Keyboard.Press(System.Windows.Forms.Keys.R, Keyboard.DefaultScanCode, Keyboard.DefaultKeyPressTime, 1, true);
Keyboard.Up(System.Windows.Forms.Keys.LWin, Keyboard.DefaultScanCode, true);

// Enter command to execute
Delay.Milliseconds(500);
Keyboard.Press(Cmd);
When I run this test, I only get "C:" in the input box. After a LOT of fooling around to figure out why some specific characters could not by typed in, I came up with the following ugly solution:

Code: Select all

// Set focus to the WmWare Console windos
MyRepo.MyForm.MyScreen.Self.Click();

// Press the WINDOWS+R sequence to open the EXECUTE box in WIndows
Keyboard.Down(System.Windows.Forms.Keys.LWin, Keyboard.DefaultScanCode, true);
Keyboard.Press(System.Windows.Forms.Keys.R, Keyboard.DefaultScanCode, Keyboard.DefaultKeyPressTime, 1, true);
Keyboard.Up(System.Windows.Forms.Keys.LWin, Keyboard.DefaultScanCode, true);

// Enter command to execute
Delay.Milliseconds(500);
for (int Pos=0; Pos<Cmd.Length; Pos++) {
	Keyboard.Press(Cmd[Pos], false);
       	Keyboard.Up(System.Windows.Forms.Keys.ControlKey, Keyboard.DefaultScanCode, true);
       	Keyboard.Up(System.Windows.Forms.Keys.ShiftKey, Keyboard.DefaultScanCode, true);
       	Keyboard.Up(System.Windows.Forms.Keys.Alt, Keyboard.DefaultScanCode, true);
       	Keyboard.Up(System.Windows.Forms.Keys.LControlKey, Keyboard.DefaultScanCode, true);
       	Keyboard.Up(System.Windows.Forms.Keys.LShiftKey, Keyboard.DefaultScanCode, true);
       	Keyboard.Up(System.Windows.Forms.Keys.LWin, Keyboard.DefaultScanCode, true);
       	Keyboard.Up(System.Windows.Forms.Keys.RControlKey, Keyboard.DefaultScanCode, true);
       	Keyboard.Up(System.Windows.Forms.Keys.RShiftKey, Keyboard.DefaultScanCode, true);
       	Keyboard.Up(System.Windows.Forms.Keys.RWin, Keyboard.DefaultScanCode, true);
}
This works, however it is very slow and ugly, can anyone can explain me why I get this weird behavior in this input box, and not in other places?

lucian.teodorescu
Posts: 82
Joined: Fri Oct 24, 2014 10:58 am
Location: Bucharest

Re: Strange behavior when entering text

Post by lucian.teodorescu » Thu Jun 11, 2015 1:11 pm

How do you pass Cmd?
What is it's value? I mean, if you pass it as a string parameter, with value "C:\Temp\hello.bat" it's OK.
If you assign the value in your code, then it should be like Cmd="C:\\Temp\\hello.bat";

Anyway, I've copy-pasted your first (nice and clean) code in one empty module and it worked (directly on my Windows OS).
Lucian Teodorescu
NetSun Software

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

Re: Strange behavior when entering text

Post by krstcs » Thu Jun 11, 2015 1:29 pm

Yeah, you need to remember that the backslash ("\") in a string is used to escape the next character. If you want a LITERAL backslash, then you need to escape it with another backslash like: "\\". If you have:

C:\Test\MyApp.exe

Windows will type "C:" and then hit "\T" and think that is a 'TAB' character, so it will move your focus to the next tab target.
Shortcuts usually aren't...

jackrabbit
Posts: 47
Joined: Wed Mar 18, 2015 10:06 pm

Re: Strange behavior when entering text

Post by jackrabbit » Thu Jun 11, 2015 3:16 pm

My \ was part of a parameter, so I did not have to escape it.

To experience the problem, you must run this test either thru the console of WmWare ou thru a RDP connection. If you try to launch an application locally on your computer, it will work fine.

Trick: manually open a WmWare console window, or a Remote Desktop, make sure you see new new desktop. Make sure the first action in your test is a click to the new Console window to set the focus to it. When you attempt to "execute" a command on this remote machine, you should see the bug.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Strange behavior when entering text

Post by Support Team » Fri Jun 12, 2015 8:22 am

Hi Jackrabbit,

Your first code works as expected on my environment.
I'm connected to a VM using mRemoteNG and my Solution is built as shown in the following screenshots
screen1.png
screen2.png
May I ask you to provide your complete solution to debug the problem in more detail?
Thank you,

Regards,
Markus (S)
You do not have the required permissions to view the files attached to this post.

jackrabbit
Posts: 47
Joined: Wed Mar 18, 2015 10:06 pm

Re: Strange behavior when entering text

Post by jackrabbit » Mon Jun 15, 2015 3:42 pm

I retried using your exact example and I get the same result.

If line 1 selects my local desktop, the C:\Temp is correctly opened.

However, if line 1 selects the Console of an opened VM in vSphere from VmWare, only "C:" is written, so it opens the root folder of drive C.

Anyone has access to vSphere from VmWare to see if they get the same results using Support Team's code?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Strange behavior when entering text

Post by Support Team » Fri Jun 19, 2015 12:59 pm

Hi Jackrabbit,

I'm afraid that this problem is related to the VMWare application. I found a posting in an German forum that the ALT GR key is not correctly mapped in the virtual environment.

May I ask you if it is possible to use another application for your vm's?

Regards,

Markus (S)

jackrabbit
Posts: 47
Joined: Wed Mar 18, 2015 10:06 pm

Re: Strange behavior when entering text

Post by jackrabbit » Fri Jun 19, 2015 2:15 pm

Unfortunately no, I guess I will need to use my special function to send any text to the VM.