我想要的功能測試send_keys不Django的測試工作
功能測試過程
- Create_user
- 使用創建的用戶
- 點擊一個名爲按鈕登錄網站
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按鈕不發送回車鍵..
請一些身體幫我
錯誤並不在此代碼,但在當表單提交 – e4c5
如果發生了什麼'book_sale'的按鈕你爲什麼不使用'book_sale.click()的''而不是send_keys()'? –
@ e4c5 ummm ,,,,我不能站在你的評論',但在提交表格時會發生什麼...... ...你能告訴我一個更容易的建議嗎? –