Docker selenium not redirecting on another page in django test

I have some issue with docker selenium. For example, I have tried it on local selenium using operadriver, so redirecting to another page, after submit form, was working.I want to see this result also in django selenium test, but I've just get selenium.common.exceptions.TimeoutException: Message: in waiting when url will change. This is my test code

import os
import socket
import shutil

# from pyvirtualdisplay import Display

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options

from django.test import LiveServerTestCase
from django.conf import settings

# Create your tests here.
class LandFormTest(LiveServerTestCase):
    host = socket.gethostbyname(socket.gethostname())

    def setUp(cls):
        selenium_url = 'http://selenium:4444/wd/hub'
        options = Options()
        options.add_argument('--no-sandbox')   
        options.add_argument('--headless')
        options.add_argument("--disable-dev-shm-usage")
        options.add_argument("--ignore-certificate-errors") 
        # options.add_argument("My user agent")
        options.add_argument(f"window-size=1920,1080")
        
        cls.driver = webdriver.Remote(
            command_executor=selenium_url,
            desired_capabilities=DesiredCapabilities.CHROME,
            options=options
        )

    def test_form(self):
        try:
            driver = self.driver
            domain = self.live_server_url.split('//')[1].split(':')[0]
            if not settings.BASE_DIR.joinpath(f'templates/lands/{domain}').is_dir():
                src = f'templates/lands/quantum.localhost'
                dest = f'templates/lands/{domain}'
                shutil.copytree(src, dest)
                
            driver.get(f'{self.live_server_url}/api/v1/test/?ai=2&gi=5')

            user_firstname = WebDriverWait(driver, 10).until(
                EC.presence_of_element_located((By.NAME, "firstname"))
            )
            current_url = driver.current_url
            
            user_firstname = driver.find_element(By.NAME, 'firstname')
            user_lastname = driver.find_element(By.NAME, 'lastname')
            user_email = driver.find_element(By.NAME, 'email')
            user_phone = driver.find_element(By.NAME, 'phone')

            user_firstname.send_keys('test')
            user_lastname.send_keys('test')
            user_email.send_keys('test@gmail.com')
            user_phone.send_keys('+(846)411-36-00')

            user_phone.submit()
            
            WebDriverWait(driver, 10).until(EC.url_changes(current_url))
            print(driver.current_url)
            print(driver.page_source)
            assert 'Hello World' in driver.page_source
        except Exception as e:
            raise(e)

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

My /api/v1/test/ url get static and template in folder by domain name, so I copy the default folder "quantum.localhost" and rename it to ip of docker. The main problem is that is working locally with driver, but not with docker and django. Want to notice that I am also tried to use firefox selenium. Thanks for help!

Back to Top