请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

实例化driver报错:more than one device/emulator;Code '1'

老师,我连接了2台模拟器,实例化driver的时候执行到webdriver.remote那边就报错adb:error:more than one device/emulator;Code '1’
base_driver.py

from appium import webdriver
from util.write_user_command import WriteUserCommand
import threading
class BaseDriver:
    def android_driver(self,i):
        write_file=WriteUserCommand()
        device=write_file.get_value('user_info_'+str(i),'deviceName')
        print('device:'+device)
        port=write_file.get_value('user_info_'+str(i),'p')
        print('port:'+port)
        desired_caps = {
            'deviceName': device,
            'app': '/Users/zy/工作/JCSample公版1.19/JCSample_2.apk',
            'appPackage': 'com.juphoon.cloud.sample',
            'appActivity': '.MainActivity',
            'platformName': 'Android',
            'automationName': 'UiAutomator2',
            'udid': device,
            #    'noReset':'true',
            'skipDeviceInitialization': 'true'
        }
        # 连接appium server
        print(port)
        url='http://127.0.0.1:%s/wd/hub'%port
        print(url)
        driver = webdriver.Remote(url, desired_caps)
        print('error before driver.remote')
        return driver
    def ios_driver(self):
        pass
    def get_driver(self):
        pass

test_case.py

#coding=utf-8
import sys
sys.path.append('sys.path.append(/Users/zy/PycharmProjects/Appiumpython)')
import unittest
import HTMLTestRunner
import threading
from business.login_business import LoginBusiness
import time
from util.server import Server
import multiprocessing
class ParameTestCase(unittest.TestCase):
    def __init__(self,methodName='runTest',parame=None):
        super(ParameTestCase,self).__init__(methodName)
        global parames
        parames=parame
class CaseTest(ParameTestCase):
    @classmethod
    def setUpClass(cls) -> None:
        print('This is setupclass------>')
        print('setupclass print parame:%d'%parames)
        cls.login_business=LoginBusiness(parames)
    def setUp(self) -> None:
        print('This is setup.')
#    @unittest.skip('CaseTest')
    def test_01(self):
        '''
        登录成功
        :return:
        '''
        print('This is test_01')
        print('test_01 print parame: %d'%parames)
        self.login_business.login_success()
    def test_02(self):
        print('This is test_02')
        print('test_02 print parame: %d'%parames)
    def tearDown(self) -> None:
        print('This is teardown')
    @classmethod
    def tearDownClass(cls) -> None:
        print('This is teardownclass')

def appium_init():
    server = Server()
    server.start_multi_appium_server()

def get_suite(i):
    suite=unittest.TestSuite()
    suite.addTest(CaseTest('test_02',parame=i))
    suite.addTest(CaseTest('test_01',parame=i))
    unittest.TextTestRunner().run(suite)
    # html_file='/Users/zy/PycharmProjects/Appiumpython/report/report_'+str(i)+'.html'
    # fp=open(html_file,'wb')
    # HTMLTestRunner.HTMLTestRunner(fp).run(suite)

if __name__=='__main__':
    appium_init()
    # threads=[]
    # lock=threading.Lock()

    t1=threading.Thread(target=get_suite,args=(0,))
    t2=threading.Thread(target=get_suite,args=(1,))
    t1.start()
    t2.start()
    
    # threads=[]
    # lock=threading.Lock()
    # for i in range(2):
    #     t=threading.Thread(target=get_suite,args=(i,))
    #     threads.append(t)
    # for j in threads:
    #     lock.acquire()
    #     j.start()
    #     lock.release()
    #     time.sleep(1)

报错图:
图片描述
图片描述
报错:

selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command '/Users/zy/android-sdk-macosx/platform-tools/adb -P 5037 -s 192.168.56.106\:5555 forward tcp\:8200 tcp\:6790' exited with code 1'; Stderr: 'adb: error: more than one device/emulator'; Code: '1'

我看了下,程序执行到webdriver.remote()就报错了,然后我输出了一下url,确认是两个端口号不一样到url。
后来我用客户端,一样的配置,2台模拟器,连接了一下appium,也是报more than one device错误,日志如下:

