Java Robot Code does not work when remote desktop window is not active - selenium

I'm running some selenium tests on a amazon cloud machine. My web application has a flash area where i'm simulating a keyboard type and click using java robot code (also tried auto it script to simulate user click and type on the flash area) . The code works when i connect to the server using remote desktop and the remote desktop window is active, but when i minimize the remote desktop window, the java robot code does not work?
Robot robot = new Robot();
robot.delay(5000);
robot.mouseMove(400, 400);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(2000);
robot.keyPress(KeyEvent.VK_H);
robot.keyPress(KeyEvent.VK_I);
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyPress(KeyEvent.VK_B);
robot.keyPress(KeyEvent.VK_U);
robot.keyPress(KeyEvent.VK_D);
robot.keyPress(KeyEvent.VK_D);
robot.keyPress(KeyEvent.VK_Y);

Issue is not with the scripts, but with the host machine's GUI settings for remote machine. To fix this, perform the following steps on the computer from which you are connecting to a remote workstation :
Configuration for current user only:
Run the regedit.exe tool.
Find the registry key HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client.
Create a DWORD value with the name RemoteDesktop_SuppressWhenMinimized and set its value to 2.
Now find the registry key HKEY_CURRENT_USER\Software\Wow6432Node\Microsoft\Terminal Server Client.
Create a DWORD value with the name RemoteDesktop_SuppressWhenMinimized and set its value to 2.
Close the regedit.exe tool.
Configuration for all users:
Run the regedit.exe tool.
Find the registry key HKEY_LOCAL_MACHINE\Software\Microsoft\Terminal Server Client.
Create a DWORD value with the name RemoteDesktop_SuppressWhenMinimized and set its value to 2.
Find the registry key HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Terminal Server Client.
Create a DWORD value with the name RemoteDesktop_SuppressWhenMinimized and set its value to 2.
Close the regedit.exe tool.
Now when you minimize the Remote Desktop Connection window on your computer, this will not affect the remote computer’s GUI and the GUI will be available to your interactive tasks.

I installed UltraVNC Server and connected using VNC client. The problem is not observed and the robot works even after disconnecting. Below is the exact steps:
Login to the remote machine using Windows Remote Desktop tool.
Install UltraVNC server as a Windows service.
Log off from the system (you are still within the remote desktop tool).
Now using VNC viewer, connect to the system.
You will be shown the login screen. You can login to the system using vnc viewer now.

Thanks, Daniel,
This resolved the issue we had while running a Synthetic Scenario where we need to use Robot Framework to perform some mouse clicks while the RDP Session is minimized.
Best Regards,
Buddhika.
Germain UX: Custom Insights, Alerts, and Automation platform to improve User Experience

Related

How can I emulate pressing CTRL+ALT+PAUSE in my Linux VM using AutoKey?

Question:
How can I emulate pressing CTRL+ALT+PAUSE in my Linux VM using AutoKey?
I tried a script that has
keyboard.send_keys("<ctrl>+<alt>+<pause>")
in it. But it does not work.
Background:
I'm using Windows 10 and RDP to log into a Fedora Linux. Switching 100 times a day.
The RDP connection runs in Windows all the time.
If the RDP window is not in the background but active, I can press CTRL+ALT+PAUSE to go into the VM (Fullscreen). If I am inside the VM I can press CTRL+ALT+PAUSE to go back to Windows.
So far so good. I want only one button. Preferably PAUSE. Windows part is ready already with following script
Pause::
If !WinExist("RDP Tool Name")
MsgBox No Window found
WinShow, RDP Tool Name
WinActivate, RDP Tool Name
Send ^!{CtrlBreak}
Return
Is the Linux part maybe not possible because the key combination is cached somewhere before my Linux system can even notice it? Any ideas?
I solved it without any other new script. I just had to edit the RDP settings: Keyboard -> Use Windows-Hotkeys -> On this Computer

Disable grabbing alt+tab in Citrix

