老师,我在第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]