• Appium+unittest+python登录app


    代码:

    # coding=utf-8
    
    from appium import webdriver
    import time
    import unittest
    import os
    import HTMLTestRunner
    
    
    class LoginTestLizi(unittest.TestCase):
        def setUp(self):
            desired_caps = {}
            desired_caps['platformName'] = 'Android'
            desired_caps['deviceName'] = 'Android Emulator'
            desired_caps['platformVersion'] = '6.0'
            desired_caps['appPackage'] = 'com.netease.cloudmusic'
            desired_caps['appActivity'] = '.activity.LoadingActivity'
            self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
        def startAPP(self):
            wd = self.driver
            wd.find_element_by_id("com.netease.cloudmusic:id/arc").click()
            wd.find_element_by_id("com.netease.cloudmusic:id/bw4").click()
            wd.find_element_by_id("com.android.packageinstaller:id/permission_allow_button").click()
            wd.find_element_by_id("com.android.packageinstaller:id/permission_allow_button").click()
            time.sleep(10)  # 睡眠10S等APP启动完成
    
        def test_login(self):
            driver = self.driver
            # 进入首页后点击‘我的’按钮
            driver.find_element_by_id("com.netease.cloudmusic:id/arc").click()
            time.sleep(2)
            # 点击登录头像按钮,进行登录,跳转到登录界面
            driver.find_element_by_id('com.netease.cloudmusic:id/pt').click()
            time.sleep(2)
            # 输入手机号
            driver.find_element_by_id('com.netease.cloudmusic:id/j5').send_keys('16688886666')
            #点击next
            driver.find_element_by_id('com.netease.cloudmusic:id/an5').click()
            time.sleep(2)
            # 输入验证码
            driver.find_element_by_id('com.netease.cloudmusic:id/an_').send_keys('1234')
            time.sleep(3)
            # 点击确认登录按钮
            driver.find_element_by_id('com.lizi.app:id/login_button').click()
    
            time.sleep(3)
            # 登录成功,页面下滑,不然点击不到设置按钮
            driver.swipe(500, 200, 500, 800, 0)
            time.sleep(2)
            # 获取登录后的昵称
            name = driver.find_element_by_id('com.lizi.app:id/login_username_tv').text
    
            # 添加断言,若昵称不正确,则打印错误信息
            try:
                assert 'No_matter' in name
                print('loginUser is right')
            except AssertionError as e:
                print('loginUser is Error')
    
            # 点击设置按钮,进入设置页面
            driver.find_element_by_id('com.lizi.app:id/setting_imageView').click()
            # 点击退出按钮
            driver.find_element_by_id('com.lizi.app:id/exit_button').click()
    
        def tearDown(self):
            self.driver.quit()
    
    
    if __name__ == '__main__':
        suite = unittest.TestSuite()
        suite.addTest(LoginTestLizi('startAPP'))
        suite.addTest(LoginTestLizi('test_login'))
        filename = 'd:\app.html'
        fb = open(filename, 'wb')
        runner = HTMLTestRunner.HTMLTestRunner(stream=fb, title='liziapptestreport', description='liziapp')
        runner.run(suite)
        fb.close()
    
  • 相关阅读:
    WEB测试用例(十五)
    WEB测试用例(十二)
    WEB测试用例(九)
    WEB测试用例(六)
    WEB测试用例(四)
    WEB测试用例(一)
    WEB测试方法(十一)
    WEB测试方法(十)
    Python 知识要点:对象的 init 和 del 方法
    Python 知识要点:类 和 对象
  • 原文地址:https://www.cnblogs.com/graybird/p/11306721.html
Copyright © 2020-2023  润新知