Skip to content

Commit

Permalink
fix(selenium): add Arg/Options to api of selenium container (#654)
Browse files Browse the repository at this point in the history
fix #652
  • Loading branch information
alexanderankin committed Aug 1, 2024
1 parent b13b43d commit e02c1b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,5 @@

intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"selenium": ("https://seleniumhq.github.io/selenium/docs/api/py/", None),
}
19 changes: 15 additions & 4 deletions modules/selenium/testcontainers/selenium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from pathlib import Path
from typing import Optional
from typing import Any, Optional

import urllib3
from typing_extensions import Self
Expand All @@ -26,7 +26,7 @@
IMAGES = {"firefox": "selenium/standalone-firefox:latest", "chrome": "selenium/standalone-chrome:latest"}


def get_image_name(capabilities: str) -> str:
def get_image_name(capabilities: dict[str, Any]) -> str:
return IMAGES[capabilities["browserName"]]


Expand All @@ -48,9 +48,16 @@ class BrowserWebDriverContainer(DockerContainer):
"""

def __init__(
self, capabilities: str, image: Optional[str] = None, port: int = 4444, vnc_port: int = 5900, **kwargs
self,
capabilities: dict[str, Any],
options: Optional[ArgOptions] = None,
image: Optional[str] = None,
port: int = 4444,
vnc_port: int = 5900,
**kwargs,
) -> None:
self.capabilities = capabilities
self.options = options
self.image = image or get_image_name(capabilities)
self.port = port
self.vnc_port = vnc_port
Expand All @@ -65,7 +72,7 @@ def _configure(self) -> None:

@wait_container_is_ready(urllib3.exceptions.HTTPError)
def _connect(self) -> webdriver.Remote:
options = ArgOptions()
options = ArgOptions() if self.options is None else self.options
for key, value in self.capabilities.items():
options.set_capability(key, value)
return webdriver.Remote(command_executor=(self.get_connection_url()), options=options)
Expand All @@ -78,6 +85,10 @@ def get_connection_url(self) -> str:
port = self.get_exposed_port(self.port)
return f"http://{ip}:{port}/wd/hub"

def with_options(self, options: Optional[ArgOptions]):
self.options = options
return self

def with_video(self, image: Optional[str] = None, video_path: Optional[Path] = None) -> Self:
video_path = video_path or Path.cwd()

Expand Down

0 comments on commit e02c1b3

Please sign in to comment.