I am using Ubuntu 16.04. I installed Django 1.9.7 and selenium 2.53.5 in a virtual environment.
I follow Harry J. W. Percival book Test Driven Development with Python, and I am currently in the first tutorial (Using Selenium to Test User Interaction) for functional tests in chapter 4. The code is as follows
from selenium import webdriver from selenium.webdriver.common.keys import Keys import unittest class NewVisitorTest(unittest.TestCase): def setUp(self): self.browser = webdriver.Firefox() self.browser.implicitly_wait(3) def tearDown(self): self.browser.quit() def test_can_start_a_list_and_retrieve_it_later(self):
Now, after starting the Django server, if I run the selenium script with python3 functional_tests.py , I get seemingly random error reports with a bunch of traces, three of which are given below
E ====================================================================== ERROR: test_can_start_a_list_and_retrieve_it_later (__main__.NewVisitorTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "functional_tests.py", line 8, in setUp self.browser = webdriver.Firefox() File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 81, in __init__ self.binary, timeout) File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/firefox/extension_connection.py", line 51, in __init__ self.binary.launch_browser(self.profile, timeout=timeout) File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser self._wait_until_connectable(timeout=timeout) File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 98, in _wait_until_connectable raise WebDriverException("The browser appears to have exited " selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details. ---------------------------------------------------------------------- Ran 1 test in 3.081s FAILED (errors=1)
or
E ====================================================================== ERROR: test_can_start_a_list_and_retrieve_it_later (__main__.NewVisitorTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "functional_tests.py", line 9, in setUp self.browser.implicitly_wait(3) File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 689, in implicitly_wait self.execute(Command.IMPLICIT_WAIT, {'ms': float(time_to_wait) * 1000}) File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 234, in execute response = self.command_executor.execute(driver_command, params) File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 401, in execute return self._request(command_info[0], url, body=data) File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 432, in _request resp = self._conn.getresponse() File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse response.begin() File "/usr/lib/python3.5/http/client.py", line 297, in begin version, status, reason = self._read_status() File "/usr/lib/python3.5/http/client.py", line 266, in _read_status raise RemoteDisconnected("Remote end closed connection without" http.client.RemoteDisconnected: Remote end closed connection without response ---------------------------------------------------------------------- Ran 1 test in 2.437s FAILED (errors=1)
or
E ====================================================================== ERROR: test_can_start_a_list_and_retrieve_it_later (__main__.NewVisitorTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "functional_tests.py", line 20, in test_can_start_a_list_and_retrieve_it_later header_text = self.browser.find_element_by_tag_name('h1').text File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 389, in find_element_by_tag_name return self.find_element(by=By.TAG_NAME, value=name) File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 745, in find_element {'using': by, 'value': value})['value'] File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 234, in execute response = self.command_executor.execute(driver_command, params) File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 401, in execute return self._request(command_info[0], url, body=data) File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 432, in _request resp = self._conn.getresponse() File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse response.begin() File "/usr/lib/python3.5/http/client.py", line 297, in begin version, status, reason = self._read_status() File "/usr/lib/python3.5/http/client.py", line 266, in _read_status raise RemoteDisconnected("Remote end closed connection without" http.client.RemoteDisconnected: Remote end closed connection without response ---------------------------------------------------------------------- Ran 1 test in 3.693s
Even before these errors, selenium will randomly show Remote end closed connection , and then work without errors if the command was executed again, without changing the code.
Can someone explain what is happening?