Skip to content

[py] Extract alert and color into dedicated libraries #17611

Open
AutomatedTester wants to merge 2 commits into
trunkfrom
worktree-fix-py-p2-remaining
Open

[py] Extract alert and color into dedicated libraries #17611
AutomatedTester wants to merge 2 commits into
trunkfrom
worktree-fix-py-p2-remaining

Conversation

@AutomatedTester
Copy link
Copy Markdown
Member

Summary

Continues the Python Bazel target granularity work (P2c + P2f):

  • P2c — alert.py: Extracted into //py:common_alert. Lazy-imported Alert in switch_to.py (method body) and moved it to TYPE_CHECKING in expected_conditions.py so neither //py:remote nor //py:support carries the compile-time dep. Grouped alerts_tests.py + webdriverwait_tests.py into a shared ALERT_TESTS sub-suite (both call driver.switch_to.alert at runtime, requiring :common_alert in runfiles).

  • P2f — color.py: Extracted into //py:support_color (no source changes needed — rendered_webelement_tests.py is the only browser test importing Color). Removed color.py from //py:support glob.

Both groups are added to FEATURE_TESTS (auto-excluded from all *-common suites) and FEATURE_SUITE_DEFS, generating test-<browser>-alerts and test-<browser>-rendered sub-suites across all browser/bidi/remote variants.

CI impact: changing alert.py now only dirties test-*-alerts targets; changing color.py only dirties test-*-rendered targets — instead of all ~700 browser test targets.

Test plan

  • Python linters (mypy, ruff) pass — Alert is under TYPE_CHECKING with from __future__ import annotations in both modified files
  • test-chrome-alerts runs alerts_tests.py + webdriverwait_tests.py (requires :common_alert)
  • test-chrome-rendered runs rendered_webelement_tests.py (requires :support_color)
  • test-chrome-common no longer includes the above test files
  • //py:selenium includes both new libraries

- Extract selenium/webdriver/common/alert.py into //py:common_alert;
  lazy-import Alert in switch_to.py (body) and expected_conditions.py
  (TYPE_CHECKING) so //py:remote and //py:support no longer carry the
  compile-time dep.

- Extract selenium/webdriver/support/color.py into //py:support_color;
  no source changes needed since no other library imports it.

- Group alerts_tests.py + webdriverwait_tests.py into ALERT_TESTS (both
  call driver.switch_to.alert at runtime, requiring :common_alert).

- Add RENDERED_WEBELEMENT_TESTS for rendered_webelement_tests.py (sole
  browser test importing Color).

- Both groups added to FEATURE_TESTS (excluded from *-common suites) and
  FEATURE_SUITE_DEFS, generating test-<browser>-alerts and
  test-<browser>-rendered sub-suites across all browser/bidi/remote
  variants.

- Add :common_alert and :support_color to //py:selenium deps.
@selenium-ci selenium-ci added C-py Python Bindings B-build Includes scripting, bazel and CI integrations B-support Issue or PR related to support classes labels Jun 2, 2026
@selenium-ci
Copy link
Copy Markdown
Member

Thank you, @AutomatedTester for this code suggestion.

The support packages contain example code that many users find helpful, but they do not necessarily represent
the best practices for using Selenium, and the Selenium team is not currently merging changes to them.

After reviewing the change, unless it is a critical fix or a feature that is needed for Selenium
to work, we will likely close the PR.

We actively encourage people to add the wrapper and helper code that makes sense for them to their own frameworks.
If you have any questions, please contact us

@AutomatedTester AutomatedTester changed the title [py] Extract alert and color into dedicated libraries (P2c/P2f) [py] Extract alert and color into dedicated libraries Jun 2, 2026
@AutomatedTester
Copy link
Copy Markdown
Member Author

Build graph goes from
Screenshot 2026-06-01 at 14 43 00

to this

Screenshot 2026-06-02 at 09 57 27

bidi_browsing_context_tests.py calls EC.alert_is_present() which
triggers driver.switch_to.alert at runtime, requiring alert.py in
the runfiles. The bidi-common suite includes BIDI_TESTS (unlike the
non-bidi common suite which excludes them) so it needs :common_alert
as an explicit dep.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-build Includes scripting, bazel and CI integrations B-support Issue or PR related to support classes C-py Python Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants