Appium: Windows system desktop application automation testing (2)

1. About the problem that the application is opened during the automation process, but the operation handle cannot be obtained

1. Problem description

(1) The figure below shows different applications connected through python scripts

(2) Application 1: There is a sessionId, indicating that the session is normal, and the application can be operated through the handle

(3) Application 2: report 500 error

(4) Error log

HTTP/1.1 500 Internal Error
Content-Length: 199
Content-Type: application/json

{"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: C:\\Program Files (x86)\\IDMVS\\Applications\\Win64\\IDMVS.exe, and processId: 39628"}}

2. Problem Analysis

(1) Network topology diagram

①The application, WinAppDriver, and python scripts are all on the same PC, and their relationship is as follows:

python script (client) "==" WinAppDriver (server) "==" application

②Take opening an application as an example, firstly, the client sends a request to start the application to the server, then the server opens the application, then the application gives feedback to the server, and finally the server gives the client an operation handle

③ What is the cause of the problem? The server reported a 500 error, and then fed back to the client to forward the information as follows:

selenium.common.exceptions.WebDriverException: Message: Failed to locate opened application window with appId: C:\Program Files (x86)\IDMVS\Applications\Win64\IDMVS.exe, and processId: 27104

④The application is opened, but the application cannot be located

(2) Reason analysis

①It may be that the application refused to give feedback to the server, and the server reported a 500 error because it could not wait for the result

② In a short period of time, if the server fails to capture the application feedback, the session has ended

③The server does not have permission to capture the application

④ Software path related

3. Problem solving

①Experiment 1: Open the software in the same directory of the software, the handle is normal, and it is considered to have nothing to do with the software path

②Experiment 2: Run the server as an administrator, but fail to obtain it, thinking that it has nothing to do with the permissions of the server

③Experiment 3: Extend the timeout wait through the python script, and the acquisition fails, which is considered to have nothing to do with the application feedback time

(PS: The remaining object of suspicion is the application itself, which is a bit helpless. We can only continue to experiment and try to troubleshoot)

④Experiment 4: Run appium as the client as an administrator, try to solve it, the error message is consistent with the python script

 ⑤Experiment 5: Use appium as the client to solve it by changing the configuration parameters, and it fails again

For configuration parameter documentation, see the link below:

appium/appium-windows-driver (github.com)https://github.com/appium/appium-windows-driver#windowsdriver-specific-capabilities

  ⑥Experiment 6: Reinstall, even replace the WinAppDriver of X86, and then run, all fail

2. Try to return to the problem itself to solve the problem

1. Target application log

Re-run the script, no new logs are generated, so no useful information can be obtained through it

 2. Try to solve the problem by checking the system log that comes with the win system

operation script, still no log generated

 

3. View the WinAppDriver log

(1) When only app parameters are given, the following error is reported

{"capabilities": {"alwaysMatch": {"appium:app": "C:\\Program Files (x86)\\IDMVS\\Applications\\Win64\\IDMVS.exe", "appium:deviceName": "WindowsPC", "platformName": "Windows"}, "firstMatch": [{}]}, "desiredCapabilities": {"app": "C:\\Program Files (x86)\\IDMVS\\Applications\\Win64\\IDMVS.exe", "deviceName": "WindowsPC", "platformName": "Windows"}}
HTTP/1.1 500 Internal Error
Content-Length: 199
Content-Type: application/json

{"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: C:\\Program Files (x86)\\IDMVS\\Applications\\Win64\\IDMVS.exe, and processId: 27968"}}

(2) When adding the parameter "ms:waitForAppLaunch":5, the following error is reported

①Sometimes the following error is reported

{"capabilities": {"alwaysMatch": {"appium:app": "C:\\Program Files (x86)\\IDMVS\\Applications\\Win64\\IDMVS.exe", "ms:waitForAppLaunch": 5}, "firstMatch": [{}]}, "desiredCapabilities": {"app": "C:\\Program Files (x86)\\IDMVS\\Applications\\Win64\\IDMVS.exe", "ms:waitForAppLaunch": 5}}
HTTP/1.1 400 Bad Request
Content-Length: 131
Content-Type: application/json

{"status":23,"value":{"error":"no such window","message":"Cannot find active window specified by capabilities: appTopLevelWindow"}}

②Sometimes the error reported is the same as (1)

(3) The new "appArguments" parameter reported the following error

{"capabilities": {"alwaysMatch": {"appium:app": "C:\\Program Files (x86)\\IDMVS\\Applications\\Win64\\IDMVS.exe", "ms:waitForAppLaunch": 5, "appium:appArguments": "C:\\Users\\yeqinfang\\Desktop\\\u4e34\u65f6\u6587\u4ef6\\log.txt"}, "firstMatch": [{}]}, "desiredCapabilities": {"app": "C:\\Program Files (x86)\\IDMVS\\Applications\\Win64\\IDMVS.exe", "ms:waitForAppLaunch": 5, "appArguments": "C:\\Users\\yeqinfang\\Desktop\\\u4e34\u65f6\u6587\u4ef6\\log.txt"}}
HTTP/1.1 500 Internal Error
Content-Length: 199
Content-Type: application/json

{"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: C:\\Program Files (x86)\\IDMVS\\Applications\\Win64\\IDMVS.exe, and processId: 28380"}}

(4) Adding the officially specified parameter createSessionTimeout is useless, and the error reported is the same as (1)

3. Is it possible that the application is not supported by winappdriver?

①Applications currently supported by the drivers we use

  • UWP  -  Universal Windows Platform

  • WinForms  -  Windows Forms

  • WPF  -  Windows Presentation Foundation

  • Win32  -  Classic Windows

②View the application type

There is no related method, can't figure it out

4. The difference between manual opening and WinAppDriver opening

open manually

WinAppDriverOpen

 (1) What does this discovery indicate?

It means that the program has not been opened correctly! So how to use the script to open it correctly?

①Experiment 1: Open the program directly through the "os.system()" module of the python project (virtual environment), but it is not opened correctly!

②Experiment 2: Use the system python environment to execute "os.system()" to open the program, but it still does not open correctly!

③Experiment 3: Run the exe program directly through the cmd command, and open it correctly!

(2) It is suspected to be related to the working directory

Add the "appWorkingDir" parameter to connect to the application, and found that it can be opened correctly, but it still fails to obtain the handle!

3. Considering many aspects, I decided to abandon this plan

1. Reason 1: The above situation shows that under certain reasons, the connection reference will be abnormal

2. Reason 2: appium does not support winappdriver well enough. It cannot be used after version 2.0.0. Only version 1.3.0 or below will have better support.

3. Reason three: The interface provided by winappdriver is actually not rich, which may also be the reason why it was abandoned by appium

4. Reason four: There is a better alternative in python, that is the pywinauto module!

Guess you like

Origin blog.csdn.net/weixin_43431593/article/details/124299851