Skip to content

Commit e4eac88

Browse files
[py] Extract feature-specific modules from //py:common (#17606)
* [py] Extract feature-specific modules from //py:common (P2b/P2d) Modules that are only used by a small subset of tests were still bundled in //py:common, causing those modules to be compiled into every test's transitive dep graph. Changing any of them triggered a full rebuild of all ~700 browser test targets. This change extracts five modules into dedicated libraries: - //py:common_fedcm (fedcm/**/*.py) - //py:common_timeouts (timeouts.py) - //py:common_virtual_authenticator (virtual_authenticator.py) - //py:common_api_request_context (api_request_context.py) - //py:common_print_page_options (print_page_options.py) For each module, the corresponding browser test file (e.g. timeout_tests.py, virtual_authenticator_tests.py) is the only test that imports it directly. New per-feature test sub-suites (test-chrome-timeouts, test-chrome-fedcm, etc.) carry the right //py:common_* dep; the -common suites have no dep on these libraries. Aggregate test_suite targets (test-chrome, test-chrome-bidi, test-chrome-remote, etc.) are unchanged so CI targets are unaffected. For the split to be precise, remote/webdriver.py previously imported these modules at the top level, which would have re-added them to every test's dep graph via //py:remote. Three changes remove this: - from __future__ import annotations makes all type annotations lazy strings, so no runtime import is needed for parameter/return types. - The four methods that instantiate these types (timeouts property, request property, dialog property, get_credentials) now lazy-import inside the method body. - The required_virtual_authenticator and required_chromium_based_browser decorators are inlined in remote/webdriver.py (they were only used there; the 10-line definition removes the top-level dep). Result: changing timeouts.py now only rebuilds ~11 test targets (timeout_tests × browser variants) instead of ~700.
1 parent 2eaf118 commit e4eac88

2 files changed

Lines changed: 277 additions & 29 deletions

File tree

py/BUILD.bazel

Lines changed: 228 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,13 @@ py_library(
296296
exclude = [
297297
"selenium/webdriver/common/action_chains.py",
298298
"selenium/webdriver/common/actions/**",
299+
"selenium/webdriver/common/api_request_context.py",
299300
"selenium/webdriver/common/bidi/**",
300301
"selenium/webdriver/common/devtools/**",
302+
"selenium/webdriver/common/fedcm/**",
303+
"selenium/webdriver/common/print_page_options.py",
304+
"selenium/webdriver/common/timeouts.py",
305+
"selenium/webdriver/common/virtual_authenticator.py",
301306
],
302307
),
303308
data = [
@@ -331,6 +336,46 @@ py_library(
331336
],
332337
)
333338

339+
py_library(
340+
name = "common_api_request_context",
341+
srcs = ["selenium/webdriver/common/api_request_context.py"],
342+
imports = ["."],
343+
visibility = ["//visibility:public"],
344+
deps = [":exceptions"],
345+
)
346+
347+
py_library(
348+
name = "common_fedcm",
349+
srcs = glob(["selenium/webdriver/common/fedcm/**/*.py"]),
350+
imports = ["."],
351+
visibility = ["//visibility:public"],
352+
deps = [":exceptions"],
353+
)
354+
355+
py_library(
356+
name = "common_print_page_options",
357+
srcs = ["selenium/webdriver/common/print_page_options.py"],
358+
imports = ["."],
359+
visibility = ["//visibility:public"],
360+
deps = [],
361+
)
362+
363+
py_library(
364+
name = "common_timeouts",
365+
srcs = ["selenium/webdriver/common/timeouts.py"],
366+
imports = ["."],
367+
visibility = ["//visibility:public"],
368+
deps = [],
369+
)
370+
371+
py_library(
372+
name = "common_virtual_authenticator",
373+
srcs = ["selenium/webdriver/common/virtual_authenticator.py"],
374+
imports = ["."],
375+
visibility = ["//visibility:public"],
376+
deps = [":exceptions"],
377+
)
378+
334379
# Module that points to the latest devtools module
335380
py_library(
336381
name = "latest",
@@ -468,6 +513,11 @@ py_library(
468513
":chromium",
469514
":common",
470515
":common_actions",
516+
":common_api_request_context",
517+
":common_fedcm",
518+
":common_print_page_options",
519+
":common_timeouts",
520+
":common_virtual_authenticator",
471521
":edge",
472522
":exceptions",
473523
":firefox",
@@ -701,6 +751,19 @@ py_library(
701751

702752
BIDI_TESTS = glob(["test/selenium/webdriver/common/**/*bidi*_tests.py"])
703753

754+
# Test files that only run against browsers supporting the given feature.
755+
# Each group is split into its own sub-suite so that changing the underlying
756+
# library only triggers that group's targets, not the full ~700-target suite.
757+
FEDCM_TESTS = ["test/selenium/webdriver/common/fedcm_tests.py"]
758+
759+
TIMEOUTS_TESTS = ["test/selenium/webdriver/common/timeout_tests.py"]
760+
761+
VIRTUAL_AUTH_TESTS = ["test/selenium/webdriver/common/virtual_authenticator_tests.py"]
762+
763+
API_REQUEST_TESTS = ["test/selenium/webdriver/common/api_request_context_tests.py"]
764+
765+
FEATURE_TESTS = FEDCM_TESTS + TIMEOUTS_TESTS + VIRTUAL_AUTH_TESTS + API_REQUEST_TESTS
766+
704767
# Test files that import from selenium.webdriver.common.actions / action_chains.
705768
# These are kept separate so they can depend on :common_actions without pulling
706769
# that library into every other test suite.
@@ -798,7 +861,7 @@ DEFAULT_BROWSER_TESTS = [b for b in BROWSER_TESTS if b != "ie"]
798861
"test/selenium/webdriver/common/**/*.py",
799862
"test/selenium/webdriver/support/**/*.py",
800863
] + BROWSER_TESTS[browser]["browser_srcs"],
801-
exclude = BIDI_TESTS + ACTIONS_TESTS + ["test/selenium/webdriver/common/print_pdf_tests.py"] +
864+
exclude = BIDI_TESTS + ACTIONS_TESTS + FEATURE_TESTS + ["test/selenium/webdriver/common/print_pdf_tests.py"] +
802865
BROWSER_TESTS[browser].get("extra_excludes", []),
803866
),
804867
args = [
@@ -839,13 +902,45 @@ DEFAULT_BROWSER_TESTS = [b for b in BROWSER_TESTS if b != "ie"]
839902
for browser in DEFAULT_BROWSER_TESTS
840903
]
841904

842-
# Aggregate test-<browser> = common + actions (keeps CI targets unchanged)
905+
# Feature test definitions: suffix -> (srcs, dep)
906+
FEATURE_SUITE_DEFS = {
907+
"fedcm": (FEDCM_TESTS, ":common_fedcm"),
908+
"timeouts": (TIMEOUTS_TESTS, ":common_timeouts"),
909+
"virtual-auth": (VIRTUAL_AUTH_TESTS, ":common_virtual_authenticator"),
910+
"api-request": (API_REQUEST_TESTS, ":common_api_request_context"),
911+
}
912+
913+
# Generate test-<browser>-<feature> targets (non-bidi, one per feature library)
914+
[
915+
py_test_suite(
916+
name = "test-%s-%s" % (browser, feature),
917+
size = "large",
918+
srcs = FEATURE_SUITE_DEFS[feature][0],
919+
args = [
920+
"--instafail",
921+
] + BROWSERS[browser]["args"],
922+
data = BROWSERS[browser]["data"],
923+
env_inherit = ["DISPLAY"],
924+
tags = ["no-sandbox"] + BROWSERS[browser]["tags"],
925+
target_compatible_with = BROWSERS[browser]["target_compatible_with"],
926+
test_suffix = "%s-%s" % (browser, feature),
927+
deps = [
928+
":init-tree",
929+
":webserver",
930+
FEATURE_SUITE_DEFS[feature][1],
931+
] + BROWSER_TESTS[browser]["deps"] + TEST_DEPS,
932+
)
933+
for browser in DEFAULT_BROWSER_TESTS
934+
for feature in FEATURE_SUITE_DEFS
935+
]
936+
937+
# Aggregate test-<browser> = common + actions + features (keeps CI targets unchanged)
843938
[test_suite(
844939
name = "test-%s" % browser,
845940
tests = [
846941
":test-%s-common" % browser,
847942
":test-%s-actions" % browser,
848-
],
943+
] + [":test-%s-%s" % (browser, f) for f in FEATURE_SUITE_DEFS],
849944
) for browser in DEFAULT_BROWSER_TESTS]
850945

851946
# Generate test-<browser>-bidi-common targets
@@ -858,7 +953,7 @@ DEFAULT_BROWSER_TESTS = [b for b in BROWSER_TESTS if b != "ie"]
858953
"test/selenium/webdriver/common/**/*.py",
859954
"test/selenium/webdriver/support/**/*.py",
860955
] + BROWSER_TESTS[browser]["browser_srcs"],
861-
exclude = ACTIONS_TESTS + ["test/selenium/webdriver/common/print_pdf_tests.py"] +
956+
exclude = ACTIONS_TESTS + FEATURE_TESTS + ["test/selenium/webdriver/common/print_pdf_tests.py"] +
862957
BROWSER_TESTS[browser].get("extra_excludes", []),
863958
),
864959
args = [
@@ -903,13 +998,39 @@ DEFAULT_BROWSER_TESTS = [b for b in BROWSER_TESTS if b != "ie"]
903998
if BROWSER_TESTS[browser].get("bidi", False)
904999
]
9051000