(I used to use NX client, which does not grab Alt + Tab, so with NX I could to switch windows with Alt + Tab on my host OS only, which is prefered for me.)
I had to switch Citrix, which grabs this (alt-tab) keys (only in fullscreen mode) so if Citrix is active I cannot switch to any other host window (using keys), which is not preferred for me.
I want to switch windows with Alt + Tab on my host OS only.
My Citrix host is Win7, guest is a RH6. Version is 4.9
Symptoms or Error
Executing ALT+TAB keys toggles opened applications on endpoint machine instead of desktop session
Solution
Launch Regedit.exe on the client device to edit the registry
For Windows 32-bit OS, navigate to the key
HKEY_LOCAL_MACHINE \SOFTWARE\Citrix\ICAClient\Engine\Lockdown Profiles\All Regions\Lockdown\Virtual Channels\Keyboard\
For Windows 64-bit OS, navigate to the key
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Citrix\ICA Client\Engine\Lockdown Profiles\All Regions\Lockdown\Virtual Channels\Keyboard\
In some cases configuring User based Setting also helps:
HKEY_CURRENT_USER\SOFTWARE\Citrix\ICAClient\Engine\Lockdown Profiles\All Regions\Lockdown\Virtual Channels\Keyboard\
Value Name TransparentKeyPassthrough
Value Type REG_SZ
Value Remote
The Value "Remote" will enable it and blank will disable it
This made Alt-Tab switch consistently on the host, for me:
(both in Window mode and Full-screen mode)
In registry, within:
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Citrix\ICA
Client\Engine\Lockdown Profiles\All Regions\Lockdown\Virtual
Channels\Keyboard
I changed:
TransparentKeyPassthrough = Local
(was empty)
Win10, 64-bit, Citrix Workspace 19.3.0.4

Setting display resolution for Selenium tests on virtual machine as Jenkins Slave

