0

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)
1
  • What error do you see when using setUp? Probably you will need to use tearDown to clean the objects created on setUp. – João Farias Jul 28 '20 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.