问题
I am having a setup where web Application in my PC is accessing the app info running on the connected device.(through USB debugging). and continuously sends the app data to the Web Application(PC).
I am automating this using selenium(web GUI) and appium(device) for my automation testing..
Issue: I am unable to connect to the device from uiautomator.bat tool once the app is getting launched in the device and communicating with the Web app(In my PC). Getting the below error. Is there a workaround for this issue.
--------uiautomator.bat log-----------
C:\Users\sat_yug\android-sdks\tools>uiautomatorviewer.bat 03:57:35 E/DeviceMonitor: Adb connection Error:An existing connection was forcibly closed by the remote host 03:57:36 E/DeviceMonitor: Connection attempts: 1 03:57:38 E/DeviceMonitor: Connection attempts: 2 03:57:40 E/DeviceMonitor: Connection attempts: 3 03:57:42 E/DeviceMonitor: Connection attempts: 4 03:57:44 E/DeviceMonitor: Connection attempts: 5 03:58:04 E/DeviceMonitor: Adb connection Error:An existing connection was forcibly closed by the remote host
------------adb devices log---------------------
C:\Users\sat_yug\android-sdks\platform-tools>adb devices List of devices attached adb server is out of date. killing... error: could not install smartsocket listener: cannot bind to 127.0.0.1:5037: Only one usage of each socket address (protocol/n etwork address/port) is normally permitted. (10048) could not read ok from ADB Server * failed to start daemon * error: cannot connect to daemon
回答1:
I just solved this for me so i thought i'd share even though the question is old. Simply restarting the adb is not going to work. Open a command prompt with administrator priviledges and execute this:
netstat -o -n -a | findstr 5037
This will produce a list of results. This is what came up in my case:
TCP 127.0.0.1:5037 0.0.0.0:0 LISTENING 3408
TCP 127.0.0.1:5037 127.0.0.1:50018 ESTABLISHED 3408
TCP 127.0.0.1:5037 127.0.0.1:54507 ESTABLISHED 3408
TCP 127.0.0.1:5037 127.0.0.1:63330 ESTABLISHED 3408
TCP 127.0.0.1:5037 127.0.0.1:63332 ESTABLISHED 3408
TCP 127.0.0.1:50018 127.0.0.1:5037 ESTABLISHED 1664
TCP 127.0.0.1:54507 127.0.0.1:5037 ESTABLISHED 1664
TCP 127.0.0.1:63330 127.0.0.1:5037 ESTABLISHED 1664
TCP 127.0.0.1:63332 127.0.0.1:5037 ESTABLISHED 1664
At the most right column is the process id (PID). The proccess that is listening to the needed socket is the 3408. So this process must DIE ! Which happends if you do:
taskkill /F /PID 3408
After that you can do
adb kill-server
adb start-server
to restart the adb server and most propably your adb will start successfully.
UPDATE:
I made this little bat file to make it easier since this happens quite often. Make sure
1. to place this bat at the same folder as adb.exe
2. run it as administrator.
It will directly show you the PID that is using the socket. Type that PID and hit enter and the problem goes away.
netstat -o -n -a | findstr 5037 | findstr LISTENING
set /p pid=Enter pid to kill:%=%
@echo %pid%
taskkill /F /PID %pid%
adb kill-server
adb start-server
pause
回答2:
As per the answer to THIS question, there is a possibility that you could have two versions of adb installed.
Try the following (quoted from same post to check if there are multiple versions) and get rid of the unwanted one.
where adb.exe
Another option you could try is to kill and start the adb server before the point of error or at the start of execution of your batch file.
adb kill-server
adb start-server
....
....
//your script here
....
....
回答3:
I had the same problem. Solution:
Login to adb shell from 1 machine and run
adb start-server
and now try to connect from other machine to the same device and you will be able to connect successfully!
In my case 2 connections was by: USB and wifi.
来源:https://stackoverflow.com/questions/34353756/unable-to-get-the-elements-in-uiautomator-tool-when-the-app-is-running-on-the-de