diff --git a/.github/workflows/ci-ruby.yml b/.github/workflows/ci-ruby.yml index a92bf9e8bd38e..653034f947f45 100644 --- a/.github/workflows/ci-ruby.yml +++ b/.github/workflows/ci-ruby.yml @@ -56,7 +56,11 @@ jobs: cache-key: rb-unit-test-${{ matrix.ruby-version }} os: ${{ matrix.os }} ruby-version: ${{ matrix.ruby-version }} - run: bazel test //rb/spec/unit/... + run: > + bazel test + --build_tests_only + --test_size_filters small + //rb/spec/... integration-tests-local: name: Local Tests @@ -90,10 +94,12 @@ jobs: os: ${{ matrix.os }} run: > bazel test - --define browser=${{ matrix.browser }} + --build_tests_only --flaky_test_attempts 3 --local_test_jobs 1 - //rb/spec/integration/... + --test_size_filters large + --test_tag_filters ${{ matrix.browser }} + //rb/spec/... integration-tests-remote: name: Remote Tests @@ -119,8 +125,9 @@ jobs: java-version: 11 run: > bazel test - --define browser=${{ matrix.browser }} - --define remote=true + --build_tests_only --flaky_test_attempts 3 --local_test_jobs 1 - //rb/spec/integration/... + --test_size_filters large + --test_tag_filters ${{ matrix.browser }}-remote + //rb/spec/... diff --git a/.skipped-tests b/.skipped-tests index 08c8ed4577a94..6a7daf508421e 100644 --- a/.skipped-tests +++ b/.skipped-tests @@ -31,6 +31,7 @@ -//py:test-chrome-test/selenium/webdriver/chrome/chrome_service_tests.py -//py:test-chrome-test/selenium/webdriver/chrome/proxy_tests.py -//py:unit-test/unit/selenium/webdriver/common/cdp_module_fallback_tests.py --//rb/spec/integration/selenium/webdriver/chrome:service --//rb/spec/integration/selenium/webdriver/edge:service --//rb/spec/integration/selenium/webdriver/firefox:service +-//rb/spec/integration/selenium/webdriver/chrome:service-chrome +-//rb/spec/integration/selenium/webdriver/edge:service-edge +-//rb/spec/integration/selenium/webdriver/firefox:service-firefox +-//rb/spec/integration/selenium/webdriver/firefox:service-firefox-beta diff --git a/README.md b/README.md index 87c452a024e98..6ccd53ba5d6fc 100644 --- a/README.md +++ b/README.md @@ -334,37 +334,45 @@ bazel test //py:all Test targets: -| Command | Description | -|--------------------------------------------------------------------------------------|------------------------------------------------| -| `bazel test //rb/...` | Run unit, integration tests (Chrome) and lint | -| `bazel test //rb:lint` | Run RuboCop linter | -| `bazel test //rb/spec/...` | Run unit and integration tests (Chrome) | -| `bazel test --test_size_filters large //rb/...` | Run integration tests using (Chrome) | -| `bazel test //rb/spec/integration/...` | Run integration tests using (Chrome) | -| `bazel test //rb/spec/integration/... --define browser=firefox` | Run integration tests using (Firefox) | -| `bazel test //rb/spec/integration/... --define remote=true` | Run integration tests using (Chrome and Grid) | -| `bazel test //rb/spec/integration/... --define browser=firefox --define remote=true` | Run integration tests using (Firefox and Grid) | -| `bazel test --test_size_filters small //rb/...` | Run unit tests | -| `bazel test //rb/spec/unit/...` | Run unit tests | - -Ruby test modules have the same name as the spec file with `_spec.rb` removed, so you can run them individually: - -| Test file | Test target | -|----------------------------------------------------------------|----------------------------------------------------------| -| `rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb` | `//rb/spec/integration/selenium/webdriver/chrome:driver` | -| `rb/spec/unit/selenium/webdriver/proxy_spec.rb` | `//rb/spec/unit/selenium/webdriver:proxy` | +| Command | Description | +| -------------------------------------------------------------------------------- | -------------------------------------------------- | +| `bazel test //rb/...` | Run unit, all integration tests and lint | +| `bazel test //rb:lint` | Run RuboCop linter | +| `bazel test //rb/spec/...` | Run unit and integration tests for all browsers | +| `bazel test //rb/spec/... --test_size_filters small` | Run unit tests | +| `bazel test //rb/spec/unit/...` | Run unit tests | +| `bazel test //rb/spec/... --test_size_filters large` | Run integration tests for all browsers | +| `bazel test //rb/spec/integration/...` | Run integration tests for all browsers | +| `bazel test //rb/spec/integration/... --test_tag_filters firefox` | Run integration tests for local Firefox only | +| `bazel test //rb/spec/integration/... --test_tag_filters firefox-remote` | Run integration tests for remote Firefox only | +| `bazel test //rb/spec/integration/... --test_tag_filters firefox,firefox-remote` | Run integration tests for local and remote Firefox | + +Ruby test targets have the same name as the spec file with `_spec.rb` removed, so you can run them individually. +Integration tests targets also have a browser and remote suffix to control which browser to pick and whether to use Grid. + +| Test file | Test target | +| ------------------------------------------------------- | ---------------------------------------------------------------- | +| `rb/spec/unit/selenium/webdriver/proxy_spec.rb` | `//rb/spec/unit/selenium/webdriver:proxy` | +| `rb/spec/integration/selenium/webdriver/driver_spec.rb` | `//rb/spec/integration/selenium/webdriver:driver-chrome` | +| `rb/spec/integration/selenium/webdriver/driver_spec.rb` | `//rb/spec/integration/selenium/webdriver:driver-chrome-remote` | +| `rb/spec/integration/selenium/webdriver/driver_spec.rb` | `//rb/spec/integration/selenium/webdriver:driver-firefox` | +| `rb/spec/integration/selenium/webdriver/driver_spec.rb` | `//rb/spec/integration/selenium/webdriver:driver-firefox-remote` | Supported browsers: * `chrome` * `edge` * `firefox` +* `firefox-beta` * `ie` -* `safari` (cannot be run in parallel - use `--local_test_jobs 1`) -* `safari-preview` (cannot be run in parallel - use `--local_test_jobs 1`) +* `safari` +* `safari-preview` Useful command line options: +* `--pin_browsers` - use browsers and drivers downloaded by Bazel +* `--headless` - run browsers in headless mode (supported be Chrome, Edge and Firefox) + In addition to the [Common Options Examples](#common-options-examples), here are some additional Ruby specific ones: * `--test_arg "-tfocus"` - test only [focused specs](https://relishapp.com/rspec/rspec-core/v/3-12/docs/filtering/inclusion-filters) * `--test_arg "-eTimeouts"` - test only specs which name include "Timeouts" @@ -380,8 +388,11 @@ Supported environment variables for use with `--test_env`: - `HEADLESS` - for chrome, edge and firefox; runs tests in headless mode - `DISABLE_BUILD_CHECK` - for chrome and edge; whether to ignore driver and browser version mismatches (allows testing Canary builds) - `CHROME_BINARY` - path to test specific Chrome browser +- `CHROMEDRIVER_BINARY` - path to test specific ChromeDriver - `EDGE_BINARY` - path to test specific Edge browser +- `MSEDGEDRIVER_BINARY` - path to test specific msedgedriver - `FIREFOX_BINARY` - path to test specific Firefox browser +- `GECKODRIVER_BINARY` - path to test specific GeckoDriver To run with a specific version of Ruby you can change the version in `rb/.ruby-version` or from command line: diff --git a/common/browsers.bzl b/common/browsers.bzl index 0d32b5cafc67d..4da9ec45b150a 100644 --- a/common/browsers.bzl +++ b/common/browsers.bzl @@ -1,5 +1,8 @@ COMMON_TAGS = [ "browser-test", + # We have to use no-sandbox at the moment because Firefox crashes + # when run under sandbox: https://bugzilla.mozilla.org/show_bug.cgi?id=1382498. + # For Chromium-based browser, we can just pass `--no-sandbox` flag. "no-sandbox", "requires-network", ] diff --git a/common/extensions/BUILD.bazel b/common/extensions/BUILD.bazel index 1ed70f2a4b804..f77f7577aec46 100644 --- a/common/extensions/BUILD.bazel +++ b/common/extensions/BUILD.bazel @@ -11,7 +11,7 @@ filegroup( "//java/test/org/openqa/selenium/firefox:__pkg__", "//javascript/node/selenium-webdriver:__pkg__", "//py:__pkg__", - "//rb:__pkg__", + "//rb/spec:__subpackages__", ], ) diff --git a/rb/spec/BUILD.bazel b/rb/spec/BUILD.bazel index 96abaa7ba40ba..57d8b4fecaa72 100644 --- a/rb/spec/BUILD.bazel +++ b/rb/spec/BUILD.bazel @@ -8,14 +8,14 @@ rb_library( ) # List of dependencies can be gathered by running: -# bazel query 'kind("rb_.* rule", //rb/spec/...) except //rb/spec:spec' | xargs -I{} echo '"{}",' +# bazel query 'kind("rb_.* rule", //rb/spec/...) except attr(tags, "browser-test", //rb/spec/...) except //rb/spec:spec' | xargs -I{} echo '"{}",' rb_library( name = "spec", testonly = True, visibility = ["//rb:__pkg__"], deps = [ - ":rspec_matchers", + "//rb/spec:rspec_matchers", "//rb/spec/integration/selenium/webdriver:action_builder", "//rb/spec/integration/selenium/webdriver:bidi", "//rb/spec/integration/selenium/webdriver:devtools", @@ -52,6 +52,7 @@ rb_library( "//rb/spec/integration/selenium/webdriver/remote:driver", "//rb/spec/integration/selenium/webdriver/remote:element", "//rb/spec/integration/selenium/webdriver/safari:driver", + "//rb/spec/unit/selenium:devtools", "//rb/spec/unit/selenium:server", "//rb/spec/unit/selenium/devtools:cdp_client_generator", "//rb/spec/unit/selenium/webdriver:file_reaper", @@ -67,6 +68,7 @@ rb_library( "//rb/spec/unit/selenium/webdriver/chrome:service", "//rb/spec/unit/selenium/webdriver/common:action_builder", "//rb/spec/unit/selenium/webdriver/common:credentials", + "//rb/spec/unit/selenium/webdriver/common:driver_finder", "//rb/spec/unit/selenium/webdriver/common:logger", "//rb/spec/unit/selenium/webdriver/common:selenium_manager", "//rb/spec/unit/selenium/webdriver/common:service", diff --git a/rb/spec/integration/selenium/webdriver/BUILD.bazel b/rb/spec/integration/selenium/webdriver/BUILD.bazel index 38788477eb259..c420436e6bdbd 100644 --- a/rb/spec/integration/selenium/webdriver/BUILD.bazel +++ b/rb/spec/integration/selenium/webdriver/BUILD.bazel @@ -12,10 +12,7 @@ rb_library( "//rb:manager-linux", "//rb:manager-macos", "//rb:manager-windows", - ] + select({ - "//rb/spec/integration:remote": ["//java/src/org/openqa/selenium/grid:selenium_server_deploy.jar"], - "//conditions:default": [], - }), + ], visibility = ["//rb/spec:__subpackages__"], deps = [ "//rb/lib:selenium-webdriver", @@ -27,14 +24,7 @@ rb_library( "//rb/lib/selenium/webdriver:remote", "//rb/spec:rspec_matchers", "@bundle", - ] + select({ - "//rb/spec/integration:edge": ["//rb/lib/selenium/webdriver:edge"], - "//rb/spec/integration:firefox": ["//rb/lib/selenium/webdriver:firefox"], - "//rb/spec/integration:ie": ["//rb/lib/selenium/webdriver:ie"], - "//rb/spec/integration:safari": ["//rb/lib/selenium/webdriver:safari"], - "//rb/spec/integration:safari-preview": ["//rb/lib/selenium/webdriver:safari"], - "//conditions:default": ["//rb/lib/selenium/webdriver:chrome"], - }), + ], ) [ @@ -79,25 +69,9 @@ rb_integration_test( rb_integration_test( name = "driver", srcs = ["driver_spec.rb"], - deps = [ - "//rb/lib/selenium/webdriver:chrome", - "//rb/lib/selenium/webdriver:edge", - "//rb/lib/selenium/webdriver:firefox", - "//rb/lib/selenium/webdriver:ie", - "//rb/lib/selenium/webdriver:remote", - "//rb/lib/selenium/webdriver:safari", - ], ) rb_integration_test( name = "element", srcs = ["element_spec.rb"], - deps = [ - "//rb/lib/selenium/webdriver:chrome", - "//rb/lib/selenium/webdriver:edge", - "//rb/lib/selenium/webdriver:firefox", - "//rb/lib/selenium/webdriver:ie", - "//rb/lib/selenium/webdriver:remote", - "//rb/lib/selenium/webdriver:safari", - ], ) diff --git a/rb/spec/integration/selenium/webdriver/chrome/BUILD.bazel b/rb/spec/integration/selenium/webdriver/chrome/BUILD.bazel index d9139a02b74ef..bd2441d4b2e56 100644 --- a/rb/spec/integration/selenium/webdriver/chrome/BUILD.bazel +++ b/rb/spec/integration/selenium/webdriver/chrome/BUILD.bazel @@ -4,7 +4,7 @@ load("//rb/spec:tests.bzl", "rb_integration_test") rb_integration_test( name = file[:-8], srcs = [file], - deps = ["//rb/lib/selenium/webdriver:chrome"], + browsers = ["chrome"], # No need to run in other browsers. ) for file in glob(["*_spec.rb"]) ] diff --git a/rb/spec/integration/selenium/webdriver/edge/BUILD.bazel b/rb/spec/integration/selenium/webdriver/edge/BUILD.bazel index 0253733e06441..73f983fef259a 100644 --- a/rb/spec/integration/selenium/webdriver/edge/BUILD.bazel +++ b/rb/spec/integration/selenium/webdriver/edge/BUILD.bazel @@ -4,7 +4,7 @@ load("//rb/spec:tests.bzl", "rb_integration_test") rb_integration_test( name = file[:-8], srcs = [file], - deps = ["//rb/lib/selenium/webdriver:edge"], + browsers = ["edge"], # No need to run in other browsers. ) for file in glob(["*_spec.rb"]) ] diff --git a/rb/spec/integration/selenium/webdriver/firefox/BUILD.bazel b/rb/spec/integration/selenium/webdriver/firefox/BUILD.bazel index 14c80d599aa5b..6cb37b594a5fb 100644 --- a/rb/spec/integration/selenium/webdriver/firefox/BUILD.bazel +++ b/rb/spec/integration/selenium/webdriver/firefox/BUILD.bazel @@ -4,7 +4,12 @@ load("//rb/spec:tests.bzl", "rb_integration_test") rb_integration_test( name = file[:-8], srcs = [file], - deps = ["//rb/lib/selenium/webdriver:firefox"], + # No need to run in other browsers. + browsers = [ + "firefox", + "firefox-beta", + ], + data = ["//common/extensions"], ) for file in glob(["*_spec.rb"]) ] diff --git a/rb/spec/integration/selenium/webdriver/remote/BUILD.bazel b/rb/spec/integration/selenium/webdriver/remote/BUILD.bazel index 7e0376bae6b7f..7c4b21bda53c0 100644 --- a/rb/spec/integration/selenium/webdriver/remote/BUILD.bazel +++ b/rb/spec/integration/selenium/webdriver/remote/BUILD.bazel @@ -4,7 +4,6 @@ load("//rb/spec:tests.bzl", "rb_integration_test") rb_integration_test( name = file[:-8], srcs = [file], - deps = ["//rb/lib/selenium/webdriver:remote"], ) for file in glob(["*_spec.rb"]) ] diff --git a/rb/spec/integration/selenium/webdriver/safari/BUILD.bazel b/rb/spec/integration/selenium/webdriver/safari/BUILD.bazel index 19ca366e44a94..54d03e20334c8 100644 --- a/rb/spec/integration/selenium/webdriver/safari/BUILD.bazel +++ b/rb/spec/integration/selenium/webdriver/safari/BUILD.bazel @@ -4,7 +4,11 @@ load("//rb/spec:tests.bzl", "rb_integration_test") rb_integration_test( name = file[:-8], srcs = [file], - deps = ["//rb/lib/selenium/webdriver:safari"], + # No need to run in other browsers. + browsers = [ + "safari", + "safari-preview", + ], ) for file in glob(["*_spec.rb"]) ] diff --git a/rb/spec/integration/selenium/webdriver/spec_support/test_environment.rb b/rb/spec/integration/selenium/webdriver/spec_support/test_environment.rb index cadaf85d56b89..daae1584aaffc 100644 --- a/rb/spec/integration/selenium/webdriver/spec_support/test_environment.rb +++ b/rb/spec/integration/selenium/webdriver/spec_support/test_environment.rb @@ -217,13 +217,15 @@ def edge_driver(service: nil, **opts) service ||= WebDriver::Service.edge service.args << '--disable-build-check' if ENV['DISABLE_BUILD_CHECK'] service.args << '--verbose' if WebDriver.logger.debug? + service.executable_path = ENV['MSEDGEDRIVER_BINARY'] if ENV.key?('MSEDGEDRIVER_BINARY') WebDriver::Driver.for(:edge, service: service, **opts) end def firefox_driver(service: nil, **opts) service ||= WebDriver::Service.firefox service.args.push('--log', 'trace') if WebDriver.logger.debug? - WebDriver::Driver.for(:firefox, **opts) + service.executable_path = ENV['GECKODRIVER_BINARY'] if ENV.key?('GECKODRIVER_BINARY') + WebDriver::Driver.for(:firefox, service: service, **opts) end def safari_driver(**opts) @@ -255,7 +257,7 @@ def edge_options(args: [], **opts) def firefox_options(args: [], **opts) opts[:binary] ||= ENV['FIREFOX_BINARY'] if ENV.key?('FIREFOX_BINARY') args << '--headless' if ENV['HEADLESS'] - WebDriver::Options.firefox(browser_version: 'stable', args: args, **opts) + WebDriver::Options.firefox(args: args, **opts) end def ie_options(**opts) diff --git a/rb/spec/tests.bzl b/rb/spec/tests.bzl index a4a706a5b8633..f9a1b36bf3b03 100644 --- a/rb/spec/tests.bzl +++ b/rb/spec/tests.bzl @@ -1,73 +1,189 @@ -load("@rules_ruby//ruby:defs.bzl", "rb_test") -load("//common:browsers.bzl", "chrome_data") +load("@rules_ruby//ruby:defs.bzl", "rb_library", "rb_test") +load( + "//common:browsers.bzl", + "COMMON_TAGS", + "chrome_data", + "edge_data", + "firefox_beta_data", + "firefox_data", +) -ENV = select({ - "//rb/spec/integration:chrome": { - "WD_REMOTE_BROWSER": "chrome", - "WD_SPEC_DRIVER": "chrome", +BROWSERS = { + "chrome": { + "data": chrome_data, + "deps": ["//rb/lib/selenium/webdriver:chrome"], + "tags": [], + "target_compatible_with": [], + "env": { + "WD_REMOTE_BROWSER": "chrome", + "WD_SPEC_DRIVER": "chrome", + } | select({ + "@selenium//common:use_pinned_linux_chrome": { + "CHROME_BINARY": "$(location @linux_chrome//:chrome-linux64/chrome)", + "CHROMEDRIVER_BINARY": "$(location @linux_chromedriver//:chromedriver)", + }, + "@selenium//common:use_pinned_macos_chrome": { + "CHROME_BINARY": "$(location @mac_chrome//:Chrome.app)/Contents/MacOS/Chrome", + "CHROMEDRIVER_BINARY": "$(location @mac_chromedriver//:chromedriver)", + }, + "//conditions:default": {}, + }) | select({ + "@selenium//common:use_headless_browser": {"HEADLESS": "true"}, + "//conditions:default": {}, + }), }, - "//rb/spec/integration:edge": { - "WD_REMOTE_BROWSER": "edge", - "WD_SPEC_DRIVER": "edge", - }, - "//rb/spec/integration:firefox": { - "WD_REMOTE_BROWSER": "firefox", - "WD_SPEC_DRIVER": "firefox", - }, - "//rb/spec/integration:ie": { - "WD_REMOTE_BROWSER": "ie", - "WD_SPEC_DRIVER": "ie", - }, - "//rb/spec/integration:safari": { - "WD_REMOTE_BROWSER": "safari", - "WD_SPEC_DRIVER": "safari", + "edge": { + "data": edge_data, + "deps": ["//rb/lib/selenium/webdriver:edge"], + "tags": [ + "skip-remote", # TODO: Add Linux version of Edge to pinned browsers. + ], + "target_compatible_with": [], + "env": { + "WD_REMOTE_BROWSER": "edge", + "WD_SPEC_DRIVER": "edge", + } | select({ + "@selenium//common:use_pinned_macos_edge": { + "EDGE_BINARY": "$(location @mac_edge//:Edge.app)/Contents/MacOS/Microsoft\\ Edge", + "MSEDGEDRIVER_BINARY": "$(location @mac_edgedriver//:msedgedriver)", + }, + "//conditions:default": {}, + }) | select({ + "@selenium//common:use_headless_browser": {"HEADLESS": "true"}, + "//conditions:default": {}, + }), }, - "//rb/spec/integration:safari-preview": { - "WD_REMOTE_BROWSER": "safari-preview", - "WD_SPEC_DRIVER": "safari-preview", + "firefox": { + "data": firefox_data, + "deps": ["//rb/lib/selenium/webdriver:firefox"], + "tags": [], + "target_compatible_with": [], + "env": { + "WD_REMOTE_BROWSER": "firefox", + "WD_SPEC_DRIVER": "firefox", + } | select({ + "@selenium//common:use_pinned_linux_firefox": { + "FIREFOX_BINARY": "$(location @linux_firefox//:firefox/firefox)", + "GECKODRIVER_BINARY": "$(location @linux_geckodriver//:geckodriver)", + }, + "@selenium//common:use_pinned_macos_firefox": { + "FIREFOX_BINARY": "$(location @mac_firefox//:Firefox.app)/Contents/MacOS/firefox", + "GECKODRIVER_BINARY": "$(location @mac_geckodriver//:geckodriver)", + }, + "//conditions:default": {}, + }) | select({ + "@selenium//common:use_headless_browser": {"HEADLESS": "true"}, + "//conditions:default": {}, + }), }, - "//conditions:default": {}, -}) | select({ - "//rb/spec/integration:remote": { - "WD_SPEC_DRIVER": "remote", + "firefox-beta": { + "data": firefox_beta_data, + "deps": ["//rb/lib/selenium/webdriver:firefox"], + "tags": [], + "target_compatible_with": [], + "env": { + "WD_REMOTE_BROWSER": "firefox", + "WD_SPEC_DRIVER": "firefox", + } | select({ + "@selenium//common:use_pinned_linux_firefox": { + "FIREFOX_BINARY": "$(location @linux_beta_firefox//:firefox/firefox)", + "GECKODRIVER_BINARY": "$(location @linux_geckodriver//:geckodriver)", + }, + "@selenium//common:use_pinned_macos_firefox": { + "FIREFOX_BINARY": "$(location @mac_beta_firefox//:Firefox.app)/Contents/MacOS/firefox", + "GECKODRIVER_BINARY": "$(location @mac_geckodriver//:geckodriver)", + }, + "//conditions:default": {}, + }) | select({ + "@selenium//common:use_headless_browser": {"HEADLESS": "true"}, + "//conditions:default": {}, + }), }, - "//conditions:default": {}, -}) | select({ - "//rb/spec/integration:headless": { - "HEADLESS": "true", + "ie": { + "data": [], + "deps": ["//rb/lib/selenium/webdriver:ie"], + "tags": [ + "skip-remote", # RBE is Linux-only. + ], + "target_compatible_with": ["@platforms//os:windows"], + "env": { + "WD_REMOTE_BROWSER": "ie", + "WD_SPEC_DRIVER": "ie", + }, }, - "//conditions:default": {}, -}) | select({ - "@selenium//common:use_pinned_linux_chrome": { - "CHROME_BINARY": "$(location @linux_chrome//:chrome-linux64/chrome)", - "CHROMEDRIVER_BINARY": "$(location @linux_chromedriver//:chromedriver)", + "safari": { + "data": [], + "deps": ["//rb/lib/selenium/webdriver:safari"], + "tags": [ + "exclusive-if-local", # Safari cannot run in parallel. + "skip-remote", # RBE is Linux-only. + ], + "target_compatible_with": ["@platforms//os:macos"], + "env": { + "WD_REMOTE_BROWSER": "safari", + "WD_SPEC_DRIVER": "safari", + }, }, - "@selenium//common:use_pinned_macos_chrome": { - "CHROME_BINARY": "$(location @mac_chrome//:Chrome.app)/Contents/MacOS/Chrome", - "CHROMEDRIVER_BINARY": "$(location @mac_chromedriver//:chromedriver)", + "safari-preview": { + "data": [], + "deps": ["//rb/lib/selenium/webdriver:safari"], + "tags": [ + "exclusive-if-local", # Safari cannot run in parallel. + "skip-remote", # RBE is Linux-only. + ], + "target_compatible_with": ["@platforms//os:macos"], + "env": { + "WD_REMOTE_BROWSER": "safari-preview", + "WD_SPEC_DRIVER": "safari-preview", + }, }, - "//conditions:default": {}, -}) +} -# We have to use no-sandbox at the moment because Firefox crashes -# when run under sandbox: https://bugzilla.mozilla.org/show_bug.cgi?id=1382498. -# For Chromium-based browser, we can just pass `--no-sandbox` flag. -TAGS = ["no-sandbox"] - -def rb_integration_test(name, srcs, deps, tags = []): - rb_test( +def rb_integration_test(name, srcs, deps = [], data = [], browsers = BROWSERS.keys(), tags = []): + # Generate a library target that is used by //rb/spec:spec to expose all tests to //rb:lint. + rb_library( name = name, - size = "large", srcs = srcs, - args = ["rb/spec/"], - data = chrome_data + ["//common/src/web"], - env = ENV, - main = "@bundle//bin:rspec", - tags = TAGS + tags, - deps = deps + ["//rb/spec/integration/selenium/webdriver:spec_helper"], visibility = ["//rb:__subpackages__"], ) + for browser in browsers: + # Generate a test target for local browser execution. + rb_test( + name = "{}-{}".format(name, browser), + size = "large", + srcs = srcs, + args = ["rb/spec/"], + data = BROWSERS[browser]["data"] + data + ["//common/src/web"], + env = BROWSERS[browser]["env"], + main = "@bundle//bin:rspec", + tags = COMMON_TAGS + BROWSERS[browser]["tags"] + tags + [browser], + deps = ["//rb/spec/integration/selenium/webdriver:spec_helper"] + BROWSERS[browser]["deps"] + deps, + visibility = ["//rb:__subpackages__"], + target_compatible_with = BROWSERS[browser]["target_compatible_with"], + ) + + # Generate a test target for remote browser execution (Grid). + rb_test( + name = "{}-{}-remote".format(name, browser), + size = "large", + srcs = srcs, + args = ["rb/spec/"], + data = BROWSERS[browser]["data"] + data + [ + "//common/src/web", + "//java/src/org/openqa/selenium/grid:selenium_server_deploy.jar", + ], + env = BROWSERS[browser]["env"] | {"WD_SPEC_DRIVER": "remote"}, + main = "@bundle//bin:rspec", + tags = COMMON_TAGS + BROWSERS[browser]["tags"] + tags + [ + "{}-remote".format(browser), + "skip-remote", # Do we want to run remote tests in RBE? + ], + deps = ["//rb/spec/integration/selenium/webdriver:spec_helper"] + BROWSERS[browser]["deps"] + deps, + visibility = ["//rb:__subpackages__"], + target_compatible_with = BROWSERS[browser]["target_compatible_with"], + ) + def rb_unit_test(name, srcs, deps, data = []): rb_test( name = name, @@ -76,10 +192,7 @@ def rb_unit_test(name, srcs, deps, data = []): args = ["rb/spec/"], main = "@bundle//bin:rspec", data = data, - tags = TAGS, - deps = deps + [ - "//rb/spec/unit/selenium/webdriver:spec_helper", - "@bundle", - ], + tags = ["no-sandbox"], # TODO: Do we need this? + deps = ["//rb/spec/unit/selenium/webdriver:spec_helper"] + deps, visibility = ["//rb:__subpackages__"], )