906-
# Aggregate test-<browser>-bidi = bidi-common + bidi-actions
1001+
# Generate test-<browser>-bidi-<feature> targets
1002+
[
1003+
py_test_suite(
1004+
name = "test-%s-bidi-%s" % (browser, feature),
1005+
size = "large",
1006+
srcs = FEATURE_SUITE_DEFS[feature][0],
1007+
args = [
1008+
"--instafail",
1009+
"--bidi",
1010+
] + BROWSERS[browser]["args"],
1011+
data = BROWSERS[browser]["data"],
1012+
env_inherit = ["DISPLAY"],
1013+
tags = ["no-sandbox"] + BROWSERS[browser]["tags"],
1014+
target_compatible_with = BROWSERS[browser]["target_compatible_with"],
1015+
test_suffix = "%s-bidi-%s" % (browser, feature),
1016+
deps = [
1017+
":init-tree",
1018+
":webserver",
1019+
FEATURE_SUITE_DEFS[feature][1],
1020+
] + BROWSER_TESTS[browser]["deps"] + TEST_DEPS,
1021+
)
1022+
for browser in DEFAULT_BROWSER_TESTS
1023+
for feature in FEATURE_SUITE_DEFS
1024+
if BROWSER_TESTS[browser].get("bidi", False)
1025+
]
1026+
1027+
# Aggregate test-<browser>-bidi = bidi-common + bidi-actions + bidi-features
9071028
[test_suite(
9081029
name = "test-%s-bidi" % browser,
9091030
tests = [
9101031
":test-%s-bidi-common" % browser,
9111032
":test-%s-bidi-actions" % browser,
912-
],
1033+
] + [":test-%s-bidi-%s" % (browser, f) for f in FEATURE_SUITE_DEFS],
9131034
) for browser in DEFAULT_BROWSER_TESTS if BROWSER_TESTS[browser].get("bidi", False)]
9141035

9151036
# Generate test-<browser>-remote-common targets (chrome and firefox only)
@@ -923,7 +1044,7 @@ DEFAULT_BROWSER_TESTS = [b for b in BROWSER_TESTS if b != "ie"]
9231044
"test/selenium/webdriver/remote/**/*.py",
9241045
"test/selenium/webdriver/support/**/*.py",
9251046
] + BROWSER_TESTS[browser]["browser_srcs"],
926-
exclude = BIDI_TESTS + ACTIONS_TESTS + ["test/selenium/webdriver/common/print_pdf_tests.py"] +
1047+
exclude = BIDI_TESTS + ACTIONS_TESTS + FEATURE_TESTS + ["test/selenium/webdriver/common/print_pdf_tests.py"] +
9271048
BROWSER_TESTS[browser].get("extra_excludes", []),
9281049
),
9291050
args = [
@@ -992,13 +1113,51 @@ DEFAULT_BROWSER_TESTS = [b for b in BROWSER_TESTS if b != "ie"]
9921113
]
9931114
]
9941115

