pywin32 / pywinauto not working properly in remote desktop when it is minimized

前端 未结 2 1858
耶瑟儿~
耶瑟儿~ 2021-01-15 13:58

I have a Jenkins pipeline that executes a program in a remote server that uses pywin to manipulate an application for functional tests.

My application works great wh

相关标签:
2条回答
  • 2021-01-15 14:22

    If I understand your problem, which is mine also, correct answer can be found there:

    https://support.smartbear.com/testcomplete/docs/testing-with/running/via-rdp/keeping-computer-unlocked.html

    (This link comes from this page: Remote Execution Guide in pywinauto)

    And exact process to follow such as described in the page:

    To disconnect from Remote Desktop, run the following command on the remote computer (in the Remote Desktop window) as an Administrator:

    %windir%\System32\tscon.exe RDP-Tcp#NNN /dest:console

    where RDP-Tcp#NNN is the ID of your current Remote Desktop session, for example, RDP-Tcp#0. You can see it in the Windows Task Manager on the Users tab, in the Session column.

    You will see the “Your remote desktop session has ended” message, and the Remote Desktop client will close. But all programs and tests on the remote computer will continue running normally.

    I am just testing it and works without problem.

    0 讨论(0)
  • 2021-01-15 14:24

    UPD: all practices listed below are compiled into Remote Execution Guide which may be more up-to-date.

    The problem with Remote Desktop doesn't depend on the tool. The RDP itself doesn't keep GUI context when it's minimized or disconnected (the same effect takes place when the OS is locked). But the symptoms usually involve .click_input() and .type_keys() / keyboard.SendKeys() methods that are not working without GUI context.

    The workarounds for minimized RDP problem:

    1. Switch RDP to windowed mode (non full screen), run the script there and quickly switch to local machine. Now you can work normally. This is the simplest way for manual run.

    2. Install VNC server software on remote machine (I used TightVNC) and VNC client (also TightVNC) on local one. You may require updating video card drivers on remote machine if you see black screen. You also must reboot remote host if RDP was used at least once. The main benefit: you can even disconnect from remote host but TightVNC will always keep GUI context. This is more suitable for automatic runs (Jenkins agent must run in this active desktop, it can't be run as a service at all). Another virtual desktop environment like Citrix might be OK for this purpose, but I have no personal experience with that.

    3. RDP (mstsc command) has some parameter to unbind virtual remote desktop from current connection (don't remember right now). Additional tools for automatic remote run may include psexec or Ansible with psexec plugin.


    If the main window is not found for this application (process PID) maybe saplogon.exe spawns another process with the target window. Then you have to do app = Application().connect(title="SAP Logon 740", timeout=10) to bind with correct process ID. This is pretty common problem for such launchers.


    ctypes.ArgumentError is more interesting. Please provide the full traceback of the error. I suspect this can be fixed on pywinauto side. This kind of error may happen because other Python libraries use ctypes incorrect way, but it can be workarounded probably.


    If LogOn button can't be found using default "win32" backend, you may try Application(backend="uia").connect(...). The difference is explained in the Getting Started Guide.

    0 讨论(0)
提交回复
热议问题