appium學習【二】:用try捕獲異常后,用例的執行結果為pass


在代碼中用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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM