Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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