testcontainers / testcontainers-python

Testcontainers is a Python library that providing a friendly API to run Docker container. It is designed to create runtime environment to use during your automatic tests.
https://testcontainers-python.readthedocs.io/en/latest/
Apache License 2.0
1.51k stars 281 forks source link

Bug: Selenium TypeError: WebDriver.__init__() got an unexpected keyword argument 'desired_capabilities' #573

Closed M4KIF closed 3 months ago

M4KIF commented 3 months ago

Describe the bug

Using pytest-selenium and test containers, after:

with BrowserWebDriverContainer(_capabilities=DesiredCapabilities.CHROME,_
                                       image="selenium/standalone-chrome") as chrome:
            chrome.start()
            driver = chrome.get_driver()

I receive: TypeError: WebDriver.__init__() got an unexpected keyword argument 'desired_capabilities',

It is said, that the variable desired_capabilities is deprecated in current selenium:

 @wait_container_is_ready(urllib3.exceptions.HTTPError)
    def _connect(self):
        from selenium import webdriver
        return webdriver.Remote(
            command_executor=(self.get_connection_url()),
            _desired_capabilities_=self.capabilities)

there should be the possibility to use options.

Could I ask for guidance and/or a way of helping with this issue? Or maybe just I am in the wrong, please correct me if that is the case. Thank you.

To Reproduce

Provide a self-contained code snippet that illustrates the bug or unexpected behavior. Ideally, send a Pull Request to illustrate with a test that illustrates the problem.

raise RuntimeError("something went wrong")

Runtime environment

Provide a summary of your runtime environment. Which operating system, python version, and docker version are you using? What is the version of testcontainers-python you are using? You can run the following commands to get the relevant information.

# Get the operating system information (on a unix os).
$ uname -a
# Get the python version.
$ python --version
# Get the docker version and other docker information.
$ docker info
# Get all python packages.
$ pip freeze
alexanderankin commented 3 months ago

Selenium changed this on their side, I remember updating it over here but to triage can you provide your pip freeze output

On Tue, May 14, 2024, 6:20 AM Jakub Koterba @.***> wrote:

Describe the bug

Using pytest-selenium and test containers, after:

with BrowserWebDriverContainer(capabilities=DesiredCapabilities.CHROME, image="selenium/standalone-chrome") as chrome: chrome.start() driver = chrome.get_driver()

I receive: TypeError: WebDriver.init() got an unexpected keyword argument 'desired_capabilities',

It is said, that the variable desired_capabilities is deprecated in current selenium: @wait_container_is_ready(urllib3.exceptions.HTTPError) def _connect(self): from selenium import webdriver return webdriver.Remote( command_executor=(self.get_connection_url()), desired_capabilities=self.capabilities)

there should be the possibility to use options.

Could I ask for guidance and/or a way of helping with this issue? Or maybe just I am in the wrong, please correct me if that is the case. Thank you.

To Reproduce

Provide a self-contained code snippet that illustrates the bug or unexpected behavior. Ideally, send a Pull Request to illustrate with a test that illustrates the problem.

raise RuntimeError("something went wrong")

Runtime environment

Provide a summary of your runtime environment. Which operating system, python version, and docker version are you using? What is the version of testcontainers-python you are using? You can run the following commands to get the relevant information.

Get the operating system information (on a unix os).

$ uname -a# Get the python version. $ python --version# Get the docker version and other docker information. $ docker info# Get all python packages. $ pip freeze

— Reply to this email directly, view it on GitHub https://github.com/testcontainers/testcontainers-python/issues/573, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACECGJFMRHPKXWW6CUCH5CTZCHQNTAVCNFSM6AAAAABHV37OFCVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI4TKMBUGA3TSNQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

M4KIF commented 3 months ago

Thank you for such a quick answer,

pip freeze:
attrs==23.2.0
black==24.4.2
certifi==2024.2.2
charset-normalizer==3.3.2
click==8.1.7
docker==7.0.0
execnet==2.1.1
h11==0.14.0
idna==3.7
iniconfig==2.0.0
Jinja2==3.1.3
MarkupSafe==2.1.5
mypy-extensions==1.0.0
outcome==1.3.0.post0
packaging==24.0
pathspec==0.12.1
platformdirs==4.2.1
pluggy==1.5.0
PySocks==1.7.1
pytest==8.1.1
pytest-base-url==2.1.0
pytest-html==4.1.1
pytest-metadata==3.1.1
pytest-selenium==4.1.0
pytest-variables==3.1.0
pytest-xdist==3.5.0
python-dotenv==1.0.1
requests==2.31.0
selenium==4.20.0
sniffio==1.3.1
sortedcontainers==2.4.0
tenacity==8.2.3
testcontainers==4.4.0
testcontainers-core==0.0.1rc1
testcontainers-selenium==0.0.1rc1
trio==0.25.0
trio-websocket==0.11.1
typing_extensions==4.11.0
urllib3==2.2.1
webdriver-manager==4.0.1
wrapt==1.16.0
wsproto==1.2.0
alexanderankin commented 3 months ago

Yep sorry for the delay in response but I see you the 0.0.1 version of things installed.

The packages used to be testcontainers-thing and are now testcontainers[thing] so feel free to try with the latest selenium extra "pip install testcontainers[selenium]" and without the "-selenium" package

On Tue, May 14, 2024, 6:55 AM Jakub Koterba @.***> wrote:

Thank you for such a quick answer,

pip freeze: attrs==23.2.0 black==24.4.2 certifi==2024.2.2 charset-normalizer==3.3.2 click==8.1.7 docker==7.0.0 execnet==2.1.1 h11==0.14.0 idna==3.7 iniconfig==2.0.0 Jinja2==3.1.3 MarkupSafe==2.1.5 mypy-extensions==1.0.0 outcome==1.3.0.post0 packaging==24.0 pathspec==0.12.1 platformdirs==4.2.1 pluggy==1.5.0 PySocks==1.7.1 pytest==8.1.1 pytest-base-url==2.1.0 pytest-html==4.1.1 pytest-metadata==3.1.1 pytest-selenium==4.1.0 pytest-variables==3.1.0 pytest-xdist==3.5.0 python-dotenv==1.0.1 requests==2.31.0 selenium==4.20.0 sniffio==1.3.1 sortedcontainers==2.4.0 tenacity==8.2.3 testcontainers==4.4.0 testcontainers-core==0.0.1rc1 testcontainers-selenium==0.0.1rc1 trio==0.25.0 trio-websocket==0.11.1 typing_extensions==4.11.0 urllib3==2.2.1 webdriver-manager==4.0.1 wrapt==1.16.0 wsproto==1.2.0

— Reply to this email directly, view it on GitHub https://github.com/testcontainers/testcontainers-python/issues/573#issuecomment-2109897400, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACECGJC7BFMLIKFJ473IWYLZCHUTNAVCNFSM6AAAAABHV37OFCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBZHA4TONBQGA . You are receiving this because you commented.Message ID: @.***>

M4KIF commented 3 months ago

also, I've didn't saw that the selenium options have the to_capabilities() method. That actually resolves the problem for me. Thank you for the tip with new package naming scheme. I will close the issue, have a good day!

M4KIF commented 3 months ago

Thank you!