Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(selenium): add Arg/Options to api of selenium container #654

Merged
merged 5 commits into from
Aug 1, 2024
Merged
Changes from 3 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
18 changes: 14 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,9 @@ 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

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

Expand Down
Loading