问答 appium+python 断言,使用 self.assertIsNone (element,'存在 element,Fail'),若 element 不存在,用例不会 pass,脚本报错:selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.

五棵木 · 2017年06月29日 · 最后由 五棵木 回复于 2017年06月29日 · 2359 次阅读
class case_mypushlish_return(unittest.TestCase):

    def setUp(self):
        public.setUp.setUp(self)

    def tearDown(self):
        self.dr.quit()

    @user1imer
    def test_mypushlish_return(self):
        self.assertIsNone(self.dr.find_element_by_name(taskname_2),'存在taskname_2,Fail')

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(case_mypushlish_return)
    unittest.TextTestRunner(verbosity=2).run(suite)

报错:

Traceback (most recent call last):
File "D:\AutoWork\自动化测试项目\Milan_H5_Auto\public\fn_timer.py", line 16, in function_timer
result = function(*args, **kwargs)
File "D:/AutoWork/自动化测试项目/Milan_H5_Auto/test_case/case_mypushlish_return.py", line 134, in test_mypushlish_return
self.assertIsNone(self.dr.find_element_by_name(taskname_2),'存在 taskname_2,Fail')
File "D:\AutoWork\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 381, in find_element_by_name
return self.find_element(by=By.NAME, value=name)
File "D:\AutoWork\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 787, in find_element
'value': value})['value']
File "D:\AutoWork\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in execute
self.error_handler.check_response(response)
File "D:\AutoWork\Python\lib\site-packages\appium\webdriver\errorhandler.py", line 29, in check_response
raise wde
File "D:\AutoWork\Python\lib\site-packages\appium\webdriver\errorhandler.py", line 24, in check_response
super(MobileErrorHandler, self).check_response(response)
File "D:\AutoWork\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.


有人知道 assertIsNone 的正确用法吗?

共收到 1 条回复 时间 点赞

已经换种方式解决

class mytest(unittest.TestCase):
    ##初始化工作
    def setUp(self):
          pass

    def tearDown(self):
        self.dr.quit()

    def testfun(self):
        pass_1 = False
        try:
            self.dr.find_element_by_id('11')
            print('pass')
        except:
            pass_1 = True
        print(pass_1)
        if pass_1 == True:
            self.assertIsNone(None, '存在wulh发起的任务,Fail')
        else:
            self.assertIsNone(not None, '存在wulh发起的任务,Fail')
if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(mytest)
    unittest.TextTestRunner(verbosity=2).run(suite)
五棵木 关闭了讨论 06月29日 11:23
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册