Appium多執行緒UiAutomator exited unexpectedly with code 0, signal null,UiAUtomator shut down unexpectedly
阿新 • • 發佈:2018-12-23
# !/usr/bin/env python # -*- coding:utf-8 -*- import unittest import HTMLTestRunner import threading import multiprocessing from utils.server import Server from business.login_business import LoginBusiness from utils.write_user_command import WriteUserCommand import time class ParameTestCase(unittest.TestCase): def __init__(self, methodName='runTest', param=None): super(ParameTestCase, self).__init__(methodName) global params params = param class CaseTest(ParameTestCase): @classmethod def setUpClass(cls): print("setupclass---->", params) cls.login_business = LoginBusiness(params) print("this is class setUp\n") def setUp(self): print("this is setup\n") def test_01(self): self.login_business.login_password_fail() def test_02(self): self.login_business.login_user_fail() def test_03(self): self.login_business.login_password_fail() def tearDown(self): print("this is tearDown\n") @classmethod def tearDownClass(cls): print("this is class tearDown\n") def get_suite(i): print("get_suite裡的", i) suite = unittest.TestSuite() suite.addTest(CaseTest("test_01", param=i)) suite.addTest(CaseTest("test_02", param=i)) write_file = WriteUserCommand() device = write_file.get_value('user_info_' + str(i), 'deviceName') html_file = "../report/result" + str(i) + ".html" with open(html_file, "wb") as fp: HTMLTestRunner.HTMLTestRunner(stream=fp, title="自動化測試", description=device + "自動化測試").run(suite) def appium_init(): server = Server() server.main() def get_count(): write_user_file = WriteUserCommand() return write_user_file.get_file_lines() if __name__ == '__main__': appium_init() thread = [] for i in range(get_count()): t = threading.Thread(target=get_suite, args=(i,)) thread.append(t) for j in thread: j.start() time.sleep(3) # 如果不等待會報UiAutomator exited unexpectedly with code 0, signal null
下面是報錯資訊:
[UiAutomator] UiAutomator exited unexpectedly with code 0, signal null
[debug] [UiAutomator] Moving to state 'stopped'
Unhandled rejection Error: UiAUtomator shut down unexpectedly
at AndroidBootstrap.callee$2$0$ (C:\Program Files\nodejs\node_global\node_modules\appium\node_modules\[email protected] @appium-android-bootstrap\lib\bootstrap.js:187:42)
at tryCatch (C:\Program Files\nodejs\node_global\node_modules\appium\node_modules\[email protected]@babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Program Files\nodejs\node_global\node_modules\appium\node_modules\ [email protected]@babel-runtime\regenerator\runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Program Files\nodejs\node_global\node_modules\appium\node_modules\[email protected]@babel-runtime\regenerator\runtime.js:100:21)
at invoke (C:\Program Files\nodejs\node_global\node_modules\appium\node_modules\[email protected]@babel-runtime\regenerator\runtime.js:136:37)
at enqueueResult (C:\Program Files\nodejs\node_global\node_modules\appium\node_modules\[email protected]@babel-runtime\regenerator\runtime.js:185:17)
at new Promise (<anonymous>)
at new F (C:\Program Files\nodejs\node_global\node_modules\appium\node_modules\[email protected]@core-js\library\modules\$.export.js:30:36)
at AsyncIterator.enqueue (C:\Program Files\nodejs\node_global\node_modules\appium\node_modules\[email protected]@babel-runtime\regenerator\runtime.js:184:12)
at AsyncIterator.prototype.(anonymous function) [as next] (C:\Program Files\nodejs\node_global\node_modules\appium\node_modules\[email protected]@babel-runtime\regenerator\runtime.js:100:21)
at Object.runtime.async (C:\Program Files\nodejs\node_global\node_modules\appium\node_modules\[email protected]@babel-runtime\regenerator\runtime.js:209:12)
at UiAutomator.callee$2$0 (C:\Program Files\nodejs\node_global\node_modules\appium\node_modules\[email protected]@appium-android-bootstrap\build\lib\bootstrap.js:356:42)
at UiAutomator.emit (events.js:182:13)
at UiAutomator.changeState (C:\Program Files\nodejs\node_global\node_modules\appium\node_modules\[email protected]@appium-uiautomator\lib\uiautomator.js:87:10)
at SubProcess.<anonymous> (C:\Program Files\nodejs\node_global\node_modules\appium\node_modules\[email protected]@appium-uiautomator\lib\uiautomator.js:47:14)
at SubProcess.emit (events.js:182:13)
at ChildProcess.emit (C:\Program Files\nodejs\node_global\node_modules\appium\node_modules\[email protected]@teen_process\lib\subprocess.js:153:14)
at ChildProcess.emit (events.js:182:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
多執行緒執行,一開始我沒有在最後加time.sleep(3)。
我有2臺機器,總會有1臺報錯,如果A和B 2臺機子,A報錯,B可以正常執行,然後我把B關閉後單獨執行A,竟然沒報問題。我懷疑是啟動的時候公用了一個東西導致的,然後我試了下time.sleep(3),竟然OK了。
但是多程序又遇到了其他問題,比如機器A執行了1條用例後就不動了,機器B執行了剩餘的用例,也可能某項操作串瞭如輸入2次密碼。
簡單點解決方案:改成多程序