Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django : Connection refused to live_server_url

I'm using docker, selenium, and Django. I just realised i was doing my tests on my production database ; while i wanted to test on StaticLiveServerTestCase self-generated database.

I tried to follow that tutorial

@override_settings(ALLOWED_HOSTS=['*'])
class BaseTestCase(StaticLiveServerTestCase):
    host = '0.0.0.0'

    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.host = socket.gethostbyname(socket.gethostname())
        cls.selenium = webdriver.Remote(
            command_executor='http://hub:4444/wd/hub',
            desired_capabilities=DesiredCapabilities.CHROME,
        )
        cls.selenium.implicitly_wait(5)

    @classmethod
    def tearDownClass(cls):
        cls.selenium.quit()
        super().tearDownClass()


class MyTest(BaseTestCase):

    def test_simple(self):
        self.selenium.get(self.live_server_url)

I've no error trying to connect to the chrome-hub, but when i try to print my page_source, i'm not on my django app but on a chrome error message. Here is a part :

<div class="error-code" jscontent="errorCode" jstcache="7">ERR_CONNECTION_REFUSED</div>

I'm using docker-compose 1. Selenium.yml:

chrome:
  image: selenium/node-chrome:3.11.0-dysprosium
  volumes:
    - /dev/shm:/dev/shm
  links:
    - hub
  environment:
    HUB_HOST: hub
    HUB_PORT: '4444'

hub:
  image: selenium/hub:3.11.0-dysprosium
  ports:
    - "4444:4444"
  expose:
    - "4444"

app:
  links:
    - hub

I guess i did something wrong in my docker-compose file, but i don't manage to figure out what.

Thanks in advance !

PS : live_server_url = http://localhost:8081

like image 938
AntoineLB Avatar asked Feb 03 '26 06:02

AntoineLB


1 Answers

You need to put container_name of the container that is running Django/the tests as host when using docker-compose, i.e.

host = 'app'

For a more detailed discussion see this question

like image 196
Alexander Qiu Avatar answered Feb 05 '26 18:02

Alexander Qiu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!