xiaocong / uiautomator

Python wrapper of Android uiautomator test tool.
MIT License
2.04k stars 644 forks source link

Not connecting to device, and runs indefinitely / RPC server not started #248

Open craftpip opened 6 years ago

craftpip commented 6 years ago

Adb output:

adb devices
List of devices attached
ZY2243GTVC      device

And script:

from uiautomator import Device

d = Device('ZY2243GTVC')
print(d.dump()) # this line is not executed. the script keeps running

I tried first with a AVD that worked perfectly, but i'm facing this problem on using a physical device.

Please help, Thanks

craftpip commented 6 years ago

After some debugging, found error comes in @ uiautomator/init.py @ 423 where e is

('Connection aborted.', ConnectionAbortedError(10053, 'An established connection was aborted by the software in your host machine', None, 10053, None))

What could cause this ?

craftpip commented 6 years ago

The program gets stuck @ line 425

   except (URLError, socket.error, HTTPException) as e:
                    if restart:
                        server.stop()
                        server.start(timeout=30) # <- here
                        return _JsonRPCMethod(url, method, timeout, False)(*args, **kwargs)
                    else:
craftpip commented 6 years ago

UPDATE: I was trying to connect to a non-rooted phone, Motorola g5 plus @ Android 6 But successfully connected to a rooted phone, Motorola g2 @ Android 4.4

I haven't seen in the documentation that uiautomator requires root privileges ?

craftpip commented 6 years ago

UPDATE: Went through the previous issues, found https://github.com/xiaocong/uiautomator/issues/210#issuecomment-292842129

@snakeli suggests to

change "self.adb.cmd("install", "-r -t", os.path.join(base_dir, apk)).wait()" to "self.adb.cmd("install", "-r", "-t", os.path.join(base_dir, apk)).wait()" in init.py

Which solves my problem. However i would like to know what difference it makes in "-r -t" and "-r" "-t" ?

craftpip commented 6 years ago

MORE REFERENCES: https://github.com/xiaocong/uiautomator/issues/203 https://github.com/xiaocong/uiautomator/pull/188 https://github.com/xiaocong/uiautomator/commit/57ba9333186cc2c748fce8596dd31593a28019a9

kotlinski commented 6 years ago

I'm having problem with an old phone Android API 18, works about 75% of the tries. The traceback points at a line doing .wait.exists

YuvrajIndiaGold commented 1 year ago

Hey @craftpip i am facing the same issue (RPC server not started ) and i am not able to resolve this , can you please help me out.