【求助】python+appium+unittest执行脚本时不执行的问题?

python+appium+unittest执行脚本时候,一直卡在这个地方,是什么原因啊,是脚本问题还是什么原因?


appium中:
> 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].<anonymous> (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].androidCommon.initUnicode (D:\Appium\loadspace\Appium\node_modules\appium\lib\devices\android\android-common.js:878:5)
>     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].<anonymous> (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":"7.0","appium:deviceName":"0123456789ABCDEF:5037","appium:appPackage":"com.njzx.care","appium:appAct]


Test_report说:

  File "D:\python\lib\http\client.py", line 297, in begin    version, status, reason = self._read_status()  File "D:\python\lib\http\client.py", line 266, in _read_status    raise RemoteDisconnected("Remote end closed connection without"urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))

 

代码如:

test_case1_njzx_login.py文件中:
## 实现守护宝app登录
#  包名和activity名:com.njzx.care/com.njzx.care.activity.MainActivity
# !/usr/bin/python
# encoding:utf-8
import time
import unittest
from appium import  webdriver

class test_login(unittest.TestCase):
    #  1、环境准备与还原:文件配置
    def setUp(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '7.0'
        desired_caps['deviceName'] = '0123456789ABCDEF:5037'
        # desired_caps['browserName'] = ''
        #  desired_caps['chromeOptions'] = {'androidProcess': 'com.tencent.mm:tools'}  # 驱动html5,必备
        desired_caps['appPackage'] = 'com.njzx.care'
        desired_caps['appActivity'] = 'com.njzx.care.activity.MainActivity'
        # desired_caps["unicodeKeyboard", "True"]  # 支持中文输入
        # desired_caps["resetKeyboard", "True"]  # 支持中文输入,必须两条都配置
        # desired_caps['automationName'] = 'Selendroid'#  link_text定位方式是Selendroid框架中的定位方式,因此appium若想采用,则需在代码加入
        desired_caps['newCommandTimeout'] = '100'  # 超时时间
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

    def tearDown(self):
        self.driver.quit()

    #  2、登录业务流程:
    #     (1)启动app
    #     (2)点击text = "您好,请登录"或者id  = "com.njzx.care:id/tv_helloname"进入登录界面
    #     (3)输入手机号码id = "com.njzx.care:id/et_username"和密码id = "com.njzx.care:id/et_password"
    #     (4)如果手机已经注册,可以直接登录;如果不存在,需要注册text= "快速注册"
    #     (5)点击登录id = "com.njzx.care:id/iv_login"
    def test_sendAndLogin(self):
        time.sleep(2)#  动态加载等待对象的时间,可以添加个WebDriverWait
        startLogin_text = self.find_element_by_text("您好,请登录")
        startLogin_text_id = self.find_element_by_id("com.njzx.care:id/tv_helloname")
        startLogin_text.click()
        time.sleep(2)
        text_num1 = input("请输入注册号码:")
        text_psd2 = input("请输入密码:")

        #  打开本地的用户名+ 密码存储文件
        user_info_file = open('user_info.txt', 'r')  # 用户名和密码存储文件
        user_info_list = user_info_file.readlines()  # 正确的用户名和密码存储队列
        correct_username = user_info_list[0].strip()  # 正确的用户名
        correct_password = user_info_list[1]  # 正确的密码
        user_info_file.close()

        if text_num1 == correct_username and text_psd2 == correct_password:
            print('账号存在,可以登录')
            time.sleep(2)
            self.find_element_by_id("com.njzx.care:id/et_username").send_keys(text_num1)
            self.find_element_by_id("com.njzx.care:id/et_password").send_keys(text_psd2)
        else:
            print('账号不存在,请重新注册!')
            # register = self.find_element_by_text("快速注册")
            # time.sleep(2)
            # # 注册id = com.njzx.care:id/et_phone
            # register_text = self.find_element_by_id("com.njzx.care:id/et_phone")
            # register_text.send_keys(number)
            # time.sleep(2)
            # self.find_element_by_id("com.njzx.care:id/img_submit")
            # time.sleep(2)
            # code_text = self.find_element_by_id("com.njzx.care:id/et_code")
            # code_text.send_keys(input("请输入验证"))
            # self.find_element_by_id("com.njzx.care:id/img_submit")
            return False

        time.sleep(2)
        submit = self.find_element_by_id("com.njzx.care:id/iv_login")
        submit.click()
        time.sleep(2)
        #  提交登陆之后,判断是否登陆成功
        # 方法1:可以判断某一个元素是否存在:
        #     如:“你好,请登录”这个元素是否存在isDisplayed():
        # try:
        #     get_user_info_message = self.find_element_by_id("com.njzx.care:id/tv_helloname").isDisplayed()
        #     print("登陆成功!")
        # except Exception as e:
        #     print("登录失败!",format(e))
        #  或者使用断言assert:
        try:
            self.find_element_by_id("com.njzx.care:id/ll_userinfo").click()# 进入个人信息界面
            time.sleep(2)
            info_message = self.find_element_by_id("com.njzx.care:id/tv_title").text  #  获取到元素中的文本信息
            correct_message = "个人信息"
            assert info_message == correct_message
            print("登陆成功")
        except Exception as e:
            print("登录失败!",format(e))

        # 方法2:可以判断只有登录成功才能出现的界面,如果存在,就表明登陆成功


testsuit_njzx.py文件中:

# !/usr/bin/python
# encoding:utf-8

import unittest
import test_case1_njzx_login
from HTMLTestRunner import HTMLTestRunner

#  测试用例集合:
if __name__ == '__main__':
    suite = unittest.TestSuite()  # unittest模块中的TestSuite()创建一个对象接收testcase
    suite.addTests(unittest.TestLoader().loadTestsFromNames(['test_case1_njzx_login.test_login']))
    with open('D:/HTMLReport.html', 'wb') as f:#  模式wb
        runner = HTMLTestRunner(stream=f,
                                title=' Test Report',
                                description='generated by HTMLTestRunner----黄亮.',
                                verbosity=2
                                )
        runner.run(suite)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值