Django LiveServerTestCase hangs when I run my tests

I am trying to set up LiveServerTestCase on Django 1.10.4. Whenever I run my tests the browser freezes and cannot reach the localhost. My frontend is a separate angular / react app. So, I create my static assets using the grunt build and then run collectstatic. Below is the code for my tests.

from django.test.testcases import LiveServerTestCase
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By



class ChromeTestCase(LiveServerTestCase):

    @classmethod
    def setUpClass(cls):
        super(ChromeTestCase, cls).setUpClass()
        cls.driver = webdriver.Chrome('/path/to/chromedriver')
        cls.driver.implicitly_wait(10)
        cls.wait = WebDriverWait(cls.driver, 10)

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()
        super(ChromeTestCase, cls).tearDownClass()

    def test_user_sign_up_from_form(self):
        self.driver.get('%s%s' % (self.live_server_url, '/'))

        self.wait.until(EC.presence_of_element_located((By.XPATH, '//input[@id="email"]')))
        email_input = self.driver.find_element_by_xpath(
            '//input[@id="email"]')
        email_input.send_keys("test@gmail.com")
        password_input = self.driver.find_element_by_xpath(
            '//input[@id="password"]')
        password_input.send_keys("secret")

        signup_button = self.driver.find_elements_by_xpath(
            '//*[@id="signup_button"]')
        signup_button.click()

        url = self.live_server_url + '/home'
        self.assertEquals(self.driver.current_url, url)

      

Does anyone know why my tests can't get to the test server?

Also, my test server url is https.

+3


source to share


2 answers


The problem ended up being related to middleware that redirects requests to https on production. I got my tests by uninstalling this middleware.



+2


source


You can enable DEBUG

with by LiveServerTestCase

adding the following lines:



from django.test import override_settings

@override_settings(DEBUG=True)
class ChromeTestCase(LiveServerTestCase):

      

0


source







All Articles