microsoft / WinAppDriver

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

Cannot open my android application through Appium script in Windows 11 #1778

Open akashp1712 opened 2 years ago

akashp1712 commented 2 years ago

I'm using Windows 11 and a beta user of WSA to test Android Application on Windows. I've side-loaded my APK and want to launch it using Appium script but it couldn't as the WinAppDriver fails to recognise the App ID. (com.example.activitylifecycle)

I found the App Id of my app using, get-StartApps command.

Following is my code in python

from appium import webdriver

desired_caps = {}
# desired_caps["app"] = "Microsoft.WindowsCalculator_8wekyb3d8bbwe! # works fine

# desired_caps["app"] = "C:\\Windows\\System32\\notepad.exe" # works fine

# desired_caps["app"] = "6b741bb2-3e37-441b-8b45-37f9de33dd9f_wkk6 # works fine

desired_caps["app"] = "com.example.activitylifecycle" # doesn't work

# desired_caps["platformName"] = "Windows"
# desired_caps["deviceName"] = "WindowsPC"

driver = webdriver.Remote("http://127.0.0.1:4723", desired_caps)

And when I run the test, I get below error in WinAppDriver console

POST /session HTTP/1.1
Accept: application/json
Accept-Encoding: identity
Connection: keep-alive
Content-Length: 167
Content-Type: application/json;charset=UTF-8
Host: 127.0.0.1:4723
User-Agent: appium/python 2.2.0 (selenium/4.4.3 (python windows))
X-Idempotency-Key: 52b8c399-2ff4-417b-a69f-0628e9d8fdc8

{"capabilities": {"alwaysMatch": {"appium:app": "com.example.activitylifecycle"}, "firstMatch": [{}]}, "desiredCapabilities": {"app": "com.example.activitylifecycle"}}
HTTP/1.1 500 Internal Error
Content-Length: 102
Content-Type: application/json

{"status":13,"value":{"error":"unknown error","message":"The system cannot find the file specified."}}

I'm using Appium_Python_Client==2.2.0 in my project and using the latest version of WinAppDriver (1.2.99).

Please let me know if there is any other way to launch the Android App Or the WinAppDriver doesn't offer support for it yet.

anunay1 commented 2 years ago

Why do you want to use windows sub system? just start Appium server it will do the job.

akashp1712 commented 2 years ago

I want to test my Android Application to see what happens when user maximize/minimize/restore the app window. This is specific to Window action, and it can be done using adb commands.

I can still start the Android App using adb command, but would require app handle for window manipulation. So is there a way I can get the WinAppDriver session using App Title ?

pdisser8 commented 2 years ago

@akashp1712 So from a quick look at the WSA documentation, you probably want to launch the Amazon Appstore app and then open your android app from there via clicks. I can't imagine you'll be able to do much more than that via WinAppDriver unfortunately because I assume the android app will be abstracted from windows inspector tools and you'll only be able to interact with the top level window and not the actual android emulation. This is an interesting use case though

akashp1712 commented 2 years ago

Thanks Paul @pdisser8 for the suggestion. I feel the proper support from WinAppDriver might come in the future when more n more developers start building apps for Windows.

And for my use-case, I've managed to automate the window using win32 APIs via python, I'm analysing logs for any crashes while manipulating the window.