appium 學習筆記(六)

2021-08-19 02:11:04 字數 2182 閱讀 7038

用htmltestrunner匯出測試報告:

fromwebdriver

importtime

importadbbase

importunittest

importhtmltestrunnercn

class

"""開心糧票"""

@classmethod

defsetupclass(cls): #準備測試環境,每個用例前執行

desired_caps = {}

desired_caps['platformname'] = 'android'

desired_caps['paltformversion'] = adbbase.platformversion()

desired_caps['devicename'] = adbbase.platformname()

globaldriver

driver = webdriver.remote(''

,desired_caps)

time.sleep(5)

deftest_login(self): #用例,以test開頭;登入測試

"""登入"""

driver.find_element_by_id("phonenumber").send_keys("13575220850")

driver.find_element_by_id("password").send_keys("q0125016")

driver.back()

driver.find_element_by_id("login").click()

time.sleep(1)

try

button = driver.find_element_by_xpath("'允許')]")

button.click()

except:

time.sleep(1)

self.assertequal(title,

"開心糧票")

deftest_billing_details(self):

"""結算詳情"""

self.assertequal(title,

"結算詳情")

@classmethod

defteardownclass(cls): #清理環境,用例執行完後執行

driver.quit()

defsuite():

suitetest = unittest.testsuite()

returnsuitetest

if__name__ == '__main__':

# unittest.main()

now = time.strftime("%y-%m-%d--%h;%m"

, time.localtime())

filepath = './report/'+ now + '.html'

fp = open(filepath,

'wb')

runner = htmltestrunnercn.htmltestrunner(

stream=fp,

title='自動化報告'

,tester='lin'

) runner.run(suite())

fp.close()

time.strftime("%y-%m-%d--%h;%m",time.localtime()) 為獲取當前時間,以「2018-04-19--22;00」的方式顯示(因為檔案命名裡不能有":",所以暫用";"替代)

filepath 為測試用例的儲存路徑

執行測試指令碼,執行完後將自動生成測試報告在./report/  資料夾裡

Appium學習筆記(六) 定位控制項

通過uiautomatorviewer.bat 工具可以檢視物件的id屬性。如果目標裝置的api level低於18則uiautomatorviewer不能獲得對應的resource id,只有等於大於18的時候才能使用。開啟uiautomatorviewer.bat工具 resource id 就...

Appium學習筆記 1 appium配置 起步

1.手機唯一id,通過命令adb devices來找,需要提前連線真機或者模擬機 2.手機版本號 4.1.1 檢視手機設定中的 關於 版本號 3.測試的裝置型別 android ios 7.編寫 冷啟動與熱啟動概念 adb logcat grep start mac adb logcat finds...

appium學習總結

driver常用方法及注意事項 常用方法 driver.findelement by.name driver.findelementbyid id driver.findelementbyname text driver.findelementbyxpath name 62 2 注意事項 使用dri...