AttributeError:'模块'对象没有属性'runTest'

时间:2018-11-09 21:09:22

标签: python selenium selenium-webdriver

我知道已经问过类似的问题,但是我无法在评论中找到答案。请在这里帮助我。

我有以下页面对象:

class ChatInput(BaseTest):
    def __init__(self, driver, *args, **kwargs):
        super(ChatInput, self).__init__(*args, **kwargs)
        self.driver = driver

    def get_chat_Input(self):
        return self.wait_for_element_by_xpath(elements.CHAT_INPUT, 60)

    def add_content_in_chatInput(self, msg):
        chatInput = self.get_chat_Input()
        chatInput.clear()
        chatInput.click()
        chatInput.send_keys('')
        chatInput.send_keys(msg)

        return True

我正在将该页面对象中的方法调用到测试类中。

from .components.ChatInput import ChatInput

class SmokeTest(BaseTest):
    def test_everything(self):
        env = self.getEnvConfig()
        for driver in env['DRIVERS']:
            self.configDriver(driver)
            self.driver.get(CONFIG.SITE_URL)

            self.chatInput = ChatInput(self.driver)

            assert self.chatInput.add_content_in_chatInput('Hello, this is agent QA. Please tell us, how we can help you today?')

但是当我运行测试时,出现以下错误:

 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/suite.py", line 84, in __call__
    return self.run(*args, **kwds)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/suite.py", line 122, in run
    test(result)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py", line 663, in __call__
    return self.run(*args, **kwds)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py", line 590, in run
    testMethod = getattr(self, self._testMethodName)
AttributeError: 'ChatInput' object has no attribute 'runTest'

请让我知道我在做什么错?

1 个答案:

答案 0 :(得分:1)

似乎您正在尝试测试一种称为runTest的方法。或更具体地说,在测试时,您想运行不存在的ChatInput.runTest。这就是错误消息的意思。