请稍等 ...
×

采纳答案成功!

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

appium可以正常启动,但是在后边执行的时候直接说我链接不到任何安卓设备,一直在重复启动adb devices ,但是连接不到安卓设备,请问这个是什么问题呢

老师,我在第5-12章将多线程、unittest、启动appium ,appium可以正常启动,但是在后边执行的时候直接说我链接不到任何安卓设备,一直在重复启动adb devices ,但是连接不到安卓设备,请问这个是什么问题呢,麻烦您帮忙看下!

# -*- coding:utf8 -*-
# __author__ = "zhangying"
# __date__ = "2019/2/20 9:19"
#创建class必须继承unittest.TestCase
import sys
sys.path.append('D:/PythonAppium')
import unittest
import HTMLTestRunner
import io
import threading
from util.server import Server
from appium import webdriver
import time
from business.login_business import LoginBusiness



class ParameTestCase(unittest.TestCase):
    def __init__(self,methodName='runTest',parame=None):
        super(ParameTestCase, self).__init__(methodName)
        global parames
        parames = parame


class Test_case(ParameTestCase):
    @classmethod
    def setUpClass(cls):
        print('this is setUpClass----->',parames)
        cls.login_business = LoginBusiness(parames)


    def setUp(self):
        print('this is setUp')

    def test_01(self):
        self.login_business.login_pass()
        print('this is case01里边的参数',parames)
        #判断两个对象是否相等
        # flag = True
        # self.assertEqual('1','1','两个对象相同')
        # self.assertNotEqual(1,2,'两个对象不相同')
        #判断是否为True False
        # self.assertTrue(flag)
        # self.assertFalse(flag)


    # 跳过某条case,放在方法上边
    # @unittest.skip("Test_case")
    def test_02(self):
        print('this is case02')

    def tearDown(self):
        print('this is tearDown')

    @classmethod
    def tearDownClass(cls):
        print('this is tearDownClass')


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


def get_suite(i):
    print("get_suit 里边的parame是",i)
    suite = unittest.TestSuite()
    suite.addTest(Test_case("test_01", parame=i))
    # suite.addTest(Test_case("test_02"))
    # html_file = "D:/PythonAppium/report/report"+str(i)+".html"
    # fp = open(html_file, "wb")
    # HTMLTestRunner.HTMLTestRunner(fp).run(suite)
    #  注释掉unittest.main() 声明一个容器罐子放case,添加哪个case就运行哪个case
    unittest.TextTestRunner().run(suite)


if __name__ == '__main__':
    # unittest.main()
    appium_init()
    threads = []
    for i in range(2):
        t = threading.Thread(target=get_suite,args=(i,))
        threads.append(t)
    for j in threads:
        j.start()
        time.sleep(2)



错误日志:

