Appium 执行 Appium+python+unittest 执行时无响应,报错 error: Unhandled error: TypeError: undefined is not a function,这个问题如何去解决?

bling8090 · 2019年05月05日 · 最后由 bling8090 回复于 2019年05月06日 · 2022 次阅读

我也做了 debug,说,{NameError}name 'sos_old_tel5' is not defined。
但不知道从何而来。

appium 控制台报错信息:

info: Starting App
info: [debug] Attempting to kill all 'uiautomator' processes
info: [debug] Getting all processes with 'uiautomator'
error: Unhandled error: TypeError: undefined is not a function
at [object Object].ADB.getPIDsByName (D:\Appium\loadspace\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:1037:8)
at [object Object].ADB.killProcessesByName (D:\Appium\loadspace\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:1079:8)
at [object Object].UiAutomator.start (D:\Appium\loadspace\Appium\node_modules\appium\lib\devices\android\uiautomator.js:29:12)
at [object Object]. (D:\Appium\loadspace\Appium\node_modules\appium\lib\devices\android\android.js:115:37)
at D:\Appium\loadspace\Appium\node_modules\appium\node_modules\async\lib\async.js:607:21
at D:\Appium\loadspace\Appium\node_modules\appium\node_modules\async\lib\async.js:246:17
at iterate (D:\Appium\loadspace\Appium\node_modules\appium\node_modules\async\lib\async.js:146:13)
at D:\Appium\loadspace\Appium\node_modules\appium\node_modules\async\lib\async.js:157:25
at D:\Appium\loadspace\Appium\node_modules\appium\node_modules\async\lib\async.js:248:21
at D:\Appium\loadspace\Appium\node_modules\appium\node_modules\async\lib\async.js:612:34
at [object Object]. (D:\Appium\loadspace\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:180:9)
at ChildProcess.exithandler (child_process.js:742:7)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1016:16)
at Process.ChildProcess._handle.onexit (child_process.js:1088:5) context: [POST /wd/hub/session {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"platformName":"Android","appium:platformVersion":"6.0","appium:deviceName":"H6ZPKR45DAB64DJB","appium:appPackage":"com.njzx.shbsetting","appium:appAc]
info: <-- POST /wd/hub/session - - ms - -
undefined

代码:

测试用例AddTel.py中

#   实现需求:打开守护设置----SOS设置,com.njzx.shbsetting/com.njzx.shbsetting.activity.ShbSettingActivity,输入号码添加紧急号码保存
# !/usr/bin/python
# encoding:utf-8
import unittest,time,random
from appium import webdriver

class test_add(unittest.TestCase):
    #   环境准备
    def setUp(self):
        desired_caps = {}
        desired_caps["platformName"] = 'Android'
       desired_caps["platformVersion"] = '6.0'
       desired_caps['deviceName'] = 'H6ZPKR45DAB64DJB'
        desired_caps["appPackage"] =  "com.njzx.shbsetting"
       desired_caps["appActivity"] =  ".activity.ShbSettingActivity"
        desired_caps["unicodeKeyboard"] =  "True"
        desired_caps["resetKeyboard"] = "True"  
        desired_caps["newCommandTimeout"] =  "40"
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
    #   环境还原
    def tearDown(self):
        self.driver.quit()
    #   业务流程
    def test_openAndAdd(self):
        sos_setting = self.driver.find_element_by_id("com.njzx.shbsetting:id/layout_sos")
        sos_setting.click()
        add_from_input = self.driver.find_element_by_id("zte.shb.sossetting:id/add_from_input")
        add_from_input.click()
        self.driver.find_element_by_id("zte.shb.sossetting:id/et_num").click()
        list_tel = [12213243213, 5678909876, 24542531241445, 2452452525565,24554654767, 245425425, 4545667657, 24254525]
        #   随机 5次从list_tel选取一个并输入
        for i in range(0,5):
            select_tel = random.choice(list_tel)
            list_tel.remove(select_tel)
            print(list_tel)
            self.driver.find_element_by_id("zte.shb.sossetting:id/et_num").send_keys(select_tel)
            self.driver.find_element_by_id("zte.shb.sossetting:id/btn_add").click()
            time.sleep(2)
        path = "E:\\pycharm\\run\\Appium\\addSOS\\"
       now_time = time.strftime("%Y-%m-%d-%H-%M-%S",time.localtime(time.time()))
       screen_picture = path + now_time + ".jpg"
        self.driver.get_screenshot_as_file(screen_picture)


执行用例用例集中test_suit.py
# !/usr/bin/python
# encoding:utf-8
import unittest,time
import AddTel
from HTMLTestRunner import HTMLTestRunner

if __name__ == '__main__':
    suite = unittest.TestSuite()  # unittest模块中的TestSuite()创建一个对象接收testcase
    suite.addTests(unittest.TestLoader().loadTestsFromNames(['AddTel.test_add']))
    now_time = time.strftime("%Y-%m-%d-%H-%M-%S",time.localtime(time.time()))
    name = now_time + "htmlreport.html"
   file_path = "E:\\pycharm\\run\\Appium\\addSOS\\htmlTestreport\\" + name
    with open(file_path, 'wb') as f:#  模式wb
        runner = HTMLTestRunner(stream=f,title=' Test Report',description='generated by HTMLTestRunner----Bling',verbosity=2)
        runner.run(suite)
共收到 3 条回复 时间 点赞

capability 是不是少了个'automationName'

kukaka 回复

我添加了 desired_caps['automationName'] = 'Appium',还是老问题啊。

可能是因为终端不是市场流行机子的原因

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册