0

Scenario: I'm attempting to ADB connect to an android phone as part of an automation framework test by using shell commands in os.popen(), I am able to connect but 'adb devices' returns the device as connected but unauthorized, example code:

def test_connect_phone(self, phone):
        connect_stream = os.popen(f'adb connect {phone.host}:{phone.port}')
        print(connect_stream.read())
        install_stream = os.popen('adb devices')
        output = install_stream.read()
        print(output)
        assert output
# output
connected to <HOST>:<PORT>

List of devices attached
<HOST>:<PORT>   unauthorized

Running the same commands directly from the terminal works and the device is authorized:

adb connect <HOST>:<PORT>
adb devices

#output
connected to <HOST>:<PORT>

List of devices attached
<HOST>:<PORT>   device

Note: I am using tox for pytest which made me think it could be an environment issue, but in testing I see during runtime my home dir remains the same. Any help is appreciated.

ereis
  • 1
  • Does this answer your question, [running adb devices showing unauthorized device?](https://stackoverflow.com/questions/25236960/running-adb-devices-showing-unauthorized-device)? – Federico Baù Jan 06 '21 at 15:18
  • does your test fail if you add `passenv = *` to your `tox.ini`? my guess is that `adb` requires some special environment variable which tox is filtering - one of the tox core devs – anthony sottile Jan 06 '21 at 19:49
  • Found the solve, apparently I needed to add sleep(2) after 'adb connect' since it takes a moment for the device to get authorization. – ereis Jan 10 '21 at 09:56

1 Answers1

0

Found the solve, apparently I needed to add sleep(1) after 'adb connect' since it takes a moment for the device to get authorization

ereis
  • 1