我嘗試在通常的類中使用assertEqual並且無法從unittest.TestCase調用方法Selenium python如何從unittest.TestCase中使用assertEqual方法「沒有這樣的測試方法在<class'unittest.case.TestCase'>」
class MyPages(unittest.TestCase):
@classmethod
def setUpClass(cls):
basetest.BaseTest().open_browser('firefox')
basetest.BaseTest().login()
def testCreateFolder(self):
print "111111111"
def testCreateFolder1(self):
print "222222222"
@classmethod
def tearDownClass(cls):
basetest.BaseTest().close_browser()
而在我的BaseTest中,我想使用文本斷言進行登錄。
class BaseTest():
def open_browser(self, browser):
self.driver = config.browser[browser]
global driver
driver = self.driver
driver.get(config.url)
def login(self):
# Go to authorisation page
driver.find_element_by_xpath(link.header["Login_button"]).click()
# Get text from LOGIN label and assert it with expected text
login_text = driver.find_element_by_xpath(link.author_popup["Login_label"])
login_text.get_attribute("text")
print login_text.text
unittest.TestCase().assertEqual(1, 1, "helllllllo")
unittest.TestCase().assertEqual(login_text.text, text.author_popup["Login"],
"Wrong label on log in auth popup. Expected text:")
因此,我有以下幾點:
Error
Traceback (most recent call last):
File "D:\python\PD_Tests\pages\my_pages.py", line 17, in setUpClass
basetest.BaseTest().login()
File "D:\python\PD_Tests\tests\basetest.py", line 25, in login
unittest.TestCase().assertEqual(1, 1, "helllllllo")
File "C:\Python27\lib\unittest\case.py", line 191, in __init__
(self.__class__, methodName))
ValueError: no such test method in <class 'unittest.case.TestCase'>: runTest
我可以使用assertEqual便方法,我的方法,如果我的課是不是unittest.TestCase生成?
現在我只是使用「if」而不是assertEqual。唯一的問題是,如果我在IF中沒有相同的文本,我的項目將運行下一步,斷言將停止測試。但現在對我來說沒問題。感謝您的回答。 – Michael