在代碼中用try..except捕獲異常截圖后,HTMLTestRunner生成的測試報告中,用例的執行結果為pass
解決辦法為:
在try..except后加raise,只要再加個raise就行了
def test_bangban_login(self): try: WebDriverWait(self.driver,10).until( EC.presence_of_element_located((By.ID,'com.cbwlkj.cyzb:id/contact_phone1')) ) self.driver.find_element_by_id('com.cbwlkj.cyzb:id/contact_phone1').send_keys('18602508223') time.sleep(5) except TimeoutException: print u'達人登錄頁面加載失敗' funcName = sys._getframe().f_code.co_name print funcName pngfile = "E:\\appium_code\\png\\" + funcName + timestr + ".png" print pngfile self.driver.get_screenshot_as_file(pngfile) raise
執行結束后,生成的測試報告中,該條case的結果為error