標籤:frame failed 環境 pre att href 詳細說明 2016年 bsp
在UI自動化測試中,有時候經常會提示跑用例失敗,在單步或單個用例調試時,用例卻成功,這個失敗的因素主要有環境、代碼或前端定位等原因。
可以看這篇文章《我們是如何讓UI測試變得穩定的》中有詳細說明,但是,在這裡,我們不討論問題,我們來看看最佳化
項目中原來的自動化架構是基本nose的,nose中有一個選項為:
--failed Run the tests that failed in the last test run.
可以單獨運行上次測試中失敗的用例,但貌似與我的想法有點背離,我的需求是失敗後再運行一次用例,然後報告可以正常輸出
無專屬偶,正好看到有一個flaky可以支援這種需求,具體的介紹和安裝,有前輩寫了:http://blog.csdn.net/liuchunming033/article/details/45916389
但在nose架構中有點差異,如下:
#coding:utf-8‘‘‘Created on 2016年6月22日@author: huzq‘‘‘from nose.tools import with_setupimport loggingfrom test_case import newfrom nose.tools import ok_from nose.tools import eq_import noseimport osfrom nose.plugins.attrib import attrfrom nose.plugins.skip import SkipTestimport sysfrom pdb import set_trace#TODO:jfjfjflog = logging.getLogger(__name__)@attr(mode=1) def test_learn_1(): u‘‘‘測試取消‘‘‘ print ‘xxx‘ #raise SkipTest #print "test_lean_1" #pass #assert 1==2 eq_(6, 7, msg=u"錯誤")@attr(mode=2) def test_lean_2(): u‘‘‘測試失敗‘‘‘ try: print "test_learn_2" ok_(4==3,msg="xxx") print sys._getframe().f_code.co_name except Exception: print sys._getframe().f_code.co_name @attr(mode=2) def test_lean_3(): u‘‘‘測試成功‘‘‘ pass def setUp(): #set_trace() print "0001 test setUp" def tearDown(): print "0001 test teardown"
使用flaky方法如下:
E:\workspace\nosetest_lear\test_case>nosetests -v test_case_0001.py --with-flaky #帶flaky運行,預設運行一次,最後會輸出flaky簡要報告E:\workspace\nosetest_lear\test_case>nosetests -v test_case_0001.py --with-flaky --no-flaky-report #沒有flaky報告輸出E:\workspace\nosetest_lear\test_case>nosetests -v test_case_0001.py --with-flaky --no-flaky-report --max-runs=3 --min-passes=1 #成功後只運行一次,失敗後運行2次
在UI自動化測試中使用flaky外掛程式運行失敗用例