首页 新闻 赞助 找找看

unittest 中断言问题

0
悬赏园豆:50 [待解决问题]

在做自动化测试关键字驱动框架时遇到这样一个问题

所有的操作 都写在excel 中,类似于

在框架中有这样一个类,定义了所有excel 种关键字对应的操作,代码如下(只列出部分)

class KeyWordsAction():
    objectMap = ObjectMap.ObjcetMap(Constants.Constants.path_configurationFile)
    driver = None

    @staticmethod
    def open_browser(browserName):
        try:
            if str(browserName).lower() == "ie":
                #或许还要指定驱动
                KeyWordsAction.driver = webdriver.Ie()
            elif str(browserName).lower() == "chrome":
                #或许还要指定驱动
                KeyWordsAction.driver = webdriver.Chrome()
            elif str(browserName).lower() == "firefox":
                #或许还要指定驱动
                KeyWordsAction.driver = webdriver.Firefox()
        except Exception,e:
            print str(e)

    @staticmethod
    def navigate(url):
        try:
            KeyWordsAction.driver.get(url)
        except Exception,e:
            print str(e)

    @staticmethod
    def assertIn(testcase,assertString):
        try:
            testcase.assertTrue(assertString in KeyWordsAction.driver.page_source)
        except AssertionError ,msg:
            print msg

在unittest,依次读取excel中的操作步骤,利用发射原理,将关键字 转换成对应的方法,执行过程中 遇到这样一个问题,进行 断言时,其实已经断言失败了,但 还是 显示 整个测试结果都成功

 def test_baiduByExcel(self):
        for i in range(1,ExcelUtil.ExcelUtil.getLastRowNum()):
            keyWord = ExcelUtil.ExcelUtil.getCellData(i,Constants.Constants.Col_KeyWordAction)
            value = ExcelUtil.ExcelUtil.getCellData(i,Constants.Constants.Col_ActionValue)


            if hasattr(KeyWordsAction.KeyWordsAction,str(keyWord)):
                func = getattr(KeyWordsAction.KeyWordsAction,str(keyWord))
                if(str(keyWord).startswith("assert")):
                    func(self,value)    #这里执行断言操作
                else:
                    func(value)
            else:
                print '没有找到相应的方法'

执行结果如下:

请教下这是 为什么?

大愚者的主页 大愚者 | 初学一级 | 园豆:106
提问于:2017-07-07 17:39
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册