# 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()
Appium+python 一個簡單的登錄測試實例
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.