| load("@aspect_bazel_lib//lib:copy_directory.bzl", "copy_directory") | |
| load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin") | |
| load("@aspect_bazel_lib//lib:jq.bzl", "jq") | |
| load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_library") | |
| load("@aspect_rules_js//npm:defs.bzl", "npm_package") | |
| load("@npm//:defs.bzl", "npm_link_all_packages") | |
| load("@npm//javascript/selenium-webdriver:eslint/package_json.bzl", eslint_bin = "bin") | |
| load("@npm//javascript/selenium-webdriver:jsdoc/package_json.bzl", jsdoc_bin = "bin") | |
| load("@npm//javascript/selenium-webdriver:prettier/package_json.bzl", prettier_bin = "bin") | |
| load("@rules_pkg//pkg:pkg.bzl", "pkg_tar") | |
| load("//:version.bzl", "VERSIONS") | |
| load("//common:browsers.bzl", "COMMON_TAGS") | |
| load("//common:defs.bzl", "copy_file") | |
| load("//common:webref_cddl.bzl", "BIDI_DFNS_FILES", "BIDI_EXTENSION_CDDL_FILES", "BIDI_VENDOR_CDDL_FILES", "WEBDRIVER_BIDI_CDDL") | |
| load("//common/manager:defs.bzl", "SE_MANAGER_TEST_DATA", "SE_MANAGER_TEST_ENV", "SE_MANAGER_TEST_EXEC_PROPERTIES") | |
| load("//javascript:defs.bzl", "mocha_test") | |
| load("//javascript/private:browsers.bzl", "BROWSERS") | |
| load("//javascript/private:jsdoc.bzl", "jsdoc") | |
| load("//javascript/selenium-webdriver/private:generate_bidi.bzl", "generate_bidi_library") | |
| load(":test/test_browsers.bzl", "TEST_BROWSERS") | |
| npm_link_all_packages(name = "node_modules") | |
| # Copy the shared license + note next to the generator so it can read them as siblings. | |
| copy_file( | |
| name = "license_header_local", | |
| src = "//scripts:license_header.txt", | |
| out = "license_header.txt", | |
| ) | |
| copy_file( | |
| name = "generated_note_local", | |
| src = "//scripts:generated_note_template.txt", | |
| out = "generated_note_template.txt", | |
| ) | |
| # Generator script that reads the merged CDDL spec and produces one .ts file per BiDi domain. | |
| js_binary( | |
| name = "generate_bidi_script", | |
| data = [ | |
| "generate_bidi.mjs", | |
| "normalize_bidi_ast.mjs", | |
| "project_bidi_schema.mjs", | |
| ":generated_note_local", | |
| ":license_header_local", | |
| ":node_modules/cddl", | |
| ], | |
| entry_point = "generate_bidi.mjs", | |
| ) | |
| # Projects the normalized, flat BiDi schema (commands + events + types) consumed | |
| # by the generated Ruby / Java / Python clients. Pure JS — no npm dependencies. | |
| js_binary( | |
| name = "project_bidi_schema_script", | |
| data = [ | |
| "normalize_bidi_ast.mjs", | |
| "project_bidi_schema.mjs", | |
| ], | |
| entry_point = "project_bidi_schema.mjs", | |
| ) | |
| # Extracts the core spec's prose section anchors (#type-/#command-/#event-/#module-) | |
| # from the pinned rendered HTML into the small index the schema step joins against. | |
| js_binary( | |
| name = "extract_bidi_anchors_script", | |
| data = ["extract_bidi_anchors.mjs"], | |
| entry_point = "extract_bidi_anchors.mjs", | |
| ) | |
| # Tests for the BiDi schema tooling: unit tests for the normalizer + projector | |
| # transforms, plus the authoritative field-fidelity check that diffs the | |
| # projected schema against cddl2ts (an independent generator over the same AST, | |
| # run over the generated artifacts) — catching dropped/mistyped fields and enum | |
| # drift that the structural validators cannot see. | |
| mocha_test( | |
| name = "bidi-schema-tests", | |
| size = "small", | |
| args = ["./*_test.mjs"], | |
| chdir = package_name(), | |
| data = [ | |
| "bidi_schema_diff_test.mjs", | |
| "extract_bidi_anchors.mjs", | |
| "normalize_bidi_ast.mjs", | |
| "normalize_bidi_ast_test.mjs", | |
| "project_bidi_schema.mjs", | |
| "project_bidi_schema_test.mjs", | |
| ":create-bidi-src_ast", | |
| ":create-bidi-src_schema", | |
| ":node_modules/cddl2ts", | |
| ":node_modules/mocha", | |
| ], | |
| ) | |
| # Generate WebDriver BiDi TypeScript modules from CDDL specification. The merged specs | |
| # (core plus every external BiDi module) come from the generated //common:webref_cddl.bzl. | |
| generate_bidi_library( | |
| name = "create-bidi-src", | |
| cddl_file = WEBDRIVER_BIDI_CDDL, | |
| # The schema step joins each spec's dfns index by type name to attach a `specHref` | |
| # link to each type's definition in the live spec. | |
| dfns_files = BIDI_DFNS_FILES, | |
| extra_cddl_files = BIDI_EXTENSION_CDDL_FILES, | |
| # Spec-shaped, browser-neutral productions that supersede an upstream one by name. Stay | |
| # in the shared schema: they complete command/event aggregates the specs define members | |
| # for but never list, or relax a field the spec requires ahead of every implementation. | |
| override_cddl_files = [ | |
| "//common/bidi:browsing-context-created-params.cddl", | |
| "//common/bidi:digital-credentials-command.cddl", | |
| "//common/bidi:web-bluetooth-events.cddl", | |
| ], | |
| # The pinned rendered core spec. The schema step extracts its prose section anchors | |
| # (#type-/#command-/#event-/#module-) to upgrade type links and add command/event/ | |
| # domain links; adjacent specs keep the webref CDDL fallback. | |
| spec_html = "@webdriver_bidi_spec_html//file:index.html", | |
| spec_version = "1.0", | |
| # Vendor grammars keyed by namespace: `<Type>Extension` groups spliced into the like-named spec | |
| # type, provenance-tagged and routed into the schema's separate `vendor` section, so the shared | |
| # schema stays exactly what upstream emits. | |
| vendor_cddl_files = BIDI_VENDOR_CDDL_FILES, | |
| ) | |
| VERSION = VERSIONS["javascript"] | |
| BROWSER_VERSIONS = [ | |
| "v155", | |
| "v156", | |
| "v157", | |
| ] | |
| js_library( | |
| name = "prod-src-files", | |
| srcs = glob([ | |
| "*.js", | |
| "example/*.js", | |
| "http/*.js", | |
| "io/*.js", | |
| "lib/*.js", | |
| "lib/fedcm/*.js", | |
| "net/*.js", | |
| "remote/*.js", | |
| "testing/*.js", | |
| "devtools/*.js", | |
| "common/*.js", | |
| "bidi/*.js", | |
| "bidi/external/*.js", | |
| "bidi/serialization/*.js", | |
| ]), | |
| deps = [ | |
| ":node_modules/@bazel/runfiles", | |
| ":node_modules/jszip", | |
| ":node_modules/tmp", | |
| ":node_modules/ws", | |
| ], | |
| ) | |
| jq( | |
| name = "package-json-stamped", | |
| srcs = ["package.json"], | |
| out = "stamped/package.json", | |
| filter = '.version = "%s"' % VERSION, | |
| ) | |
| npm_package( | |
| name = "selenium-webdriver", | |
| srcs = [ | |
| ":create-bidi-src", | |
| ":license", | |
| ":manager-linux-arm64", | |
| ":manager-linux-x86_64", | |
| ":manager-macos", | |
| ":manager-notice", | |
| ":manager-sbom", | |
| ":manager-windows", | |
| ":prod-src-files", | |
| "//javascript/selenium-webdriver/lib/atoms:accessibility_snapshot", | |
| "//javascript/selenium-webdriver/lib/atoms:bidi-mutation-listener", | |
| "//javascript/selenium-webdriver/lib/atoms:find-elements", | |
| "//javascript/selenium-webdriver/lib/atoms:get_attribute", | |
| "//javascript/selenium-webdriver/lib/atoms:is_displayed", | |
| "//javascript/selenium-webdriver/lib/atoms:mutation-listener", | |
| ] + select({ | |
| # Tests link the unstamped package, so the version and the docs that change every release stay out of it | |
| "//common:stamp": [ | |
| "CHANGES.md", | |
| "README.md", | |
| ":package-json-stamped", | |
| ], | |
| "//conditions:default": ["package.json"], | |
| }), | |
| package = "selenium-webdriver", | |
| publishable = True, | |
| replace_prefixes = {"stamped/": ""}, | |
| tags = [ | |
| "release-artifact", | |
| ], | |
| visibility = ["//visibility:public"], | |
| ) | |
| pkg_tar( | |
| name = "selenium-webdriver.tgz", | |
| srcs = [ | |
| ":selenium-webdriver", | |
| ], | |
| out = "selenium-webdriver-%s.tgz" % VERSION, | |
| extension = "tgz", | |
| package_dir = "package", | |
| strip_prefix = "selenium-webdriver", | |
| ) | |
| SMALL_TESTS = [ | |
| "test/bidi/domain_test.js", | |
| "test/bidi/index_test.js", | |
| "test/bidi/network_types_test.js", | |
| "test/bidi/serialization/record_test.js", | |
| "test/bidi/serialization/union_test.js", | |
| "test/bidi/serialization/wire_contract_test.js", | |
| "test/bidi/vendor_test.js", | |
| "test/http/http_test.js", | |
| "test/http/util_test.js", | |
| "test/io/io_test.js", | |
| "test/io/zip_test.js", | |
| "test/lib/accessibility_snapshot_test.js", | |
| "test/lib/bidi_connection_test.js", | |
| "test/lib/by_test.js", | |
| "test/lib/credentials_test.js", | |
| "test/lib/error_test.js", | |
| "test/lib/http_test.js", | |
| "test/lib/input_test.js", | |
| "test/lib/logging_test.js", | |
| "test/lib/promise_test.js", | |
| "test/lib/test_browsers_test.js", | |
| "test/lib/until_test.js", | |
| "test/lib/virtualauthenticatoroptions_test.js", | |
| "test/lib/web_extension_test.js", | |
| "test/lib/webdriver_test.js", | |
| "test/net/index_test.js", | |
| "test/net/portprober_test.js", | |
| "test/remote_test.js", | |
| ] | |
| LARGE_TESTS = glob( | |
| ["test/**/*_test.js"], | |
| exclude = SMALL_TESTS, | |
| ) | |
| js_library( | |
| name = "small-test-srcs", | |
| srcs = SMALL_TESTS, | |
| ) | |
| js_library( | |
| name = "large-test-srcs", | |
| srcs = LARGE_TESTS, | |
| ) | |
| js_library( | |
| name = "test-data", | |
| srcs = glob( | |
| [ | |
| "lib/test/**", | |
| "test/**", | |
| ], | |
| exclude = [ | |
| "test/**/*_test.js", | |
| ], | |
| ), | |
| deps = [ | |
| ":node_modules/@bazel/runfiles", | |
| ], | |
| ) | |
| mocha_test( | |
| name = "small-tests", | |
| size = "small", | |
| args = SMALL_TESTS, | |
| chdir = package_name(), | |
| data = [ | |
| ":large-test-srcs", | |
| ":node_modules/@bazel/runfiles", | |
| ":node_modules/mocha", | |
| ":node_modules/mocha-junit-reporter", | |
| ":node_modules/sinon", | |
| ":node_modules/ws", | |
| ":small-test-srcs", | |
| ":test-data", | |
| "//:node_modules/selenium-webdriver", | |
| "//common/extensions:js-lib", | |
| "//common/src/web:js-lib", | |
| ], | |
| tags = ["unit"], | |
| ) | |
| # Browsers refuse to load an unpacked extension whose files are runfiles symlinks pointing | |
| # outside its directory, so tests get the fixture directories as real copies. | |
| copy_directory( | |
| name = "webextensions-selenium-example-dir", | |
| testonly = True, | |
| src = "//common/extensions:webextensions-selenium-example", | |
| out = "test/extensions/webextensions-selenium-example", | |
| ) | |
| copy_directory( | |
| name = "webextensions-selenium-example-signed-dir", | |
| testonly = True, | |
| src = "//common/extensions:webextensions-selenium-example-signed", | |
| out = "test/extensions/webextensions-selenium-example-signed", | |
| ) | |
| LARGE_TEST_DATA = [ | |
| ":large-test-srcs", | |
| ":node_modules/express", | |
| ":node_modules/mocha", | |
| ":node_modules/mocha-junit-reporter", | |
| ":node_modules/multer", | |
| ":node_modules/serve-index", | |
| ":node_modules/sinon", | |
| ":test-data", | |
| ":webextensions-selenium-example-dir", | |
| ":webextensions-selenium-example-signed-dir", | |
| "//:node_modules/selenium-webdriver", | |
| "//common/extensions:js-lib", | |
| "//common/src/web:js-lib", | |
| ] | |
| # Behavior depends on the operating system, which RBE (Linux only) cannot cover. | |
| OS_SENSITIVE_TESTS = [ | |
| "test/actions_test.js", | |
| "test/firefox/full_page_screenshot_test.js", | |
| "test/window_test.js", | |
| ] | |
| # Find the driver through Selenium Manager. | |
| SE_MANAGER_TESTS = [ | |
| "test/chrome/service_test.js", | |
| "test/edge/service_test.js", | |
| ] | |
| [ | |
| [ | |
| mocha_test( | |
| name = "%s-%s" % ( | |
| test.replace("/", "-").replace("_", "-"), | |
| browser, | |
| ), | |
| size = "large", | |
| args = [ | |
| "--retries", | |
| "1", | |
| test, | |
| ], | |
| chdir = package_name(), | |
| data = LARGE_TEST_DATA + (SE_MANAGER_TEST_DATA if test in SE_MANAGER_TESTS else BROWSERS[browser]["data"]), | |
| env = { | |
| "SELENIUM_BROWSER": browser, | |
| } | (SE_MANAGER_TEST_ENV if test in SE_MANAGER_TESTS else BROWSERS[browser]["env"]), | |
| exec_properties = SE_MANAGER_TEST_EXEC_PROPERTIES if test in SE_MANAGER_TESTS else {}, | |
| tags = [browser] + COMMON_TAGS + | |
| (["os-sensitive"] if test in OS_SENSITIVE_TESTS else []) + | |
| (["se-manager"] if test in SE_MANAGER_TESTS else []), | |
| ), | |
| ] | |
| for test in LARGE_TESTS | |
| for browser in BROWSERS.keys() | |
| if browser in TEST_BROWSERS.get( | |
| test, | |
| BROWSERS.keys(), | |
| ) | |
| ] | |
| GRID_BROWSERS = [ | |
| "chrome", | |
| "firefox", | |
| ] | |
| # These test the local driver service itself. | |
| NO_GRID_TESTS = [ | |
| "test/chrome/service_test.js", | |
| "test/edge/service_test.js", | |
| ] | |
| GRID_TESTS = [test for test in LARGE_TESTS if test not in NO_GRID_TESTS] | |
| genrule( | |
| name = "java-location", | |
| srcs = [], | |
| outs = ["java-location.txt"], | |
| cmd = "echo $(JAVA) > $@", | |
| toolchains = ["@bazel_tools//tools/jdk:current_java_runtime"], | |
| ) | |
| [ | |
| mocha_test( | |
| name = "%s-%s-remote" % ( | |
| test.replace("/", "-").replace("_", "-"), | |
| browser, | |
| ), | |
| size = "large", | |
| args = [ | |
| "--retries", | |
| "1", | |
| test, | |
| ], | |
| chdir = package_name(), | |
| data = LARGE_TEST_DATA + BROWSERS[browser]["data"] + [ | |
| ":java-location", | |
| "//java/src/org/openqa/selenium/grid:selenium_server_deploy.jar", | |
| "@bazel_tools//tools/jdk:current_java_runtime", | |
| ], | |
| env = { | |
| "SELENIUM_BROWSER": browser, | |
| "SELENIUM_SERVER_JAR": "$(rootpath //java/src/org/openqa/selenium/grid:selenium_server_deploy.jar)", | |
| "SE_BAZEL_JAVA_LOCATION": "$(rootpath :java-location)", | |
| } | BROWSERS[browser]["env"], | |
| # rules_js cannot copy the hermetic JDK's external-repository files into the output tree. | |
| no_copy_to_bin = ["@bazel_tools//tools/jdk:current_java_runtime"], | |
| tags = [ | |
| browser, | |
| "remote", | |
| "%s-remote" % browser, | |
| ] + COMMON_TAGS, | |
| ) | |
| for test in GRID_TESTS | |
| for browser in GRID_BROWSERS | |
| if browser in TEST_BROWSERS.get(test, GRID_BROWSERS) | |
| ] | |
| # npm_package does not pick up filegroup sources. | |
| genrule( | |
| name = "license", | |
| srcs = ["//:license"], | |
| outs = [ | |
| "LICENSE", | |
| "NOTICE", | |
| ], | |
| cmd = "cp $(locations //:license) $(@D)", | |
| ) | |
| copy_file( | |
| name = "manager-linux-x86_64", | |
| src = "//common/manager:selenium-manager-linux-x86_64", | |
| out = "bin/linux-x86_64/selenium-manager", | |
| ) | |
| copy_file( | |
| name = "manager-linux-arm64", | |
| src = "//common/manager:selenium-manager-linux-arm64", | |
| out = "bin/linux-arm64/selenium-manager", | |
| ) | |
| copy_file( | |
| name = "manager-macos", | |
| src = "//common/manager:selenium-manager-macos", | |
| out = "bin/macos/selenium-manager", | |
| ) | |
| copy_file( | |
| name = "manager-windows", | |
| src = "//common/manager:selenium-manager-windows", | |
| out = "bin/windows/selenium-manager.exe", | |
| ) | |
| copy_file( | |
| name = "manager-sbom", | |
| src = "//common/manager:selenium-manager-sbom", | |
| out = "bin/selenium-manager.cdx.json", | |
| ) | |
| copy_file( | |
| name = "manager-notice", | |
| src = "//common/manager:selenium-manager-notice", | |
| out = "bin/selenium-manager-THIRD-PARTY-NOTICES.txt", | |
| ) | |
| copy_to_bin( | |
| name = "package-json", | |
| srcs = ["package.json"], | |
| ) | |
| eslint_bin.eslint_test( | |
| name = "eslint-test", | |
| chdir = package_name(), | |
| data = [ | |
| # Sources require the generated BiDi modules. | |
| ":create-bidi-src", | |
| ":eslint-config", | |
| ":node_modules/@eslint/js", | |
| ":node_modules/eslint-plugin-mocha", | |
| ":node_modules/eslint-plugin-n", | |
| ":node_modules/eslint-plugin-no-only-tests", | |
| ":node_modules/eslint-plugin-prettier", | |
| ":node_modules/globals", | |
| ":node_modules/jszip", | |
| ":node_modules/mocha", | |
| ":node_modules/tmp", | |
| ":node_modules/ws", | |
| ":package-json", | |
| ":prod-src-files", | |
| # lib/accessibility_snapshot.js requires the built atom module statically. | |
| "//javascript/selenium-webdriver/lib/atoms:accessibility_snapshot", | |
| ], | |
| tags = [ | |
| "lint", | |
| "skip-rbe", | |
| ], | |
| ) | |
| copy_to_bin( | |
| name = "eslint-config", | |
| srcs = ["eslint.config.js"], | |
| ) | |
| prettier_bin.prettier_test( | |
| name = "prettier-test", | |
| args = [ | |
| ".", | |
| "--check", | |
| "--ignore-unknown", | |
| "--config=.prettierrc", | |
| ], | |
| chdir = package_name(), | |
| data = [ | |
| ":large-test-srcs", | |
| ":package-json", | |
| ":prettier-config", | |
| ":prettier-ignore", | |
| ":prod-src-files", | |
| ":small-test-srcs", | |
| ], | |
| tags = [ | |
| "lint", | |
| "skip-rbe", | |
| ], | |
| ) | |
| copy_to_bin( | |
| name = "prettier-config", | |
| srcs = [".prettierrc"], | |
| ) | |
| copy_to_bin( | |
| name = "prettier-ignore", | |
| srcs = [".prettierignore"], | |
| ) | |
| _ESLINT_DATA = [ | |
| ":eslint-config", | |
| ":large-test-srcs", | |
| ":node_modules/@eslint/js", | |
| ":node_modules/eslint-plugin-mocha", | |
| ":node_modules/eslint-plugin-n", | |
| ":node_modules/eslint-plugin-no-only-tests", | |
| ":node_modules/eslint-plugin-prettier", | |
| ":node_modules/globals", | |
| ":node_modules/jszip", | |
| ":node_modules/tmp", | |
| ":node_modules/ws", | |
| ":package-json", | |
| ":prod-src-files", | |
| ":small-test-srcs", | |
| ] | |
| # Eslint binary with auto-fix support: bazel run //javascript/selenium-webdriver:eslint -- --fix . | |
| eslint_bin.eslint_binary( | |
| name = "eslint", | |
| chdir = package_name(), | |
| data = _ESLINT_DATA, | |
| ) | |
| # Internal jsdoc binary from npm - used by the docs rule | |
| jsdoc_bin.jsdoc_binary( | |
| name = "jsdoc_bin", | |
| visibility = ["//visibility:private"], | |
| ) | |
| # Documentation generator that wraps jsdoc and handles: | |
| # - Output to workspace build directory | |
| # - Ignoring jsdoc type warning exit codes | |
| jsdoc( | |
| name = "docs", | |
| config = "jsdoc_conf.json", | |
| data = [ | |
| "README.md", | |
| ":node_modules/clean-jsdoc-theme", | |
| ":prod-src-files", | |
| ], | |
| jsdoc_binary = ":jsdoc_bin", | |
| ) |