9

(I debated between posting this here, ServerFault, and StackOverFlow. Settled for this. Hopefully it's in the right place.)

We run our UI testing suite using Selenium Grid 2 with an Amazon EC2 Windows machine (that is started up in using Amazon's CloudFormation APIs). My question is, how do I change the resolution of that machine?

If I remote into it, I can specify the resolution using Remote Desktop. But obviously that doesn't permanently change the resolution. When we run our tests, the resolution is so small that the browser scrunches the elements together and causes the tests to fail.

Any ideas? Is there something I can put in the CloudFormation recipe? Is there something I can do to the image before creating the AMI?

Screenshot of Device Manager

Thanks.

Joel
  • 235

6 Answers6

5

Disclaimer: TightVNC is not secure, so if security is an issue, you may need to find a different approach. The whole process will take only a few minutes, so the security hole is small, but there nonetheless.

  1. Install TightVNC Server on the EC2 instance so you can log into the console
  2. Disconnect all user remote desktop sessions and return the session to console
  3. Use the TightVNC Viewer to log into the EC2 instance console, ensuring port 5900 is open for that connection
    • Right-click on the desktop and select "Screen resolution"
    • Select "Advanced settings"
    • Select "List All Modes"
    • Select a higher resolution
slhck
  • 235,242
2

I tried all most all above and failed. Found a solution unique for my situation which was simple ..use windows power-shell.

wrote power-shell script

Set-DisplayResolution -Width 1920 -Height 1080 -Force

name it resolution.ps1

saved in C:\myTestFolder

and run it from command line like below..... (my scripts are driven by batch files)

WindowsPowerShell\v1.0\powershell.exe C:\myTestFolder\resolution.ps1
1234
  • 121
2

You can change the screen resolution by modifying two registry values. These two values are: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Video\GUID\0000\DefaultSettings.XResolution HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Video\GUID\0000\DefaultSettings.YResolution Where GUID is a randomly generated GUID.

You can actually specify any XResolution and YResolution value as long as they are hexadecimal.

Note: In the case of a CRT monitor specifying an absurd resolution might damage your monitor. In the case of a LCD monitor your monitor might not show any user interface anymore. A good way to change your Screen resolution is to write down the amount of pixels you want to fill your screen width with (this is the XResolution) and the amount of pixels you want on your screen height (the YResolution). The Windows calculator (not available in Server Core , you will have to find another computer or a hardware advanced calculator) offers an easy way to convert decimal amounts to hexadecimal amounts. You can then use these values to modify the corresponding registry values. A restart will make your preferred screen resolution meet reality.

The color depth used on your monitor is captured in the following registry value: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Video\GUID\0000\DefaultSettings.BitsPerPel On my box this hexadecimal value was set to 0x00000008 (8) which meant my screen used an 8 bit color depth. (256 colors) Changing it to 16 bits (0x00000010) will show 65536 colors (High Colors) Other values that are typically available are 24 bits (0x00000018) and 32 bits (0x00000020).

Source

paradroid
  • 23,297
1

I was able to get this working using a combination of @kenny-trytek 's answer above and setting up auto login.

I think the VNC resolution only gets set for the current user, so setting up auto-login ensures that this user has an open session.

Setup auto login https://support.microsoft.com/en-us/kb/324737

Next, in the users Start Up folder provide a shortcut or bat file to kick off the selenium node process.

porto88
  • 11
0

Here is how I set the headless screen resolution on AWS Windows using RDP:

  • create a new user called rdp_local
  • create a startup script to RDP into a specified user account (e.g. selenium) at specified resolution
  • add a firewall rule to open RDP port 3389
  • configure auto-logon to login as rdp_local on reboot

Note that auto-logon requires a username and password and that the password is stored unencrypted under windows registry HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon.

Tested on Amazon Windows Server 2012 R2 AMI.

Here is a Chef cookbook that does the above: https://github.com/dhoer/chef-windows_screenresolution

0

Cannot put comments to the answers or vote, so creating another answer.

Thanks Kenny Trytek, your solution worked!

I am using Windows Server 2022 on AWS ec2 to run Appium tests. I have one autologged user after start of the ec2, which just starts the Appium process. When the Appium starts the GUI application, it maximizes and uses the configured resolution, which was set up via the VNC.

After setting the resolution, I have uninstalled the VNC, closed the VNC ports and made a new AMI. Now I do not have to do some fancy stuff with RDP, which did not work for me at all, and also save some resources because of it.

Other things, which I tried, but did not work. E.g. the app was spawned in good resolution, but elements were not visible/clickable, like they were out of the view in some scrollable area. List:

  • Two Windows users, one is autologged, and after login it starts an RDP session to 127.0.0.2 with precofigured resolution as another user, which on the other hand starts Appium on login. (https://outofmemoryexception.wordpress.com/2016/03/29/automate-your-remote-desktop-sessions/)
    • or a variant with one user staring Appium, and starting of the RDP is done 'manually' via Appium powershell script before running the tests, e.g.: mstsc /v:127.0.0.2 /w:1920 /h:1200 /control /admin (you need to have the credentials for that ip saved, as mentioned in the article)
  • Using powershell command Set-DisplayResolution
  • Updating registry with video resolution
  • setting window size via Appium
  • setting window size by powershell script Setting window size and position in PowerShell 5 and 6