我想进行功能测试
功能测试过程是
booksale
myproject/functional_test/test_booksale.py
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from django.test import LiveServerTestCase
from users.models import User
class OurClientLogInTest(LiveServerTestCase):
def setUp(self):
self.browser = webdriver.Firefox()
## create 1 user id
User.objects.create_user(username='MyTestID', password='123', nickname='NICKNAMETEST', phone='01011111111')
def tearDown(self):
self.browser.quit()
def test_our_client_can_log_in_this_website(self):
# url connect
self.browser.get(self.live_server_url)
# web page header title has 'Korea book'
self.assertIn('Korea book', self.browser.title)
# click log_in button in main page
log_in = self.browser.find_element_by_id('log_in')
log_in.send_keys(Keys.ENTER)
self.assertIn('로그인', self.browser.title)
# insert username, password
# click enter
username_box = self.browser.find_element_by_name('username')
password_box = self.browser.find_element_by_name('password')
username_box.send_keys('MyTestID')
password_box.send_keys('123')
self.browser.find_element_by_id('button').click()
##redirect main page
self.assertIn('Korea book', self.browser.title)
## click a button named book_sale
book_sale = self.browser.find_element_by_id('book_sale')
book_sale.send_keys(Keys.ENTER)
from IPython import embed; embed()
我命令python manage.py functional_test
它显示错误
raceback (most recent call last):
File "/Users/hanminsoo/.pyenv/versions/3.5.1/lib/python3.5/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/test/testcases.py", line 1198, in __call__
return super(FSFilesHandler, self).__call__(environ, start_response)
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 177, in __call__
response = self.get_response(request)
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/test/testcases.py", line 1181, in get_response
return self.serve(request)
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/test/testcases.py", line 1193, in serve
return serve(request, final_rel_path, document_root=self.get_base_dir())
File "/Users/hanminsoo/.pyenv/versions/study_alone/lib/python3.5/site-packages/django/views/static.py", line 54, in serve
fullpath = os.path.join(document_root, newpath)
File "/Users/hanminsoo/.pyenv/versions/3.5.1/lib/python3.5/posixpath.py", line 89, in join
genericpath._check_arg_types('join', a, *p)
File "/Users/hanminsoo/.pyenv/versions/3.5.1/lib/python3.5/genericpath.py", line 143, in _check_arg_types
(funcname, s.__class__.__name__)) from None
TypeError: join() argument must be str or bytes, not 'NoneType'
删除代码时
book_sale.send_keys(Keys.ENTER)
测试通过非常清楚
我无法理解为什么book_sale按钮不会发送ENTER KEY ..
请某些人帮帮我