object has no attribute 'assertEqual'

醉酒当歌 提交于 2021-01-28 01:03:10

问题


Getting object has no attribute 'assertEqual' when I try to use the below statement in my code:

self.assertEqual("IRELAND INSTITUTE OF PITTSBURGH", driver.find_element_by_id("cname").get_attribute("value"))

This works fine when I use in my test case instead. I understand that it is a good practice to put asserts in the test case. But I would like to understand why this piece of code cannot work in the page instead if we are following page object pattern


回答1:


assertEqual is a method that belongs to the class TestCase from the unittest module (python unittest docs).

The reason it works in your test code is most likely because you test class inherits from the TestCase class.

class YourTestClass(unittest.TestCase):
    pass

You could just use the keyword assert:

assert "IRELAND INSTITUTE OF PITTSBURGH" == driver.find_element_by_id("cname").get_attribute("value")

If the assertion fails, it will raise an AssertionError.



来源:https://stackoverflow.com/questions/42859577/object-has-no-attribute-assertequal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!