環境搭建html
python3
Java JDK
.netFramework
nodejs
android SDK
appium
Appium-Python-Client(pip install Appium-Python-Client)node
鏈接設備python
cmd打開命令行窗口
輸入adb connect 127.0.0.1:62001鏈接模擬器
輸入adb shell dumpsys window windows | findstr "Current"獲取當前包名
啓動appiumandroid
經常使用元素定位
driver.find_element_by_id
driver.find_element_by_class
driver.find_element_by_name
driver.find_element_by_xpath(//*[@text=‘text屬性’])web
編寫登陸腳本shell
#!/usr/bin/env python # -*- coding: utf-8 -*- from appium import webdriver import unittest import time desired_caps = { 'platformName': 'Android', 'platfromVersion': '5.1', 'deviceName': '127.0.0.1:62001', 'appPackge': 'com.xxxx.artstation', 'appActivity': 'com.xxxx.artstation.main.login.activity.LoginActivity' } # TestCase類,全部測試用例繼承的基本類 class LoginTest(unittest.TestCase): # 測試前執行的初始化工做 def setUp(self): self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) # 測試用例執行後的善後工做。如關閉數據庫鏈接,退出應用。不管寫在哪,最後一個執行 def tearDown(self): self.driver.quit() # 測試用例,必須以test開頭 def test_login(self): self.driver.find_element_by_id('com.xxxx.artstation:id/tv_sure').click() time.sleep(3) # 輸入帳號密碼 self.driver.find_element_by_id( 'com.xxxx.artstation:id/clear_edittext_username').send_keys('158xxxxxxxx') self.driver.find_element_by_id( 'com.xxxx.artstation:id/clear_edittext_password').send_keys('123456') # 點擊登陸按鈕 self.driver.find_element_by_id( 'com.xxxx.artstation:id/tv_login').click time.sleep(3)
自動生成測試報告數據庫
#!/usr/bin/env python # -*- coding: utf-8 -*- import HTMLTestRunner import unittest from testcase import test_login if __name__ == '__main__': # 實例化測試套件,定義一個測試容器 suite = unittest.TestSuite() # 加載測試用例 suite.addTest(test_login.LoginTest('test_login')) # 使用discover方法批量加載運行測試用例 # suite= unittest.defaultTestLoader.discover('../testcase','test_*.py') # runner = unittest.TextTestRunner() # 定義測試報告存放路徑和報告名稱 with open('HTMLReropt.html', 'wb')as f: runner = HTMLTestRunner.HTMLTestRunner( stream=f, verbosity=2, title='XX登陸自動化測試報告', description='執行人:嘻嘻' ) runner.run(suite) # 關閉測試報告 f.close()
馬蜂窩怎麼增長粉絲 http://blog.sina.com.cn/s/blog_184e9f38b0102yyi5.html 馬蜂窩遊記推廣 https://tieba.baidu.com/p/6427032866windows