title: Selenium login test doesn't accept pytest fixtures for login or refuses to connect
body: <p>I'm getting desperate because I can't seem to find a solution for what I thought would be used by everyone out there.</p>
  
  <p>I want to test a simple login with selenium and pytest with a live_server url. According to pytest-django doc, a simple fixture called <code>live_server</code> should do the trick (<a href="https://pytest-django.readthedocs.io/en/latest/helpers.html#live-server" rel="nofollow noreferrer">https://pytest-django.readthedocs.io/en/latest/helpers.html#live-server</a>). </p>
  
  <p>Unfortunately when I pass this fixture to my test and try to visit my website with it I get:</p>
  
  <blockquote>
    <p>localhost refused to connect</p>
  </blockquote>
  
  <p>for example for this:</p>
  
  <pre><code>    def test_selenium(self, live_server, create_staff_user_in_db):
          browser = webdriver.Remote(
              command_executor='http://selenium:4444/wd/hub',
              desired_capabilities=DesiredCapabilities.CHROME,
          )
  
          browser.get(live_server.url)
  </code></pre>
  
  <p>Leveraging this question <a href="https://stackoverflow.com/questions/56194838/">Selenium unable to login to Django LiveServerTestCase</a> I am trying to use a different server-fixture which then connects me and I can see my website in my VNC viewer.</p>
  
  <pre><code>@pytest.fixture
  def test_server() -&gt; LiveServer:
      addr = socket.gethostbyname(socket.gethostname())
      server = LiveServer(addr)
      yield server
      server.stop()
  </code></pre>
  
  <p>But with this I am now not able to login to my website if I create users in the db with my fixtures. Even though it seems like users are actually created. So my test now looks like: </p>
  
  <pre><code>
    def test_selenium(self, test_server, create_staff_user_in_db):
          browser = webdriver.Remote(
              command_executor='http://selenium:4444/wd/hub',
              desired_capabilities=DesiredCapabilities.CHROME,
          )
  
          browser.get(f"{live_server.url}/login")
          input_username = browser.find_element_by_name('username')
          input_password = browser.find_element_by_name('password')
          input_username.send_keys('testuserstaff')
          input_password.send_keys('mypasswordstaff')
          browser.find_element_by_xpath(
              '//*[@id="page-top"]/div[1]/div/div/div/div/form/button'
          ).click()
  
  </code></pre>
  
  <p>And my user fixture is: </p>
  
  <pre><code>@pytest.fixture()
  def create_staff_user_in_db():
      User = get_user_model()
      staff_user = User.objects.create_user(
          username="testuserstaff",
          password="mypasswordstaff",
      )
      staff_user.is_staff = True
      staff_user.save()
  
      return staff_user
  </code></pre>
  
  <p>The tests visits my login page and fails to log in. I am 100% certain that I am using the right credentials. </p>
  
  <p>If I print out for debugging I also can verify that my user is in my db: </p>
  
  <pre><code>print(u.username) ==&gt; testuserstaff
  print(u.password) ==&gt; igetthehashofthepassword
  print(User.objects.count()) ==&gt; 1 
  </code></pre>
  
  <p>Thus I assume the db that is being created by pytest is filled with this user I pass as fixture. Now somehow my live server is either not using the db or not recognising the fixtures.</p>
  
  <p>It must be connected to the live_server/test_server fixture. I would be supergrateful for any help. I feel like I am so close but I just can't seem to find out why it doesn't log in.</p>
  
  <p>What else have I tried: 
  1) Login in with users that are in my development db. No success. So I am wondering: What db is then be used?</p>
  
  <p>2) I tried to setup pytest-selenium library. If I try to load a page I get <code>selenium.common.exceptions.SessionNotCreatedException: Message: Unable to create session</code></p>
  
  <p>3) I tried to work with StaticLiveServerCase, but this is not an option since I need to pass fixtures as an argument. </p>
  
  <p>4) I searched everywhere on the web and cannot find anything else </p>
  
  <p>Also good to know: </p>
  
  <p>I am running this in a docker environment (happy to share if it helps)</p>
  
  <p>So my stack is basically:
  Docker, Django, Pytest, selenium</p>
  
  <p>Again, would really appreciate a hand here. Thanks so much in advance</p>
  
  <p>EDIT: </p>
  
  <p>My docker-compose file: </p>
  
  <pre><code>version: '3'
  
  volumes:
    local_postgres_data: {}
    local_postgres_data_backups: {}
  
  services:
    django:
      build:
        context: .
        dockerfile: ./compose/local/django/Dockerfile
      image: mywebsite_local_django
      depends_on:
        - postgres
      volumes:
        - .:/app
      env_file:
        - ./.envs/.local/.django
        - ./.envs/.local/.postgres
      ports:
        - "8000:8000"
      command: /start
  
    selenium:
      image: selenium/standalone-chrome-debug
      ports:
        - 4444:4444
        - 5900:5900
  
    postgres:
      build:
        context: .
        dockerfile: ./compose/production/postgres/Dockerfile
      image: mywebsite_production_postgres
      volumes:
        - local_postgres_data:/var/lib/postgresql/data
        - local_postgres_data_backups:/backups
      env_file:
        - ./.envs/.local/.postgres
  </code></pre>