[Appium] Welcome to Appium v1.15.1
[Appium] Non-default server args:
[Appium]   allowInsecure: {
[Appium]   }
[Appium]   denyInsecure: {
[Appium]   }
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[HTTP] --> GET /wd/hub/sessions
[HTTP] {}
[GENERIC] Calling AppiumDriver.getSessions() with args: []
[GENERIC] Responding to client with driver.getSessions() result: []
[HTTP] <-- GET /wd/hub/sessions 200 7 ms - 40
[HTTP] 
[HTTP] --> POST /wd/hub/session
[HTTP] {"desiredCapabilities":{"app":"/Users/zy/工作/JCSample公版1.19/JCSample_2.apk","appActivity":".MainActivity","appPackage":"com.juphoon.cloud.sample","automationName":"UiAutomator2","deviceName":"192.168.56.106:5555","platformName":"Android","skipDeviceInitialization":true,"udid":"192.168.56.106:5555","newCommandTimeout":0,"connectHardwareKeyboard":true}}
[MJSONWP] Calling AppiumDriver.createSession() with args: [{"app":"/Users/zy/工作/JCSample公版1.19/JCSample_2.apk","appActivity":".MainActivity","appPackage":"com.juphoon.cloud.sample","automationName":"UiAutomator2","deviceName":"192.168.56.106:5555","platformName":"Android","skipDeviceInitialization":true,"udid":"192.168.56.106:5555","newCommandTimeout":0,"connectHardwareKeyboard":true},null,null]
[BaseDriver] Event 'newSessionRequested' logged at 1573447631495 (12:47:11 GMT+0800 (CST))
[Appium] Appium v1.15.1 creating new AndroidUiautomator2Driver (v1.37.2) session
[BaseDriver] Creating session with MJSONWP desired capabilities: {
[BaseDriver]   "app": "/Users/zy/工作/JCSample公版1.19/JCSample_2.apk",
[BaseDriver]   "appActivity": ".MainActivity",
[BaseDriver]   "appPackage": "com.juphoon.cloud.sample",
[BaseDriver]   "automationName": "UiAutomator2",
[BaseDriver]   "deviceName": "192.168.56.106:5555",
[BaseDriver]   "platformName": "Android",
[BaseDriver]   "skipDeviceInitialization": true,
[BaseDriver]   "udid": "192.168.56.106:5555",
[BaseDriver]   "newCommandTimeout": 0,
[BaseDriver]   "connectHardwareKeyboard": true
[BaseDriver] }
[BaseDriver] The following capabilities were provided, but are not recognized by Appium:
[BaseDriver]   connectHardwareKeyboard
[BaseDriver] Session created with session id: 26288d69-2edd-4353-81c3-2dd18c10ad47
[BaseDriver] Using local app '/Users/zy/工作/JCSample公版1.19/JCSample_2.apk'
[UiAutomator2] Checking whether app is actually present
[ADB] Found 1 'build-tools' folders under '/Users/zy/android-sdk-macosx' (newest first):
[ADB]     /Users/zy/android-sdk-macosx/build-tools/29.0.2
[ADB] Using 'adb' from '/Users/zy/android-sdk-macosx/platform-tools/adb'
[AndroidDriver] Retrieving device list
[ADB] Trying to find a connected android device
[ADB] Getting connected devices...
[ADB] Connected devices: [{"udid":"192.168.56.106:5555","state":"device"},{"udid":"192.168.56.107:5555","state":"device"}]
[AndroidDriver] Using device: 192.168.56.106:5555
[ADB] Using 'adb' from '/Users/zy/android-sdk-macosx/platform-tools/adb'
[ADB] Setting device id to 192.168.56.106:5555
[ADB] Running '/Users/zy/android-sdk-macosx/platform-tools/adb -P 5037 -s 192.168.56.106\:5555 shell getprop ro.build.version.sdk'
[ADB] Current device property 'ro.build.version.sdk': 21
[ADB] Device API level: 21
[AndroidDriver] 'skipDeviceInitialization' is set. Skipping device initialization.
[ADB] Running '/Users/zy/android-sdk-macosx/platform-tools/adb -P 5037 -s 192.168.56.106\:5555 shell settings put secure mock_location 1'
[Logcat] Starting logcat capture
[ADB] Getting install status for io.appium.uiautomator2.server
[ADB] Running '/Users/zy/android-sdk-macosx/platform-tools/adb -P 5037 -s 192.168.56.106\:5555 shell dumpsys package io.appium.uiautomator2.server'
[ADB] 'io.appium.uiautomator2.server' is installed
[ADB] Getting package info for 'io.appium.uiautomator2.server'
[ADB] Running '/Users/zy/android-sdk-macosx/platform-tools/adb -P 5037 -s 192.168.56.106\:5555 shell dumpsys package io.appium.uiautomator2.server'
[ADB] Cannot extract apk info using apkanalyzer. Falling back to aapt. Original error: Could not find 'apkanalyzer' in ["/Users/zy/android-sdk-macosx/platform-tools/apkanalyzer","/Users/zy/android-sdk-macosx/emulator/apkanalyzer","/Users/zy/android-sdk-macosx/tools/apkanalyzer","/Users/zy/android-sdk-macosx/tools/bin/apkanalyzer","/Users/zy/android-sdk-macosx/build-tools/29.0.2/apkanalyzer"]. Do you have Android Build Tools installed at '/Users/zy/android-sdk-macosx'?
[ADB] Using 'aapt' from '/Users/zy/android-sdk-macosx/build-tools/29.0.2/aapt'
[ADB] The version name of the installed 'io.appium.uiautomator2.server' is greater or equal to the application version name ('4.3.0' >= '4.3.0')
[UiAutomator2] io.appium.uiautomator2.server installation state: sameVersionInstalled
[ADB] Checking app cert for /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v4.3.0.apk
[ADB] Using 'apksigner' from '/Users/zy/android-sdk-macosx/build-tools/29.0.2/apksigner'
[ADB] Starting '/Users/zy/android-sdk-macosx/build-tools/29.0.2/apksigner' with args '["verify","--print-certs","/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v4.3.0.apk"]'
[ADB] apksigner stdout: Signer #1 certificate DN: EMAILADDRESS=android@android.com, CN=Android, OU=Android, O=Android, L=Mountain View, ST=California, C=US
[ADB] Signer #1 certificate SHA-256 digest: a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc
[ADB] Signer #1 certificate SHA-1 digest: 61ed377e85d386a8dfee6b864bd85b0bfaa5af81
[ADB] Signer #1 certificate MD5 digest: e89b158e4bcf988ebd09eb83f5378e87
[ADB] 
[ADB] '/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v4.3.0.apk' is already signed.
[ADB] Getting install status for io.appium.uiautomator2.server.test
[ADB] Running '/Users/zy/android-sdk-macosx/platform-tools/adb -P 5037 -s 192.168.56.106\:5555 shell dumpsys package io.appium.uiautomator2.server.test'
[ADB] 'io.appium.uiautomator2.server.test' is installed
[ADB] Checking app cert for /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk
[ADB] Starting '/Users/zy/android-sdk-macosx/build-tools/29.0.2/apksigner' with args '["verify","--print-certs","/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk"]'
[ADB] apksigner stdout: Signer #1 certificate DN: EMAILADDRESS=android@android.com, CN=Android, OU=Android, O=Android, L=Mountain View, ST=California, C=US
[ADB] Signer #1 certificate SHA-256 digest: a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc
[ADB] Signer #1 certificate SHA-1 digest: 61ed377e85d386a8dfee6b864bd85b0bfaa5af81
[ADB] Signer #1 certificate MD5 digest: e89b158e4bcf988ebd09eb83f5378e87
[ADB] 
[ADB] '/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk' is already signed.
[UiAutomator2] Server packages are not going to be (re)installed
[UiAutomator2] Waiting up to 30000ms for services to be available
[ADB] Running '/Users/zy/android-sdk-macosx/platform-tools/adb -P 5037 -s 192.168.56.106\:5555 shell pm list instrumentation'
[UiAutomator2] Instrumentation target 'io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner' is available
[UiAutomator2] Forwarding UiAutomator2 Server port 6790 to 8200
[ADB] Forwarding system: 8200 to device: 6790
[ADB] Running '/Users/zy/android-sdk-macosx/platform-tools/adb -P 5037 -s 192.168.56.106\:5555 forward tcp\:8200 tcp\:6790'
[UiAutomator2] Deleting UiAutomator2 session
[UiAutomator2] Deleting UiAutomator2 server session
[WD Proxy] Matched '/' to command name 'deleteSession'
[UiAutomator2] Did not get confirmation UiAutomator2 deleteSession worked; Error was: UnknownError: An unknown server-side error occurred while processing the command. Original error: Trying to proxy a session command without session id
[ADB] Running '/Users/zy/android-sdk-macosx/platform-tools/adb -P 5037 -s 192.168.56.106\:5555 shell am force-stop com.juphoon.cloud.sample'
[Logcat] Stopping logcat capture
[ADB] Removing forwarded port socket connection: 8200 
[ADB] Running '/Users/zy/android-sdk-macosx/platform-tools/adb -P 5037 -s 192.168.56.106\:5555 forward --remove tcp\:8200'
[UiAutomator2] Unable to remove port forward 'Error executing adbExec. Original error: 'Command '/Users/zy/android-sdk-macosx/platform-tools/adb -P 5037 -s 192.168.56.106\:5555 forward --remove tcp\:8200' exited with code 1'; Stderr: 'adb: error: more than one device/emulator'; Code: '1''
[BaseDriver] Event 'newSessionStarted' logged at 1573447635696 (12:47:15 GMT+0800 (CST))
[MJSONWP] Encountered internal error running command: Error executing adbExec. Original error: 'Command '/Users/zy/android-sdk-macosx/platform-tools/adb -P 5037 -s 192.168.56.106\:5555 forward tcp\:8200 tcp\:6790' exited with code 1'; Stderr: 'adb: error: more than one device/emulator'; Code: '1'
[MJSONWP] Error: Command '/Users/zy/android-sdk-macosx/platform-tools/adb -P 5037 -s 192.168.56.106\:5555 forward tcp\:8200 tcp\:6790' exited with code 1
[MJSONWP]     at ChildProcess.proc.on.code (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/teen_process/lib/exec.js:113:19)
[MJSONWP]     at ChildProcess.emit (events.js:182:13)
[MJSONWP]     at maybeClose (internal/child_process.js:961:16)
[MJSONWP]     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:5)
[HTTP] <-- POST /wd/hub/session 500 4207 ms - 383
[HTTP] 
[HTTP] --> DELETE /wd/hub/session
[HTTP] {}
[HTTP] No route found. Setting content type to 'text/plain'
[HTTP] <-- DELETE /wd/hub/session 404 9 ms - 57
[HTTP] 

