Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

python 3.x - Pytest and Tox ADB connect issue - Device unauthorized

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...