F:\software\Python36\python.exe D:/PythonAppium/case/test_case.py
already connected to 127.0.0.1:21503
0
already connected to 127.0.0.1:21513
0
�ɹ�: ����ֹ���� "node.exe"���� PID Ϊ 7560��
�ɹ�: ����ֹ���� "node.exe"���� PID Ϊ 7436��
[Appium] Welcome to Appium v1.11.1
[Appium] Non-default server args:
[Appium]   port: 4700
[Appium]   bootstrapPort: 4900
[Appium]   udid: 127.0.0.1:21503
[Appium] Deprecated server args:
[Appium]   -U,--udid => --default-capabilities '{"udid":"127.0.0.1:21503"}'
[Appium] Default capabilities, which will be added to each request unless overridden by desired capabilities:
[Appium]   udid: 127.0.0.1:21503
[Appium] Welcome to Appium v1.11.1
[Appium] Non-default server args:
[Appium]   port: 4701
[Appium]   bootstrapPort: 4901
[Appium]   udid: 127.0.0.1:21513
[Appium] Deprecated server args:
[Appium]   -U,--udid => --default-capabilities '{"udid":"127.0.0.1:21513"}'
[Appium] Default capabilities, which will be added to each request unless overridden by desired capabilities:
[Appium]   udid: 127.0.0.1:21513
[Appium] Appium REST http interface listener started on 0.0.0.0:4700
[Appium] Appium REST http interface listener started on 0.0.0.0:4701
get_suit 里边的parame是 0
this is setUpClass-----> 0
[HTTP] --> POST /wd/hub/session
[HTTP] {"capabilities":{"firstMatch":[{"platformName":"Android","appium:deviceName":"127.0.0.1:21503","appium:app":"D:\\PythonAppium\\mukewang.apk","appium:appPackage":"cn.com.open.mooc","appium:appActivity":"cn.com.open.mooc.index.splash.MCSplashActivity","appium:noReset":true}]},"desiredCapabilities":{"platformName":"Android","deviceName":"127.0.0.1:21503","app":"D:\\PythonAppium\\mukewang.apk","appPackage":"cn.com.open.mooc","appActivity":"cn.com.open.mooc.index.splash.MCSplashActivity","noReset":true}}
[debug] [W3C] Calling AppiumDriver.createSession() with args: [{"platformName":"Android","deviceName":"127.0.0.1:21503","app":"D:\\PythonAppium\\mukewang.apk","appPackage":"cn.com.open.mooc","appActivity":"cn.com.open.mooc.index.splash.MCSplashActivity","noReset":true},null,{"firstMatch":[{"platformName":"Android","appium:deviceName":"127.0.0.1:21503","appium:app":"D:\\PythonAppium\\mukewang.apk","appium:appPackage":"cn.com.open.mooc","appium:appActivity":"cn.com.open.mooc.index.splash.MCSplashActivity","appium:noReset":true}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1550902526269 (14:15:26 GMT+0800 (GMT+08:00))
[BaseDriver] The capabilities ["udid"] are not standard capabilities and should have an extension prefix
[Appium] DeprecationWarning: 'automationName' capability was not provided. Future versions of Appium will require 'automationName' capability to be set for Android sessions.
[Appium] Setting automation to 'UiAutomator1'. 
[Appium] Creating new AndroidDriver (v4.8.0) session
[Appium] Capabilities:
[Appium]   platformName: Android
[Appium]   udid: 127.0.0.1:21503
[Appium]   deviceName: 127.0.0.1:21503
[Appium]   app: D:\PythonAppium\mukewang.apk
[Appium]   appPackage: cn.com.open.mooc
[Appium]   appActivity: cn.com.open.mooc.index.splash.MCSplashActivity
[Appium]   noReset: true
[debug] [BaseDriver] W3C capabilities {"alwaysMatch":{"platformNa... and MJSONWP desired capabilities {"udid":"127.0.0.1:21503","... were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {"alwaysMatch":{"platformNa...
[BaseDriver] Session created with session id: cb84eb61-b35d-40da-b282-472d1d1cd820
(node:7644) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[AndroidDriver] Java version is: 1.8.0_201
[ADB] Checking whether adb is present
[ADB] Found 1 'build-tools' folders under 'C:\Program Files\Java\adt\sdk' (newest first):
[ADB]     C:/Program Files/Java/adt/sdk/build-tools/android-4.4W
[ADB] Using adb.exe from C:\Program Files\Java\adt\sdk\platform-tools\adb.exe
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices...
get_suit 里边的parame是 1
this is setUpClass-----> 1
[HTTP] --> POST /wd/hub/session
[HTTP] {"capabilities":{"firstMatch":[{"platformName":"Android","appium:deviceName":"127.0.0.1:21513","appium:app":"D:\\PythonAppium\\mukewang.apk","appium:appPackage":"cn.com.open.mooc","appium:appActivity":"cn.com.open.mooc.index.splash.MCSplashActivity","appium:noReset":true}]},"desiredCapabilities":{"platformName":"Android","deviceName":"127.0.0.1:21513","app":"D:\\PythonAppium\\mukewang.apk","appPackage":"cn.com.open.mooc","appActivity":"cn.com.open.mooc.index.splash.MCSplashActivity","noReset":true}}
[debug] [W3C] Calling AppiumDriver.createSession() with args: [{"platformName":"Android","deviceName":"127.0.0.1:21513","app":"D:\\PythonAppium\\mukewang.apk","appPackage":"cn.com.open.mooc","appActivity":"cn.com.open.mooc.index.splash.MCSplashActivity","noReset":true},null,{"firstMatch":[{"platformName":"Android","appium:deviceName":"127.0.0.1:21513","appium:app":"D:\\PythonAppium\\mukewang.apk","appium:appPackage":"cn.com.open.mooc","appium:appActivity":"cn.com.open.mooc.index.splash.MCSplashActivity","appium:noReset":true}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1550902528293 (14:15:28 GMT+0800 (GMT+08:00))
[BaseDriver] The capabilities ["udid"] are not standard capabilities and should have an extension prefix
[Appium] DeprecationWarning: 'automationName' capability was not provided. Future versions of Appium will require 'automationName' capability to be set for Android sessions.
[Appium] Setting automation to 'UiAutomator1'. 
[Appium] Creating new AndroidDriver (v4.8.0) session
[Appium] Capabilities:
[Appium]   platformName: Android
[Appium]   udid: 127.0.0.1:21513
[Appium]   deviceName: 127.0.0.1:21513
[Appium]   app: D:\PythonAppium\mukewang.apk
[Appium]   appPackage: cn.com.open.mooc
[Appium]   appActivity: cn.com.open.mooc.index.splash.MCSplashActivity
[Appium]   noReset: true
[debug] [BaseDriver] W3C capabilities {"alwaysMatch":{"platformNa... and MJSONWP desired capabilities {"udid":"127.0.0.1:21513","... were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {"alwaysMatch":{"platformNa...
[BaseDriver] Session created with session id: 1cf331b9-b434-4f81-834f-967beb6e1558
(node:7084) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[AndroidDriver] Java version is: 1.8.0_201
[ADB] Checking whether adb is present
[ADB] Found 1 'build-tools' folders under 'C:\Program Files\Java\adt\sdk' (newest first):
[ADB]     C:/Program Files/Java/adt/sdk/build-tools/android-4.4W
[ADB] Using adb.exe from C:\Program Files\Java\adt\sdk\platform-tools\adb.exe
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices...
[debug] [ADB] 0 device(s) connected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Getting connected devices...
[debug] [ADB] 0 device(s) connected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[ADB] Error killing ADB server, going to see if it's online anyway
[debug] [ADB] Getting connected devices...
[debug] [ADB] 0 device(s) connected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Getting connected devices...
[debug] [ADB] 0 device(s) connected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Getting connected devices...
[debug] [ADB] 0 device(s) connected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Getting connected devices...
[debug] [ADB] 0 device(s) connected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Getting connected devices...
[debug] [ADB] 0 device(s) connected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Getting connected devices...
[debug] [ADB] 0 device(s) connected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Getting connected devices...
[debug] [ADB] 0 device(s) connected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Getting connected devices...
[debug] [ADB] 0 device(s) connected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [AndroidDriver] Shutting down Android driver
[debug] [AndroidDriver] Called deleteSession but bootstrap wasn't active
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1550902555626 (14:15:55 GMT+0800 (GMT+08:00))
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [W3C] Encountered internal error running command: Error: Could not find a connected Android device.
[debug] [W3C]     at getDevices (C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-adb@7.2.0@appium-adb\lib\tools\system-calls.js:195:13)
[debug] [W3C]     at getDevices (C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-adb@7.2.0@appium-adb\lib\tools\system-calls.js:212:20)
[HTTP] <-- POST /wd/hub/session 500 29394 ms - 715
[HTTP] 
E
======================================================================
ERROR: setUpClass (__main__.Test_case)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:/PythonAppium/case/test_case.py", line 29, in setUpClass
    cls.login_business = LoginBusiness(parames)
  File "D:\PythonAppium\business\login_business.py", line 12, in __init__
    self.login_handle = LoginhHandle(i)
  File "D:\PythonAppium\handle\login_handle.py", line 12, in __init__
    self.login_page = Login_Page(i)
  File "D:\PythonAppium\page\login_page.py", line 22, in __init__
    self.driver = base_driver.android_driver(i)
  File "D:\PythonAppium\base\base_driver.py", line 27, in android_driver
    driver = webdriver.Remote("http://127.0.0.1:"+port+"/wd/hub", capabilities)
  File "F:\software\Python36\lib\site-packages\appium_python_client-0.36-py3.6.egg\appium\webdriver\webdriver.py", line 118, in __init__
    super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
  File "F:\software\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "F:\software\Python36\lib\site-packages\appium_python_client-0.36-py3.6.egg\appium\webdriver\webdriver.py", line 159, in start_session
    response = self.execute(RemoteCommand.NEW_SESSION, parameters)
  File "F:\software\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "F:\software\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not find a connected Android device.


----------------------------------------------------------------------
Ran 0 tests in 29.445s

FAILED (errors=1)
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [AndroidDriver] Shutting down Android driver
[debug] [AndroidDriver] Called deleteSession but bootstrap wasn't active
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1550902559398 (14:15:59 GMT+0800 (GMT+08:00))
[debug] [W3C] Encountered internal error running command: Error: Could not find a connected Android device.
[debug] [W3C]     at getDevices (C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-adb@7.2.0@appium-adb\lib\tools\system-calls.js:195:13)
[debug] [W3C]     at getDevices (C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-adb@7.2.0@appium-adb\lib\tools\system-calls.js:212:20)
E
======================================================================
ERROR: setUpClass (__main__.Test_case)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:/PythonAppium/case/test_case.py", line 29, in setUpClass
    cls.login_business = LoginBusiness(parames)
  File "D:\PythonAppium\business\login_business.py", line 12, in __init__
    self.login_handle = LoginhHandle(i)
  File "D:\PythonAppium\handle\login_handle.py", line 12, in __init__
    self.login_page = Login_Page(i)
  File "D:\PythonAppium\page\login_page.py", line 22, in __init__
    self.driver = base_driver.android_driver(i)
  File "D:\PythonAppium\base\base_driver.py", line 27, in android_driver
    driver = webdriver.Remote("http://127.0.0.1:"+port+"/wd/hub", capabilities)
  File "F:\software\Python36\lib\site-packages\appium_python_client-0.36-py3.6.egg\appium\webdriver\webdriver.py", line 118, in __init__
    super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
  File "F:\software\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "F:\software\Python36\lib\site-packages\appium_python_client-0.36-py3.6.egg\appium\webdriver\webdriver.py", line 159, in start_session
    response = self.execute(RemoteCommand.NEW_SESSION, parameters)
  File "F:\software\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "F:\software\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not find a connected Android device.


----------------------------------------------------------------------
Ran 0 tests in 31.226s

FAILED (errors=1)
[HTTP] <-- POST /wd/hub/session 500 31155 ms - 715
[HTTP] 

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

4回答

提问者 qq_时间已到做回花韵_04140646 2019-02-27 14:19:46

老师,换掉adb之后也是不行,只要执行Test_case这个文件,安卓设备就掉了,连接不上,cmd中就显示没有连接,您有时间帮我远程看一下吧!谢谢了,我的appium是最新版本v1.11.1 和这个有关系吗?

0 回复 有任何疑惑可以回复我~
Mushishi 2019-02-24 17:17:36

https://img1.sycdn.imooc.com//szimg/5c7260f50001dccd04610305.jpg用你sdk里面得adb替换掉你模拟器里面得这个adb

0 回复 有任何疑惑可以回复我~
  • 搞好了,安卓sdk里边的adb要和逍遥游里边的adb版本相同,弄好就ok了,大家要是遇到这样的问题,可以试试这个办法
    回复 有任何疑惑可以回复我~ 2019-02-28 10:08:23
提问者 qq_时间已到做回花韵_04140646 2019-02-23 21:47:11
每次都要连接一下,才能显示设备信息,还经常断,过个一会就掉了,然后重接adb connect 127.0.0.1:21503  和127.0.0.1:21513 再次adb devices 就出来了,但是一运行文件就报错,链接不到安卓设备
0 回复 有任何疑惑可以回复我~
Mushishi 2019-02-23 19:55:13

[debug] [ADB] Trying to find a connected android device

你看提示得是 你找不到设备信息。你在cmd下去通过adb查看一下是否有设备信息。

0 回复 有任何疑惑可以回复我~
  • 每次都要连接一下,才能显示设备信息,还经常断,过个一会就掉了,然后重接adb connect 127.0.0.1:21503  和127.0.0.1:21513 再次adb devices 就出来了,但是一运行文件就报错,链接不到安卓设备
    回复 有任何疑惑可以回复我~ 2019-02-23 22:03:00
  • 你把adb 那个工具放到你逍遥游模拟器得安装陌路
    回复 有任何疑惑可以回复我~ 2019-02-24 17:16:33
  • 老师,换掉adb之后也是不行,只要执行Test_case这个文件,安卓设备就掉了,连接不上,cmd中就显示没有连接,您有时间帮我远程看一下吧!谢谢了,我的appium是最新版本v1.11.1 和这个有关系吗?
    回复 有任何疑惑可以回复我~ 2019-02-25 10:52:32
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信