Search code examples
seleniumwindows-10virtual-machinemicrosoft-edgeselenium-edgedriver

Why does Edge/Selenium throw an error when disconnected from the Windows 10 virtual machine hosting the node?


I'm struggling to set up a scalable solution for supporting Selenium Edge testing. Firstly, Edge cannot run as a Windows service. Secondly, only a single test instance of Edge can be run on a machine at a time. And now thirdly, when using a virtual Windows 10 machine to host the node and Edge the tests fail when the remote desktop session is disconnected.

Here is the error that occurs when the Remote Desktop Connection to the Windows 10 virtual machine is disconnected (but the user is still logged into the VM):

Result Message: Initialization method SeleniumTests.LeftNavigationTests.Init threw exception. System.InvalidOperationException: System.InvalidOperationException: A window size operation failed because the window is not currently available.

The problem only occurs when a remote session is not active. The tests run fine when connected.

Has anyone seen this issue before and found a way past it? Any help would be greatly appreciated!

System Info:

  • Windows 10 Virtual Machine: Version 10.0.15063 Build 15063
  • Microsoft Edge 40.15063.674.0
  • Microsoft EdgeHTML 15.15063
  • Microsoft Web Driver: 15063
  • Selenium: 3.12.0
  • The Selenium node is being run in a console window on the Windows 10 VM.

Solution

  • It looks like this is how Edge is currently designed. The browser no longer works in the same way when the desktop is inactive . Much like applications going into active memory in a life-cycle.

    The only fix I found is running a batch file which leaves your session active, while kicking you out of the remote session as if another user was trying to start a new remote session. Here are the contents of the batch file.

    Create a batch file with this code called DisconnectRDP and run as administrator:
    for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
      %windir%\System32\tscon.exe %%s /dest:console
    )
    Create a desktop shortcut to this file. To do this, right-click the batch file and select Send to | Desktop (create shortcut).
    In the shortcut properties, click Advanced and select Run as administrator.
    

    If you are having issues with the desktop locking you can try altering the following settings in the registry.

    1. Open the registry (do a local Windows Search for regedit)
    2. Navigate to the following folder in the registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
    3. Set AutoAdminLogon to 1
    4. Set the DefaultDomainName if required
    5. Set the DefaultUserName
    6. Create DefaultPassword and set as appropriate

    Another issue is that Edge only seems to support a single Selenium session at a time. This makes it difficult to scale testing.