I'm in the beginning phase of developing a webapp with Django. I'm using a headless selenium setup in Vagrant.
Accessing the pages works fine but in the following test it just hangs. I not sure whether this is due to compatibility between selenium and my firefox version.
The pip3 freeze of my test environment:
coverage==4.0.3
defusedxml==0.4.1
Django==1.9.1
django-allauth==0.24.1
oauthlib==1.0.3
psycopg2==2.6.1
python3-openid==3.0.9
requests==2.9.1
requests-oauthlib==0.6.0
selenium==2.49.0
wheel==0.24.0
xvfbwrapper==0.2.7
firefox -v
Mozilla Firefox 43.0.4
I'll start with the class I wrote to test allauth (Google login) than the specific function which hangs.
# -*- coding: utf-8 -*-
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.core.urlresolvers import reverse
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from xvfbwrapper import Xvfb
class TestGoogleLogin(StaticLiveServerTestCase):
def setUp(self):
self.vdisplay = Xvfb()
self.vdisplay.start()
self.browser = webdriver.Firefox()
self.browser.maximize_window()
self.browser.implicitly_wait(3000)
self.browser.wait = WebDriverWait(self.browser, 5)
def tearDown(self):
self.browser.quit()
self.vdisplay.stop()
def get_element_by_id(self, element_id):
return self.browser.wait.until(EC.presence_of_element_located(
(By.ID, element_id)))
def get_button_by_id(self, element_id):
return self.browser.wait.until(EC.element_to_be_clickable(
(By.ID, element_id)))
def get_full_url(self, namespace):
return self.live_server_url + reverse(namespace)
The following test hangs.
def test_google_login(self):
self.browser.get(self.get_full_url("home"))
google_login = self.get_element_by_id("google_login")
with self.assertRaises(TimeoutException):
self.get_element_by_id("logout")
self.assertEqual(
google_login.get_attribute("href"),
self.live_server_url + "/accounts/google/login")
google_login.click()
with self.assertRaises(TimeoutException):
self.get_element_by_id("google_login")
google_logout = self.get_element_by_id("logout")
google_logout.click()
google_login = self.get_element_by_id("google_login")
The weird thing is if I take everything out and only run the first two sentences it passes. However, when I insert the with statement it hangs!
If I run the two first sentences and assertEqual the href attribute (so without the with statement and everything else) it passes. When I also add in the google_login.click it hangs again.
When I CTRL-C the test I get the following Traceback:
======================================================================
ERROR: test_google_login (functional_tests.test_allauth.TestGoogleLogin)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/vagrant/project/functional_tests/test_allauth.py", line 40, in test_google_login
self.get_element_by_id("logout")
File "/home/vagrant/project/functional_tests/test_allauth.py", line 27, in get_element_by_id
(By.ID, element_id)))
File "/home/vagrant/.virtualenvs/test/lib/python3.4/site-packages/selenium/webdriver/support/wait.py", line 71, in until
value = method(self._driver)
File "/home/vagrant/.virtualenvs/test/lib/python3.4/site-packages/selenium/webdriver/support/expected_conditions.py", line 59, in __call__
return _find_element(driver, self.locator)
File "/home/vagrant/.virtualenvs/test/lib/python3.4/site-packages/selenium/webdriver/support/expected_conditions.py", line 274, in _find_element
return driver.find_element(*by)
File "/home/vagrant/.virtualenvs/test/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 712, in find_element
{'using': by, 'value': value})['value']
File "/home/vagrant/.virtualenvs/test/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 199, in execute
response = self.command_executor.execute(driver_command, params)
File "/home/vagrant/.virtualenvs/test/lib/python3.4/site-packages/selenium/webdriver/remote/remote_connection.py", line 395, in execute
return self._request(command_info[0], url, body=data)
File "/home/vagrant/.virtualenvs/test/lib/python3.4/site-packages/selenium/webdriver/remote/remote_connection.py", line 426, in _request
resp = self._conn.getresponse()
File "/usr/lib/python3.4/http/client.py", line 1171, in getresponse
response.begin()
File "/usr/lib/python3.4/http/client.py", line 351, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.4/http/client.py", line 321, in _read_status
raise BadStatusLine(line)
http.client.BadStatusLine: ''
Hopefully someone is able to help me out with this. Thanks in advance!!