这是我的代码;
from selenium import webdriver
import unittest
class NewVisitorTest(unittest.TestCase):
def setup(self):
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(5)
def teardown(self):
self.browser.quit()
def test_can_start_list_and_retrieve_later(self):
# checkout the homepage
self.browser.get('http://127.0.0.1:8000')
# check title and header
self.assertIn('To-Do', self.browser.title)
self.fail('Finish the test')
if __name__ == '__main__':
unittest.main(warnings='ignore')
会导致以下错误:
$ python3 functional_tests.py
E
======================================================================
ERROR: test_can_start_list_and_retrieve_later (__main__.NewVisitorTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "functional_tests.py", line 15, in test_can_start_list_and_retrieve_later
self.browser.get('http://127.0.0.1:8000')
AttributeError: 'NewVisitorTest' object has no attribute 'browser'
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
代码来自TDD with python
我的代码与本教程中编写的内容相匹配,但是由于页面尚未设置,因此应该产生一个assertIn错误。任何帮助将不胜感激。