Django selenium LiveServerTestCase

I have a problem with selenium and LiveServerTestCase. When I start ./manage.py test functional_tests, it loads the page "Title: page loading problem. Body: unable to connect ..."

functional_tests.py:

from selenium import webdriver
from django.test import LiveServerTestCase

class GeneralFunctionalTests(LiveServerTestCase):
    def setUp(self):
        self.browser = webdriver.Chrome()
        self.browser.implicitly_wait(3)

    def tearDown(self):
        self.browser.quit()

    def test_can_navigate_site(self):
        self.browser.get('http://localhost:8000')
        assert 'Django' in self.browser.title

I tried setting Up and tearDown using classmethod:

@classmethod
def setUpClass(cls):
    super(MySeleniumTests, cls).setUpClass()
    cls.browser = WebDriver()
...

The result is the same. But I could load any other pages on the network with self.browser.get('http://example.com'). Selenium updated.

Thanks!

+9
source share
3 answers

What are you doing wrong?

LiveServerTestCase 8081, URL- 8000. , 8000, .

LiveServerTestCase:

: localhost:8081 URL- self.live_server_url.

?

1. URL-

URL, 8081.

def test_can_navigate_site(self):
    self.browser.get('http://localhost:8081') # change the port
    assert 'Django' in self.browser.title

2. URL-

live_server_url , @yomytho.

def test_can_navigate_site(self):
    self.browser.get(self.live_server_url) # use the live server url
    assert 'Django' in self.browser.title

3. 8000

Django 1.10 8000 --liveserver, liveserver 8000.

$ ./manage.py test --liveserver=localhost:8000 # run liveserver on port 8000

Django 1.11, :

class MyTestCase(LiveServerTestCase):
    port = 8000

    def test_can_navigate_site(self):
        ....
+16

: , http://localhost:8081.

- self.live_server_url:

    def test_can_navigate_site(self):
        self.browser.get(self.live_server_url)
+5

, Django 1.11 (LiveServerTestCase):

localhost 0, , . URL- self.live_server_url .

... self.live_server_url.

+3

Source: https://habr.com/ru/post/1609367/


All Articles