Linked Questions

Popular Questions

I am using openssh to provide the python command to run in powershell. The python script being a UI test script tries to launch the application UI. The application starts as a background process and fails to load on the UI and hence the rest of my test script fails. I tried using paramiko, pywinrm, pypsexec, etc. All fails at the same point. I used all python packages since the CI framework is written in python and it handles reservation of machines, setting up machines and providing the above python command etc via python code.

I tried running it manually which yields the same result:

ssh myuser@<win10_machine_ip> python C:\path\to\myscript.py

Is there any other way other than ssh to connect to remote windows machine UI via python code? I am stuck at this point.

a) Using winrm

import winrm
session = winrm.Session(remote_machine,
        auth=(username, password),
        transport='ntlm')
command = "python C:\path\to\myscript.py"
command_result = session.run_ps(command)

b) Using paramiko

import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host, username=username, password=password)
command = "python C:\path\to\myscript.py"
stdin, stdout, stderr = ssh_client.exec_command("powershell.exe -Command {}".format(cmd))
print(stdout.read().decode('utf-8')

c) Using pypsexec

from pypsexec.client import Client
c = Client("my_machine_ip", username="myuser", password="mypassword")
c.connect()
c.create_service()
stdout, stderr, rc = c.run_executable("cmd.exe",
                                       arguments="/c python C:/Users/user/framework/executetests.py -d staging -s serverconnectionui_win 21581411 -i test1")

I was expecting the ui test to run without any issues

Related Questions