I want to use setUp instead of setUpClass in my selenium tests. This code works fine and is able to get the correct host when using setUpClass:
@tag('selenium')
@override_settings(ALLOWED_HOSTS=['*'])
class BaseTestCase(StaticLiveServerTestCase):
"""
Provides base test class which connects to the Docker
container running selenium.
"""
host = '0.0.0.0'
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.host = socket.gethostbyname(socket.gethostname())
cls.selenium = webdriver.Remote(
command_executor='http://selenium_hub:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME.copy(),
)
cls.selenium.implicitly_wait(15)
How should I do it if I'm gonna use setUp?
@tag('selenium')
@override_settings(ALLOWED_HOSTS=['*'])
class BaseTestCase(StaticLiveServerTestCase):
"""
Provides base test class which connects to the Docker
container running selenium.
"""
host = '0.0.0.0'
def setUp(self) -> None:
super(BaseTestCase, self).setUp()
self.selenium = webdriver.Remote(
command_executor='http://selenium_hub:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME.copy(),
)
self.host = socket.gethostbyname(socket.gethostname())
self.selenium.implicitly_wait(15)