zoukankan      html  css  js  c++  java
  • Appium+python 一个简单的登录测试实例

    # 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['platformVersion'] = '6.0.1'  # 设备系统版本
            desired_caps['deviceName'] = '270f2988'  # 设备名称
            desired_caps['appPackage'] = 'com.lizi.app'  # 测试app包名
            desired_caps['appActivity'] = '.activity.MainActivity'  # 测试appActivity
            self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)  # 启动app
    
        def test_login(self):
            driver = self.driver
            # 进入首页后点击‘我的’按钮
            driver.find_element_by_name(u'我的').click()
            time.sleep(2)
            # 点击登录头像按钮,进行登录,跳转到登录界面
            driver.find_element_by_id('com.lizi.app:id/user_login_iv').click()
            time.sleep(2)
            # 输入用户名
            driver.find_element_by_id('com.lizi.app:id/zhanghao_edittext').send_keys('18267200735')
            # 输入密码
            driver.find_element_by_id('com.lizi.app:id/password_edittext').send_keys('password')
            # 点击确认登录按钮
            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('test_login'))
        filename = 'C:\Temp\app.html'
        fb = file(filename, 'wb')
        runner = HTMLTestRunner.HTMLTestRunner(stream=fb, title='liziapptestreport', description='liziapp')
        runner.run(suite)
        fb.close()
  • 相关阅读:
    python 发邮件乱码
    膳魔师杯使用注意事项
    了解指针,分分钟的事情 C++筆記--指針
    海淘攻略
    【转】Cocos2dx.3x入门三部曲
    在Windows7上搭建Cocos2d-x 3.2alpha0开发环境
    黑苹果 MAC OS X 10.10.2 安装流程
    Linux 下如何查找木马并处理
    js如何判断访问是来自搜索引擎(蜘蛛人)还是直接访问
    泰*网 Centos 一些命令
  • 原文地址:https://www.cnblogs.com/forcepush/p/7090640.html
Copyright © 2011-2022 走看看