2017-05-16 2 views
3

Django 1.10.4를 사용하여 LiveServerTestCase를 설정하려고합니다. 테스트를 실행할 때마다 브라우저가 멈추고 localhost에 연결할 수 없습니다. 내 프론트 엔드는 별도의 각도/반응 앱입니다. 그래서 무딘 빌드를 사용하여 정적 애셋을 빌드 한 다음 collectstatic을 실행합니다. 아래는 내 테스트를위한 코드입니다.테스트를 실행할 때 Django LiveServerTestCase가 응답하지 않습니다.

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("[email protected]") 
     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) 

내 테스트가 테스트 서버에 도달 할 수없는 이유를 아는 사람이 있습니까?

또한 내 테스트 서버에서 생성하는 URL은 https입니다.

+0

당신이 당신의 JS와 네트워크를 디버깅나요? 해체에 대한 의견을 말하면 브라우저가 남아 있고 개발자 도구를 열 수 있습니다. 그리고 js에서 나는 더 안전한 phantomjs 브라우저를 발견했습니다. – XaviP

+0

콘솔을 검사 할 때 localhost : 8011 /에서 ERR_CONNECTION_REFUSED 오류가 발생하며 네트워크 탭에서 리소스 오류를로드하지 못했습니다. phantomjs 제안에 감사드립니다. – alexkeating

답변

2

문제는 생산시 https로 요청을 리디렉션하는 미들웨어와 관련이 있습니다. 나는 그 미들웨어를 제거해 내 검사를 받았다.

0

이러한 행을 추가, LiveServerTestCaseDEBUG을 활성화 할 수 있습니다

from django.test import override_settings 

@override_settings(DEBUG=True) 
class ChromeTestCase(LiveServerTestCase): 
관련 문제