Skip to content

Commit 3b1c490

Browse files
authored
[rb] update bazel test tags (#17558)
* [rb] update bazel test tags * add no_grid parameter to avoid generating noop -remote targets * split se-manager from os-sensitive tags * apply os-sensitive tags to specific local browser runs * split devtools and bidi definitions
1 parent 312e586 commit 3b1c490

9 files changed

Lines changed: 136 additions & 82 deletions

File tree

rb/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ rb_gem_build(
8181
"//rb/lib/selenium/webdriver:bidi",
8282
"//rb/lib/selenium/webdriver:chrome",
8383
"//rb/lib/selenium/webdriver:common",
84+
"//rb/lib/selenium/webdriver:devtools",
8485
"//rb/lib/selenium/webdriver:edge",
8586
"//rb/lib/selenium/webdriver:firefox",
8687
"//rb/lib/selenium/webdriver:ie",

rb/lib/selenium/webdriver/BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ rb_library(
2020
srcs = glob([
2121
"bidi/**/*.rb",
2222
"bidi.rb",
23+
]),
24+
deps = [":common"],
25+
)
26+
27+
rb_library(
28+
name = "devtools",
29+
srcs = glob([
2330
"devtools/**/*.rb",
2431
"devtools.rb",
2532
]),

rb/spec/integration/selenium/webdriver/BUILD.bazel

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@ rb_library(
2727
],
2828
)
2929

30+
_OS_SENSITIVE = [
31+
"action_builder_spec.rb",
32+
"takes_screenshot_spec.rb",
33+
"window_spec.rb",
34+
]
35+
36+
# specs whose classes have both bidi implementations
37+
_BIDI_IMPLEMENTATIONS = [
38+
"navigation_spec.rb",
39+
]
40+
41+
# tests that require bidi enabled
42+
_BIDI_ONLY = [
43+
"bidi_spec.rb",
44+
"network_spec.rb",
45+
]
46+
47+
_DEVTOOLS = ["devtools_spec.rb"]
48+
3049
[
3150
rb_integration_test(
3251
name = file[:-8],
@@ -37,21 +56,20 @@ rb_library(
3756
)
3857
for file in glob(
3958
["*_spec.rb"],
40-
exclude = [
41-
"bidi_spec.rb",
42-
"driver_spec.rb",
43-
"devtools_spec.rb",
44-
"element_spec.rb",
45-
"navigation_spec.rb",
46-
"network_spec.rb",
47-
],
59+
exclude = _OS_SENSITIVE + _BIDI_IMPLEMENTATIONS + _BIDI_ONLY + _DEVTOOLS,
4860
)
4961
]
5062

51-
_BIDI_FILES = [
52-
"bidi_spec.rb",
53-
"navigation_spec.rb",
54-
"network_spec.rb",
63+
[
64+
rb_integration_test(
65+
name = f[:-8],
66+
srcs = [f],
67+
tags = ["os-sensitive"],
68+
deps = [
69+
"//rb/lib/selenium/webdriver:common",
70+
],
71+
)
72+
for f in _OS_SENSITIVE
5573
]
5674

5775
[
@@ -60,29 +78,33 @@ _BIDI_FILES = [
6078
srcs = [f],
6179
tags = ["bidi"],
6280
deps = [
63-
"//rb/lib/selenium/devtools",
6481
"//rb/lib/selenium/webdriver:bidi",
6582
],
6683
)
67-
for f in _BIDI_FILES
84+
for f in _BIDI_IMPLEMENTATIONS
6885
]
6986

70-
rb_integration_test(
71-
name = "devtools",
72-
srcs = ["devtools_spec.rb"],
73-
tags = ["exclusive-if-local"],
74-
deps = [
75-
"//rb/lib/selenium/devtools",
76-
"//rb/lib/selenium/webdriver:bidi",
77-
],
78-
)
79-
80-
rb_integration_test(
81-
name = "driver",
82-
srcs = ["driver_spec.rb"],
83-
)
87+
[
88+
rb_integration_test(
89+
name = f[:-8],
90+
srcs = [f],
91+
bidi_only = True,
92+
deps = [
93+
"//rb/lib/selenium/webdriver:bidi",
94+
],
95+
)
96+
for f in _BIDI_ONLY
97+
]
8498

85-
rb_integration_test(
86-
name = "element",
87-
srcs = ["element_spec.rb"],
88-
)
99+
[
100+
rb_integration_test(
101+
name = f[:-8],
102+
srcs = [f],
103+
tags = ["exclusive-if-local"],
104+
deps = [
105+
"//rb/lib/selenium/devtools",
106+
"//rb/lib/selenium/webdriver:devtools",
107+
],
108+
)
109+
for f in _DEVTOOLS
110+
]

rb/spec/integration/selenium/webdriver/bidi/BUILD.bazel

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ load("//rb/spec:tests.bzl", "rb_integration_test")
44
rb_integration_test(
55
name = file[:-8],
66
srcs = [file],
7-
tags = [
8-
"bidi",
9-
"exclusive-if-local",
10-
],
7+
bidi_only = True,
8+
tags = ["exclusive-if-local"],
119
deps = [
12-
"//rb/lib/selenium/devtools",
1310
"//rb/lib/selenium/webdriver:bidi",
1411
],
1512
)

rb/spec/integration/selenium/webdriver/chrome/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ rb_integration_test(
2323
"chrome",
2424
"chrome-beta",
2525
],
26+
no_grid = True,
2627
tags = [
27-
"no-grid",
28+
"se-manager",
2829
"skip-rbe",
2930
],
3031
)

rb/spec/integration/selenium/webdriver/edge/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ rb_integration_test(
1717
name = "service",
1818
srcs = ["service_spec.rb"],
1919
browsers = ["edge"],
20+
no_grid = True,
2021
tags = [
21-
"no-grid",
22+
"se-manager",
2223
"skip-rbe",
2324
],
2425
)

rb/spec/integration/selenium/webdriver/firefox/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ rb_integration_test(
2323
"firefox",
2424
"firefox-beta",
2525
],
26+
no_grid = True,
2627
tags = [
27-
"no-grid",
28+
"se-manager",
2829
"skip-rbe",
2930
],
3031
)

rb/spec/tests.bzl

Lines changed: 65 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ BROWSERS = {
3838
"deps": ["//rb/lib/selenium/webdriver:chrome"],
3939
"tags": [],
4040
"target_compatible_with": [],
41+
"bidi": True,
4142
"env": {
4243
"WD_REMOTE_BROWSER": "chrome",
4344
"WD_SPEC_DRIVER": "chrome",
@@ -62,6 +63,7 @@ BROWSERS = {
6263
"deps": ["//rb/lib/selenium/webdriver:edge"],
6364
"tags": [],
6465
"target_compatible_with": [],
66+
"bidi": True,
6567
"env": {
6668
"WD_REMOTE_BROWSER": "edge",
6769
"WD_SPEC_DRIVER": "edge",
@@ -108,6 +110,7 @@ BROWSERS = {
108110
"deps": ["//rb/lib/selenium/webdriver:firefox"],
109111
"tags": [],
110112
"target_compatible_with": [],
113+
"bidi": True,
111114
"env": {
112115
"WD_REMOTE_BROWSER": "firefox",
113116
"WD_SPEC_DRIVER": "firefox",
@@ -165,7 +168,25 @@ BROWSERS = {
165168

166169
DEFAULT_BROWSERS = [b for b in BROWSERS.keys() if b not in ("ie", "safari-preview")]
167170

168-
def rb_integration_test(name, srcs, deps = [], data = [], browsers = DEFAULT_BROWSERS, tags = []):
171+
# Tags listed here apply only to the local target of the listed browsers.
172+
_BROWSER_TAG_FILTERS = {
173+
"os-sensitive": ["chrome-beta", "edge", "firefox-beta", "safari"],
174+
}
175+
176+
def _split_filtered_tags(tags, browser):
177+
universal_tags = [t for t in tags if t not in _BROWSER_TAG_FILTERS]
178+
local_tags = [t for t in tags if browser in _BROWSER_TAG_FILTERS.get(t, [])]
179+
return universal_tags, local_tags
180+
181+
def rb_integration_test(
182+
name,
183+
srcs,
184+
deps = [],
185+
data = [],
186+
browsers = DEFAULT_BROWSERS,
187+
tags = [],
188+
bidi_only = False,
189+
no_grid = False):
169190
# Generate a library target that is used by //rb/spec:spec to expose all tests to //rb:lint.
170191
rb_library(
171192
name = name,
@@ -174,46 +195,49 @@ def rb_integration_test(name, srcs, deps = [], data = [], browsers = DEFAULT_BRO
174195
)
175196

176197
for browser in browsers:
177-
# Generate a test target for local browser execution.
178-
rb_test(
179-
name = "{}-{}".format(name, browser),
180-
size = "large",
181-
srcs = srcs,
182-
args = ["rb/spec/"],
183-
data = BROWSERS[browser]["data"] + data + ["//common/src/web"],
184-
env = BROWSERS[browser]["env"],
185-
main = "@bundle//bin:rspec",
186-
tags = COMMON_TAGS + BROWSERS[browser]["tags"] + tags + [browser],
187-
deps = ["//rb/spec/integration/selenium/webdriver:spec_helper"] + BROWSERS[browser]["deps"] + deps,
188-
visibility = ["//rb:__subpackages__"],
189-
target_compatible_with = BROWSERS[browser]["target_compatible_with"],
190-
)
198+
universal_tags, local_tags = _split_filtered_tags(tags, browser)
199+
if not bidi_only:
200+
# Generate a test target for local browser execution.
201+
rb_test(
202+
name = "{}-{}".format(name, browser),
203+
size = "large",
204+
srcs = srcs,
205+
args = ["rb/spec/"],
206+
data = BROWSERS[browser]["data"] + data + ["//common/src/web"],
207+
env = BROWSERS[browser]["env"],
208+
main = "@bundle//bin:rspec",
209+
tags = COMMON_TAGS + BROWSERS[browser]["tags"] + universal_tags + local_tags + [browser],
210+
deps = ["//rb/spec/integration/selenium/webdriver:spec_helper"] + BROWSERS[browser]["deps"] + deps,
211+
visibility = ["//rb:__subpackages__"],
212+
target_compatible_with = BROWSERS[browser]["target_compatible_with"],
213+
)
191214

192-
# Generate a test target for remote browser execution (Grid).
193-
rb_test(
194-
name = "{}-{}-remote".format(name, browser),
195-
size = "large",
196-
srcs = srcs,
197-
args = ["rb/spec/"],
198-
data = BROWSERS[browser]["data"] + data + [
199-
"//common/src/web",
200-
"//java/src/org/openqa/selenium/grid:selenium_server_deploy.jar",
201-
"//rb/spec:java-location",
202-
"@bazel_tools//tools/jdk:current_java_runtime",
203-
],
204-
env = BROWSERS[browser]["env"] | {
205-
"WD_BAZEL_JAVA_LOCATION": "$(rootpath //rb/spec:java-location)",
206-
"WD_SPEC_DRIVER": "remote",
207-
},
208-
main = "@bundle//bin:rspec",
209-
tags = COMMON_TAGS + BROWSERS[browser]["tags"] + tags + ["{}-remote".format(browser)],
210-
deps = ["//rb/spec/integration/selenium/webdriver:spec_helper"] + BROWSERS[browser]["deps"] + deps,
211-
visibility = ["//rb:__subpackages__"],
212-
target_compatible_with = BROWSERS[browser]["target_compatible_with"],
213-
)
215+
# Generate a test target for remote browser execution (Grid).
216+
if not no_grid:
217+
rb_test(
218+
name = "{}-{}-remote".format(name, browser),
219+
size = "large",
220+
srcs = srcs,
221+
args = ["rb/spec/"],
222+
data = BROWSERS[browser]["data"] + data + [
223+
"//common/src/web",
224+
"//java/src/org/openqa/selenium/grid:selenium_server_deploy.jar",
225+
"//rb/spec:java-location",
226+
"@bazel_tools//tools/jdk:current_java_runtime",
227+
],
228+
env = BROWSERS[browser]["env"] | {
229+
"WD_BAZEL_JAVA_LOCATION": "$(rootpath //rb/spec:java-location)",
230+
"WD_SPEC_DRIVER": "remote",
231+
},
232+
main = "@bundle//bin:rspec",
233+
tags = COMMON_TAGS + BROWSERS[browser]["tags"] + universal_tags + ["{}-remote".format(browser)],
234+
deps = ["//rb/spec/integration/selenium/webdriver:spec_helper"] + BROWSERS[browser]["deps"] + deps,
235+
visibility = ["//rb:__subpackages__"],
236+
target_compatible_with = BROWSERS[browser]["target_compatible_with"],
237+
)
214238

215-
# Generate a test target for bidi browser execution if there is a matching tag
216-
if "bidi" in tags:
239+
# Generate a test target for bidi browser execution on browsers that opt in.
240+
if ("bidi" in tags or bidi_only) and BROWSERS[browser].get("bidi", False):
217241
rb_test(
218242
name = "{}-{}-bidi".format(name, browser),
219243
size = "large",
@@ -222,7 +246,7 @@ def rb_integration_test(name, srcs, deps = [], data = [], browsers = DEFAULT_BRO
222246
data = BROWSERS[browser]["data"] + data + ["//common/src/web"],
223247
env = BROWSERS[browser]["env"] | {"WEBDRIVER_BIDI": "true"},
224248
main = "@bundle//bin:rspec",
225-
tags = COMMON_TAGS + BROWSERS[browser]["tags"] + tags + ["{}-bidi".format(browser)],
249+
tags = COMMON_TAGS + BROWSERS[browser]["tags"] + universal_tags + ["{}-bidi".format(browser)],
226250
deps = {d: True for d in (
227251
["//rb/spec/integration/selenium/webdriver:spec_helper", "//rb/lib/selenium/webdriver:bidi"] +
228252
BROWSERS[browser]["deps"] +
@@ -241,7 +265,7 @@ def rb_unit_test(name, srcs, deps, data = [], flaky = False):
241265
flaky = flaky,
242266
main = "@bundle//bin:rspec",
243267
data = data,
244-
tags = ["no-sandbox"], # TODO: Do we need this?
268+
tags = ["unit"],
245269
deps = ["//rb/spec/unit/selenium/webdriver:spec_helper"] + deps,
246270
visibility = ["//rb:__subpackages__"],
247271
)

rb/spec/unit/selenium/webdriver/devtools/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ load("//rb/spec:tests.bzl", "rb_unit_test")
44
rb_unit_test(
55
name = file[:-8],
66
srcs = [file],
7-
deps = ["//rb/lib/selenium/webdriver:bidi"],
7+
deps = ["//rb/lib/selenium/webdriver:devtools"],
88
)
99
for file in glob(["*_spec.rb"])
1010
]

0 commit comments

Comments
 (0)