Работа над TDD для Python, глава 5, Django 1.8, Python 2.7 и после введения токенов CSRF все становится странным. Я прочитал множество других постов и смог решить большинство проблем, но у меня возникают проблемы, когда я обдумываю этот вопрос ...
Я получаю исключение StaleReferenceException, но не могу воспроизвести. Это приходит с перерывами. Если я запускаю файл functions_test.py два или три раза подряд, тест, наконец, вернется, как и ожидалось ...
Я не уверен, что это проблема времени или что-то еще. Любые идеи о том, как отследить это?
(venv_unittesting) roadblock:superlists Admin$ python functional_test.py
E
======================================================================
ERROR: test_open_home_page_header_input_table (__main__.NewVisitorTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "functional_test.py", line 39, in test_open_home_page_header_input_table
rows = table.find_elements_by_tag_name('tr')
File "/Users/Admin/coding/django/venv_unittesting/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 320, in find_elements_by_tag_name
return self.find_elements(by=By.TAG_NAME, value=name)
File "/Users/Admin/coding/django/venv_unittesting/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 680, in find_elements
{"using": by, "value": value})['value']
File "/Users/Admin/coding/django/venv_unittesting/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "/Users/Admin/coding/django/venv_unittesting/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "/Users/Admin/coding/django/venv_unittesting/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
StaleElementReferenceException: Message: The element reference of <table id="id_list_table"> is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
----------------------------------------------------------------------
Ran 1 test in 9.359s
FAILED (errors=1)
(venv_unittesting) roadblock:superlists Admin$ python functional_test.py
F
======================================================================
FAIL: test_open_home_page_header_input_table (__main__.NewVisitorTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "functional_test.py", line 43, in test_open_home_page_header_input_table
table.text,)
AssertionError: Not located on this page:
Buy Peacock Feathers
----------------------------------------------------------------------
Ran 1 test in 8.907s
FAILED (failures=1)
(venv_unittesting) roadblock:superlists Admin$
Functional_test.py
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import unittest
import time
class NewVisitorTest(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(2)
def tearDown(self):
self.browser.quit()
# self.fail('Finish Testing! or put next task here')
#A new user heard about a Todo list and want to to
# Open the add
def test_open_home_page_header_input_table(self):
self.browser.get('http://localhost:8000')
self.assertIn('To-Do', self.browser.title)
header_text = self.browser.find_element_by_tag_name('h1').text
self.assertIn('To-Do', header_text)
inputbox = self.browser.find_element_by_id('id_new_item')
self.assertEqual(inputbox.get_attribute('placeholder'),
'Enter a to-do item')
inputbox.send_keys('Buy peacock Feathers')
inputbox.send_keys(Keys.ENTER)
# time.sleep(10)
table = self.browser.find_element_by_id('id_list_table')
rows = table.find_element_by_tag_name('tr')
# self.assertTrue(
# any(row == '1: Buy Peacock Feathers' for row in rows),
# 'Not located on this page')
self.assertIn('1: Buy peacock feathers', [row.text for row in rows])
if __name__ == '__main__':
unittest.main()