Skip to content

Support IntelliSense and fix locale settings #3792

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

Merged
merged 4 commits into from
Jun 3, 2025
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
2 changes: 1 addition & 1 deletion examples/migration/protractor/input_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class AngularMaterialInputTests(BaseCase):
def test_invalid_input(self):
# Test that there's an error for an invalid input
self.open("https://material.angular.io/components/input/examples")
self.type("#mat-input-1", "invalid")
self.type('input[type="email"]', "invalid")
self.assert_element("mat-error")
6 changes: 4 additions & 2 deletions examples/migration/protractor/mat_paginator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
class AngularMaterialPaginatorTests(BaseCase):
def test_pagination(self):
self.open("https://material.angular.io/components/paginator/examples")
self.click_if_visible("button.mat-mdc-button")
self.scroll_to("div.mat-mdc-paginator-page-size")
# Set pagination to 5 items per page
self.click("mat-select > div")
self.click("#mat-option-0")
self.click("mat-option:nth-of-type(1)")
# Verify navigation to the next page
self.click('button[aria-label="Next page"]')
self.assert_exact_text(
Expand All @@ -20,7 +22,7 @@ def test_pagination(self):
)
# Set pagination to 10 items per page
self.click("mat-select > div")
self.click("#mat-option-1")
self.click("mat-option:nth-of-type(2)")
# Verify page with correct number of pages
self.assert_exact_text(
"1 – 10 of 50", ".mat-mdc-paginator-range-label"
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.39.1"
__version__ = "4.39.2"
3 changes: 3 additions & 0 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,9 @@ def _set_chrome_options(
prefs["profile.default_content_setting_values.automatic_downloads"] = 1
if locale_code:
prefs["intl.accept_languages"] = locale_code
sb_config._cdp_locale = locale_code
else:
sb_config._cdp_locale = None
if block_images:
prefs["profile.managed_default_content_settings.images"] = 2
if disable_cookies:
Expand Down
3 changes: 2 additions & 1 deletion seleniumbase/core/sb_driver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Add new methods to extend the driver"""
from contextlib import suppress
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.remote.webelement import WebElement
from seleniumbase.config import settings
from seleniumbase.fixtures import js_utils
Expand All @@ -8,7 +9,7 @@
from seleniumbase.fixtures import shared_utils


class DriverMethods():
class DriverMethods(WebDriver):
def __init__(self, driver):
self.driver = driver

Expand Down
3 changes: 2 additions & 1 deletion seleniumbase/plugins/driver_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"""
import os
import sys
from seleniumbase.core import sb_driver


class DriverContext():
Expand Down Expand Up @@ -139,7 +140,7 @@ def Driver(
pls=None, # Shortcut / Duplicate of "page_load_strategy".
cft=None, # Use "Chrome for Testing"
chs=None, # Use "Chrome-Headless-Shell"
):
) -> sb_driver.DriverMethods:
"""
* SeleniumBase Driver as a Python Context Manager or a returnable object. *

Expand Down
5 changes: 3 additions & 2 deletions seleniumbase/plugins/sb_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#########################################
"""
from contextlib import contextmanager, suppress
from typing import Any, Generator
from seleniumbase import BaseCase


@contextmanager # Usage: -> ``with SB() as sb:``
Expand Down Expand Up @@ -133,7 +135,7 @@ def SB(
highlights=None, # Number of highlight animations for Demo Mode actions.
interval=None, # SECONDS (Autoplay interval for SB Slides & Tour steps.)
time_limit=None, # SECONDS (Safely fail tests that exceed the time limit.)
):
) -> Generator[BaseCase, Any, None]:
"""
* SeleniumBase as a Python Context Manager *

Expand Down Expand Up @@ -263,7 +265,6 @@ def SB(
import sys
import time
import traceback
from seleniumbase import BaseCase
from seleniumbase import config as sb_config
from seleniumbase.config import settings
from seleniumbase.fixtures import constants
Expand Down
4 changes: 4 additions & 0 deletions seleniumbase/undetected/cdp_driver/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ async def get(
_cdp_locale = kwargs["locale"]
elif "lang" in kwargs:
_cdp_locale = kwargs["lang"]
elif "locale_code" in kwargs:
_cdp_locale = kwargs["locale_code"]
if "platform" in kwargs:
_cdp_platform = kwargs["platform"]
elif "plat" in kwargs:
Expand All @@ -336,6 +338,8 @@ async def get(
if _cdp_timezone:
await connection.send(cdp.page.navigate("about:blank"))
await connection.set_timezone(_cdp_timezone)
if _cdp_locale:
await connection.set_locale(_cdp_locale)
if _cdp_user_agent or _cdp_locale or _cdp_platform:
await connection.send(cdp.page.navigate("about:blank"))
await connection.set_user_agent(
Expand Down
2 changes: 0 additions & 2 deletions seleniumbase/undetected/cdp_driver/cdp_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,6 @@ async def start(
sb_config._cdp_locale = kwargs["locale"]
elif "locale_code" in kwargs:
sb_config._cdp_locale = kwargs["locale_code"]
else:
sb_config._cdp_locale = None
if tzone:
sb_config._cdp_timezone = tzone
elif "timezone" in kwargs:
Expand Down
1 change: 1 addition & 0 deletions seleniumbase/undetected/cdp_driver/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ async def wait(self, t: Union[int, float] = None):
async def set_locale(self, locale: Optional[str] = None):
"""Sets the Language Locale code via set_user_agent_override."""
await self.set_user_agent(user_agent="", accept_language=locale)
await self.send(cdp.emulation.set_locale_override(locale))

async def set_timezone(self, timezone: Optional[str] = None):
"""Sets the Timezone via set_timezone_override."""
Expand Down