然后我连接2台真机试了下,也是报这个错误。
老师,我的appium版本是1.15.1的,不能同时连接多个设备吗

正在回答 回答被采纳积分+3

2回答

提问者 连枝 2019-11-14 08:29:41

老师我的问题没解决,同样的报错?。我后来手动打开2个appium服务,写代码用多线程去做启动配置,还是同样的adb报错

0 回复 有任何疑惑可以回复我~
  • 你再cmd去运行,你启动appium用多线程,但是case执行driver初始化用多进程
    回复 有任何疑惑可以回复我~ 2019-11-14 08:59:45
Mushishi 2019-11-11 19:43:17

你好,可以的,你看我讲解,此时继续看,我建议多进程。

0 回复 有任何疑惑可以回复我~
  • 提问者 连枝 #1
    老师谢谢你的解答,我已经把你的多线程课程这部分内容看完,事实上我一开始执行的是按照你的课程讲解一样的代码执行,可惜报错,我就怀疑是否是因为python2.7和python3.X在多线程这块的差异导致的,于是我去掉了循环实例化线程,改为一个一个实例化线程,还是报错more than one device.后来我找别的同事在他电脑上执行了我的代码,他那边是可以的,所以可能是我的环境关系。老师的课程讲得非常清楚,谢谢老师!
    回复 有任何疑惑可以回复我~ 2019-11-11 21:39:51
  • Mushishi 回复 提问者 连枝 #2
    哈哈,应该不是,你可以继续后面学习,进程会分开对象所有好一些,我也建议你不用pycharm,直接命令行
    回复 有任何疑惑可以回复我~ 2019-11-12 09:47:22
  • 慕运维8167328 回复 提问者 连枝 #3
    你好,我想问下你后面自己本地环境解决了吗,我也遇到了相同的问题
    回复 有任何疑惑可以回复我~ 2020-03-11 20:23:43
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信