I'm having trouble running some Selenium tests on a Jenkins Slave. To be specific, the display resolution that is used to run the tests is too small, causing some of the tests to fail.
To check the display resolution, we log the display height and width to the console, using:
driver.manage().window().maximize();
System.out.println("Window height: " + driver.manage().window().getSize().getHeight());
System.out.println("Window width: " + driver.manage().window().getSize().getWidth());
This returns:
Window height: 784
Window width: 1040
which seems like a very strange resolution to me. The desired resolution is 1920 x 1080.
The server that is used as a slave is a virtual machine (Windows Server 2012 R2). The Jenkins Slave is Connected via JNLP agent. The slave has the service running with Log On As "Local System" with the "Allow service to interact with desktop" option enabled.
So far we've tried a number of things like:
Connecting to slave VM using RDP and disconnecting to leave session open with desired display resolution
Using powershell to set the display resolution
Setting the default display resolution in the VM configuration
Setting the window dimensions using Selenium
And more...
All of these didn't resolve the issues. Suggestions are very welcome!
Finally managed to fix these issues after realizing that Jenkins does not necessarily need to run the slaves as a windows service. To start the slave, the JNLP agent can be downloaded from Jenkins and copied to the server. When running the JNLP file, you can select for the option to install the slave agent as a service.
Previously we had this option selected, that's why the slave was running as a service. After stopping and removing the service, we ran the JNLP file again and made sure to not select the option.
The solutions suggested that included disconnecting the remote desktop session and leaving the session open with a large resolution didn't work when running the slave as a service. They do work however when running the slave in the default way.
Make sure that the remote desktop session is not ended after a certain period of time:
Hope this helps someone!
Based on my experience with this you can't solve this problem programmatically. Your tests will run on the resolution which was used last time when you physically accessed this VM's display. For example, if I open VM on my big screen monitor and maximize it, tests will run on that resolution. But if I open it on my laptop screen and close RDP connection, tests will run on that smaller screen size.
I know it sounds strange, but I really couldn't find better solution. :D So now I must be careful to maximize VM display on my bigger screen before I close VM. You will probably dislike this answer, but remember it when you find yourself out of other solutions. ;)
Solution that worked for me is to run Chrome in a 'headless' mode (without GUI). It works with Jenkins Agent running as a service, when GUI is not available.
Here is the code sample of the web driver initialization:
var options = new ChromeOptions();
options.BinaryLocation = #"C:\Program Files\Google\Chrome\Application\chrome.exe";
options.AddArgument("Headless");
options.AddArgument("window-size=1920,1080");
driver = new ChromeDriver(#"<path>\Selenium.WebDriver.ChromeDriver.2.37.0\driver\win32", options);
I've been experienced the same issue. My seleniumn tests run under jenkins slave installed as windows service, using "Local System" account with "Allow service to interact with desktop" option enabled in windows 7. Some test cases were always failed due to incorrect display resolution.
I logged in to the console of the windows VM (EXSI Server + VMware Fusion), changed the resolution to 1400x900, and restart the windwos VM. Everything works well now.

How to configure a Windows Server 2008 VM to run with a specific resolution

I have a build server running Windows Server 2008 R2. It runs a suite of automated acceptance tests which use the Selenium web driver. These tests are triggered automatically after a check-in and are failing due to having too small of a screen resolution. They are unable to access elements that are in a modal window because the modal window is too big to fit within the limited viewport that the tests are running in.
If I RDP into the machine at 1280 x 1024, I can run the tests and see that they pass just fine. Is there a way to specify the "default" resolution for a windows box when a user isn't actually logged in with a monitor?
Thanks!
I found a link, it looks like you can set your desired resolution with regedit: http://philipflint.wordpress.com/2008/06/30/changing-the-screen-resolution-in-windows-server-2008-server-core/
From the URL:
HKLM\System\CurrentControlSet\Control\Video\{ClassID}000\DefaultSettings.XResolution
HKLM\System\CurrentControlSet\Control\Video\{ClassID}000\DefaultSettings.Yresolution
The ClassID is a GUID. There is one for each display driver installed on your system. You can tell which one is currently in use as below the 0000 Key you will have another Key called “Volatile Settings”.

can we execute QTP script on remote machine by keeping session minimized

I have couple of machines on which I wish to schedule exceutions. I need to access these machines remotely for exceution. Whenever I start exceution from these machines and minimize the session my script fails. So just curious to know whether QTP scripts can be executed while keeping sessions minimized. If yes what changes needs to be made in script. Thanks.
When you minimize this window, the operating system switches the remote session to a GUI-less mode and does not display windows and controls. As a result, the tests are unable to interact with the tested application’s GUI as the GUI doesn’t actually exist in this case.
You need to change Registry keys on your computer (that is, the computer from which you connect to a remote QTP workstation). Here is a step-by-step description:
Close Remote Desktop sessions opened on your computer.
Click Start and select Run. In the Run dialog box, type regedit and press Enter. Registry Editor starts
Locate any of the following Registry keys:
HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\
(if you want to change the RDC settings for your user account)
-- or --
HKEY_LOCAL_MACHINE\Software\Microsoft\Terminal Server Client\
(if you want to change the RDC settings for all accounts)
Create a new DWORD value in this key named RemoteDesktop_SuppressWhenMinimized. Specify 2 as the value data.
That’s all. Now minimizing the Remote Desktop Connection window on your computer will not affect the remote computer’s GUI and the GUI will still be available to your automated GUI tests.
This was taken from: http://blog.smartbear.com/post/10-10-11/testcomplete-tip-running-tests-in-minimized-remote-desktop-windows/
The problem you're facing is that if you minimize your display the remove machine knows that it doesn't have a display and ignores any questions about control locations and requests to move the mouse. In some cases QTP runs tests using device replay which means that the test will fail.
To work around this you need to have the remote machine think that it still has someone attached to it. One way is (obviously) to not minimize or close the remote desktop session. Another way is to use a remote access program that doesn't inform the remote machine when it's minimized a free example of such program is VNC, if I remember correctly you can even close the VNC session (not just minimize it) and the test will still run successfully.