995-
# Aggregate test-<browser>-remote = remote-common + remote-actions
1116+
# Generate test-<browser>-remote-<feature> targets (chrome and firefox only)
1117+
[
1118+
py_test_suite(
1119+
name = "test-%s-remote-%s" % (browser, feature),
1120+
size = "large",
1121+
srcs = FEATURE_SUITE_DEFS[feature][0],
1122+
args = [
1123+
"--instafail",
1124+
"--remote",
1125+
] + BROWSERS[browser]["args"],
1126+
data = BROWSERS[browser]["data"] + [
1127+
":java-location",
1128+
"//java/src/org/openqa/selenium/grid:selenium_server_deploy.jar",
1129+
"@bazel_tools//tools/jdk:current_java_runtime",
1130+
],
1131+
env = {
1132+
"SE_BAZEL_JAVA_LOCATION": "$(rootpath :java-location)",
1133+
},
1134+
env_inherit = ["DISPLAY"],
1135+
tags = [
1136+
"no-sandbox",
1137+
"remote",
1138+
"%s-remote" % browser,
1139+
],
1140+
test_suffix = "%s-remote-%s" % (browser, feature),
1141+
deps = [
1142+
":init-tree",
1143+
":webserver",
1144+
FEATURE_SUITE_DEFS[feature][1],
1145+
] + BROWSER_TESTS[browser]["deps"] + TEST_DEPS,
1146+
)
1147+
for browser in [
1148+
"chrome",
1149+
"firefox",
1150+
]
1151+
for feature in FEATURE_SUITE_DEFS
1152+
]
1153+
1154+
# Aggregate test-<browser>-remote = remote-common + remote-actions + remote-features
9961155
[test_suite(
9971156
name = "test-%s-remote" % browser,
9981157
tests = [
9991158
":test-%s-remote-common" % browser,
10001159
":test-%s-remote-actions" % browser,
1001-
],
1160+
] + [":test-%s-remote-%s" % (browser, f) for f in FEATURE_SUITE_DEFS],
10021161
) for browser in [
10031162
"chrome",
10041163
"firefox",
@@ -1021,7 +1180,7 @@ py_test_suite(
10211180
"test/selenium/webdriver/common/**/*.py",
10221181
"test/selenium/webdriver/support/**/*.py",
10231182
],
1024-
exclude = BIDI_TESTS + ACTIONS_TESTS,
1183+
exclude = BIDI_TESTS + ACTIONS_TESTS + FEATURE_TESTS,
10251184
),
10261185
args = [
10271186
"--instafail",
@@ -1069,12 +1228,40 @@ py_test_suite(
10691228
] + TEST_DEPS,
10701229
)
10711230

1231+
[
1232+
py_test_suite(
1233+
name = "test-webkitgtk-%s" % feature,
1234+
size = "large",
1235+
srcs = FEATURE_SUITE_DEFS[feature][0],
1236+
args = [
1237+
"--instafail",
1238+
"--driver=webkitgtk",
1239+
"--browser-binary=MiniBrowser",
1240+
"--browser-args=--automation",
1241+
],
1242+
tags = [
1243+
"exclusive-if-local",
1244+
"no-sandbox",
1245+
"skip-rbe",
1246+
],
1247+
test_suffix = "webkitgtk-%s" % feature,
1248+
deps = [
1249+
":init-tree",
1250+
":support",
1251+
":webkitgtk",
1252+
":webserver",
1253+
FEATURE_SUITE_DEFS[feature][1],
1254+
] + TEST_DEPS,
1255+
)
1256+
for feature in FEATURE_SUITE_DEFS
1257+
]
1258+
10721259
test_suite(
10731260
name = "test-webkitgtk",
10741261
tests = [
10751262
":test-webkitgtk-actions",
10761263
":test-webkitgtk-common",
1077-
],
1264+
] + [":test-webkitgtk-%s" % f for f in FEATURE_SUITE_DEFS],
10781265
)
10791266

10801267
py_test_suite(
@@ -1085,7 +1272,7 @@ py_test_suite(
10851272
"test/selenium/webdriver/common/**/*.py",
10861273
"test/selenium/webdriver/support/**/*.py",
10871274
],
1088-
exclude = BIDI_TESTS + ACTIONS_TESTS,
1275+
exclude = BIDI_TESTS + ACTIONS_TESTS + FEATURE_TESTS,
10891276
),
10901277
args = [
10911278
"--instafail",
@@ -1133,12 +1320,40 @@ py_test_suite(
11331320
] + TEST_DEPS,
11341321
)
11351322

1323+
[
1324+
py_test_suite(
1325+
name = "test-wpewebkit-%s" % feature,
1326+
size = "large",
1327+
srcs = FEATURE_SUITE_DEFS[feature][0],
1328+
args = [
1329+
"--instafail",
1330+
"--driver=wpewebkit",
1331+
"--browser-binary=MiniBrowser",
1332+
"--browser-args=--automation --headless",
1333+
],
1334+
tags = [
1335+
"exclusive-if-local",
1336+
"no-sandbox",
1337+
"skip-rbe",
1338+
],
1339+
test_suffix = "wpewebkit-%s" % feature,
1340+
deps = [
1341+
":init-tree",
1342+
":support",
1343+
":webserver",
1344+
":wpewebkit",
1345+
FEATURE_SUITE_DEFS[feature][1],
1346+
] + TEST_DEPS,
1347+
)
1348+
for feature in FEATURE_SUITE_DEFS
1349+
]
1350+
11361351
test_suite(
11371352
name = "test-wpewebkit",
11381353
tests = [
11391354
":test-wpewebkit-actions",
11401355
":test-wpewebkit-common",
1141-
],
1356+
] + [":test-wpewebkit-%s" % f for f in FEATURE_SUITE_DEFS],
11421357
)
11431358

11441359
py_binary(

0 commit comments

Comments
 (0)