microsoft / WinAppDriver

Windows Application Driver
MIT License
3.7k stars 1.4k forks source link

Create session and get screenshot error if start WinAppDriver by Windows Service #1772

Open zhou9584 opened 2 years ago

zhou9584 commented 2 years ago

Start WinAppDriver

  1. Add path of WinAppDriver to PC environment
  2. Register WinAppDriver as a service of Windows by this command: sc create WinAppDriver binPath= "cmd.exe /c start WinAppDriver.exe 4725/wd/hub" start= auto
  3. Start WinAppDriver service image

Use WinAppDriver by REST API

Scenario 1: Create root session

image Meet error when get screenshot image

Scenario 2: Create WinApp session

image

anunay1 commented 2 years ago

What are you trying to achieve?

zhou9584 commented 2 years ago
  1. Our team build a mobile test infrastructure to support UI automation test triggered by Azure DevOps Pipeline.
  2. Our main process was registered as a Windows service because we want to make sure it can be restarted after restarting Windows.
  3. The infrastructure use Appium to support Android, iOS··· And the process of Appium will be started by the main process.
  4. Recently, we are going to support a testing scenario that operate Windows App and Android App at the same time. When we try to run it, the error happened.
  5. We tried to modify the Log On property of Windows Service, but it didn't work.
anunay1 commented 2 years ago

if you are using azure pipeline there is a task to start and stop winappdriver. Also appium supports windows automation using winappdriver under the hood.

ChristoWolf commented 2 years ago

Windows services run in session 0, which is non-interactive/headless. This means that you cannot do any UI/visual interactions, because there is nothing to interact with. Out of interest, why do you want to run it as a service?

zhou9584 commented 2 years ago

Windows services run in session 0, which is non-interactive/headless. This means that you cannot do any UI/visual interactions, because there is nothing to interact with. Out of interest, why do you want to run it as a service?

Thanks for your comment. We build a mobile test infrastructure, and the architecture of the infrastructure is 1 center -> n agents. The agents are used to run test cases. We want to register the main process of agents as a Windows service to make sure it can be started automatically after PC rebooting caused by system update or other reason.

zhou9584 commented 2 years ago

if you are using azure pipeline there is a task to start and stop winappdriver. Also appium supports windows automation using winappdriver under the hood.

We want to decouple the test infrastructure with ADO and the ADO will not connect with our agents directly. The ADO can trigger a test task in test center by Gradle plugin or ADO extension. Then, the center distributes task to targeted agents.

zhou9584 commented 2 years ago

2. WinAppDriver

BTW, the WinAppDriver will started by the main process of agents, so it will be a child process of Windows service

ChristoWolf commented 2 years ago

By agent do you mean an Azure pipelines agent? AFAIK the agent service can instead also be run (and should be if you want to do UI automation) as an interactive process (i.e. headful).

If this is not possible or not what you want, you can simply let the agent configure a startup script which automatically starts WinAppDriver.