├── .bazelci ├── presubmit.yml └── setup_ubuntu.sh ├── .bazelignore ├── .bazelrc ├── .bcr ├── config.yml ├── metadata.template.json ├── presubmit.yml ├── source.template.json ├── web_testing_go │ ├── metadata.template.json │ ├── presubmit.yml │ └── source.template.json ├── web_testing_java │ ├── metadata.template.json │ ├── presubmit.yml │ └── source.template.json ├── web_testing_python │ ├── metadata.template.json │ ├── presubmit.yml │ └── source.template.json └── web_testing_scala │ ├── metadata.template.json │ ├── presubmit.yml │ └── source.template.json ├── .gitignore ├── AUTHORS ├── BUILD.bazel ├── CODEOWNERS ├── CONTRIBUTING ├── CONTRIBUTORS ├── LICENSE ├── MODULE.bazel ├── README.md ├── browsers ├── BUILD.bazel ├── chrome-external.json ├── chromium-local.json ├── disabled.json ├── firefox-external.json ├── firefox-local.json ├── sauce │ ├── BUILD.bazel │ ├── chrome-win10-connect.json │ └── chrome-win10.json └── size.json ├── build_files ├── BUILD.bazel ├── metadata.BUILD ├── wsl.BUILD ├── wsl_main.BUILD └── wtl.BUILD ├── common └── conditions │ └── BUILD.bazel ├── go.mod ├── go.sum ├── go ├── bazel │ ├── BUILD.bazel │ └── bazel.go ├── cmdhelper │ ├── BUILD.bazel │ └── cmd_helper.go ├── errors │ ├── BUILD.bazel │ ├── errors.go │ └── errors_test.go ├── healthreporter │ ├── BUILD.bazel │ ├── health_reporter.go │ └── health_reporter_test.go ├── httphelper │ ├── BUILD.bazel │ ├── http_helper.go │ └── http_helper_test.go ├── metadata │ ├── BUILD.bazel │ ├── capabilities │ │ ├── BUILD.bazel │ │ ├── capabilities.go │ │ └── capabilities_test.go │ ├── extension_test.go │ ├── main │ │ ├── BUILD.bazel │ │ ├── merger.go │ │ └── merger_test.sh │ ├── metadata.go │ ├── metadata_test.go │ └── web_test_files.go ├── portpicker │ ├── BUILD.bazel │ └── port_picker.go ├── web │ ├── BUILD.bazel │ └── go.bzl ├── webdriver │ ├── BUILD.bazel │ ├── webdriver.go │ ├── webdriver_error.go │ └── webdriver_test.go ├── webtest │ ├── BUILD.bazel │ ├── browserinfo_test.go │ ├── webtest.go │ └── webtest_test.go ├── wsl │ ├── BUILD.bazel │ ├── driver │ │ ├── BUILD.bazel │ │ └── driver.go │ ├── hub │ │ ├── BUILD.bazel │ │ └── hub.go │ ├── main │ │ ├── BUILD.bazel │ │ └── main.go │ ├── resolver │ │ ├── BUILD.bazel │ │ └── resolver.go │ ├── upload │ │ ├── BUILD.bazel │ │ ├── upload.go │ │ └── upload_test.go │ ├── wsl.go │ └── wsl_test.go └── wtl │ ├── BUILD.bazel │ ├── diagnostics │ ├── BUILD.bazel │ └── diagnostics.go │ ├── environment │ ├── BUILD.bazel │ ├── environment.go │ ├── external │ │ ├── BUILD.bazel │ │ └── external.go │ ├── local │ │ ├── BUILD.bazel │ │ └── local.go │ └── sauce │ │ ├── BUILD.bazel │ │ └── sauce.go │ ├── main │ ├── BUILD.bazel │ └── main.go │ ├── proxy │ ├── BUILD.bazel │ ├── driverhub │ │ ├── BUILD.bazel │ │ ├── debugger │ │ │ ├── BUILD.bazel │ │ │ ├── debugger.go │ │ │ └── debugger_test.go │ │ ├── driver_hub.go │ │ ├── driver_responses.go │ │ ├── driver_session.go │ │ ├── drivermu │ │ │ ├── BUILD.bazel │ │ │ └── driver_mu.go │ │ ├── quithandler │ │ │ ├── BUILD.bazel │ │ │ ├── quit_handler.go │ │ │ └── quit_handler_test.go │ │ └── scripttimeout │ │ │ ├── BUILD.bazel │ │ │ ├── script_timeout.go │ │ │ └── script_timeout_test.go │ ├── healthz │ │ ├── BUILD.bazel │ │ └── healthz.go │ ├── proxy.go │ └── proxy_test.go │ ├── service │ ├── BUILD.bazel │ ├── cmd.go │ ├── sauce │ │ ├── BUILD.bazel │ │ └── connect.go │ ├── server.go │ ├── service.go │ └── wsl │ │ ├── BUILD.bazel │ │ └── wsl.go │ └── wtl.go ├── sauce.md ├── testdata ├── BUILD.bazel ├── all-fields.json ├── android-browser-gingerbread-nexus-s.json ├── bad-named-files.json ├── cert.pem ├── chrome-linux.json ├── example.png ├── extension.json ├── key.pem ├── merge-from-file-result.json ├── merger-result.json ├── named-files1.json ├── named-files2.json ├── testpage.html ├── webdriver.html └── webdriver_autofocus.html ├── third_party ├── chromedriver │ ├── BUILD.bazel │ └── LICENSE ├── chromium │ ├── BUILD.bazel │ └── LICENSE ├── firefox │ ├── BUILD.bazel │ └── LICENSE ├── geckodriver │ ├── BUILD.bazel │ └── LICENSE └── sauceconnect │ ├── BUILD.bazel │ └── license.html ├── tools ├── copy.bara.sky └── releaser.sh ├── web ├── BUILD.bazel ├── extension.bzl ├── internal │ ├── BUILD.bazel │ ├── browser.bzl │ ├── constants.bzl │ ├── convert_dmg.sh │ ├── custom_browser.bzl │ ├── executable_name.bzl │ ├── files.bzl │ ├── metadata.bzl │ ├── noop_web_test.sh.template │ ├── platform_archive.bzl │ ├── platform_metadata.bzl │ ├── provider.bzl │ ├── runfiles.bzl │ ├── web_test.bzl │ ├── web_test.sh.template │ ├── web_test_config.bzl │ ├── web_test_files.bzl │ ├── web_test_named_executable.bzl │ ├── web_test_named_file.bzl │ ├── windows_utils.bzl │ └── wrap_web_test_suite.bzl ├── versioned │ ├── BUILD.bazel │ ├── browsers-0.3.1.bzl │ ├── browsers-0.3.2.bzl │ ├── browsers-0.3.3.bzl │ └── browsers-0.3.4.bzl └── web.bzl ├── web_testing_go ├── .bazelci │ └── setup_ubuntu.sh ├── BUILD.bazel ├── MODULE.bazel ├── testdata │ ├── BUILD │ └── all-fields.json ├── web │ ├── BUILD.bazel │ └── go.bzl └── webtest │ ├── BUILD.bazel │ ├── browserinfo_test.go │ ├── webtest.go │ └── webtest_test.go ├── web_testing_java ├── .bazelci │ └── setup_ubuntu.sh ├── MODULE.bazel ├── java │ └── com │ │ └── google │ │ └── testing │ │ ├── bazel │ │ ├── BUILD.bazel │ │ └── Bazel.java │ │ └── web │ │ ├── BUILD.bazel │ │ └── WebTest.java ├── javatests │ └── com │ │ └── google │ │ └── testing │ │ └── web │ │ ├── BUILD.bazel │ │ └── WebTestTest.java └── web │ ├── BUILD.bazel │ └── java.bzl ├── web_testing_python ├── .bazelci │ └── setup_ubuntu.sh ├── BUILD.bazel ├── MODULE.bazel ├── requirements.in ├── requirements_lock.txt ├── requirements_lock_windows.txt ├── testing │ └── web │ │ ├── BUILD.bazel │ │ ├── debugger │ │ ├── BUILD │ │ └── debugger.py │ │ ├── webtest.py │ │ └── webtest_test.py └── web │ ├── BUILD.bazel │ └── py.bzl └── web_testing_scala ├── .bazelci └── setup_ubuntu.sh ├── MODULE.bazel ├── scalatests ├── BUILD.bazel └── WebTestTest.scala └── web ├── BUILD.bazel └── scala.bzl /.bazelci/setup_ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2025 Google Inc. All Rights Reserved 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS-IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Script that can be used by CI server for testing rules_webtesting builds. 17 | set -ex 18 | 19 | sudo apt -y update 20 | sudo apt -y install libasound2 \ 21 | libdbus-glib-1-2 \ 22 | libatk-bridge2.0-0 \ 23 | libatk1.0-0 \ 24 | libc6 \ 25 | libcairo2 \ 26 | libcups2 \ 27 | libdbus-1-3 \ 28 | libexpat1 \ 29 | libfontconfig1 \ 30 | libgbm1 \ 31 | libgcc1 \ 32 | libglib2.0-0 \ 33 | libgtk-3-0 \ 34 | libnspr4 \ 35 | libnss3 \ 36 | libpango-1.0-0 \ 37 | libpangocairo-1.0-0 \ 38 | libstdc++6 \ 39 | libx11-6 \ 40 | libx11-xcb1 \ 41 | libxcb1 \ 42 | libxcomposite1 \ 43 | libxcursor1 \ 44 | libxdamage1 \ 45 | libxext6 \ 46 | libxfixes3 \ 47 | libxi6 \ 48 | libxrandr2 \ 49 | libxrender1 \ 50 | libxss1 \ 51 | libxtst6 \ 52 | libgtk-3-0 53 | -------------------------------------------------------------------------------- /.bazelignore: -------------------------------------------------------------------------------- 1 | web_testing_go 2 | web_testing_java 3 | web_testing_python 4 | web_testing_scala 5 | -------------------------------------------------------------------------------- /.bazelrc: -------------------------------------------------------------------------------- 1 | common --noenable_workspace 2 | 3 | # For running sauce-based configs. 4 | test --test_env=SAUCE_USERNAME 5 | test --test_env=SAUCE_ACCESS_KEY 6 | test --test_env=TUNNEL_IDENTIFIER 7 | test --test_env=BUILD_TAG 8 | test --local_test_jobs=5 9 | 10 | # Do not build runfile forests by default. If an execution strategy relies on runfile 11 | # forests, the forest is created on-demand. See: https://github.com/bazelbuild/bazel/issues/6627 12 | # and https://github.com/bazelbuild/bazel/commit/03246077f948f2790a83520e7dccc2625650e6df 13 | # Note: This also works around an issue where Bazel does not support spaces in runfiles. The 14 | # Chromium app files for Darwin contain files with spaces and this would break. For darwin though, 15 | # the sandbox strategy is used anyway and runfile forests are not needed. 16 | # Related Bazel bug: https://github.com/bazelbuild/bazel/issues/4327. 17 | build --nobuild_runfile_links 18 | 19 | # Fail if a glob doesn't match anything (https://github.com/bazelbuild/bazel/issues/8195) 20 | build --incompatible_disallow_empty_glob 21 | -------------------------------------------------------------------------------- /.bcr/config.yml: -------------------------------------------------------------------------------- 1 | # See https://github.com/bazel-contrib/publish-to-bcr#a-note-on-release-automation 2 | fixedReleaser: 3 | login: mollyibot 4 | email: mollyibot@google.com 5 | moduleRoots: [".", "web_testing_go", "web_testing_java", "web_testing_python", "web_testing_scala"] -------------------------------------------------------------------------------- /.bcr/metadata.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "homepage": "https://github.com/bazelbuild/rules_webtesting", 3 | "maintainers": [ 4 | { 5 | "name": "Michael Rea", 6 | "email": "mtrea@google.com", 7 | "github": "mtrea" 8 | }, 9 | { 10 | "name": "Yuan Tian", 11 | "email": "mollyibot@google.com", 12 | "github": "mollyibot" 13 | } 14 | ], 15 | "repository": [ 16 | "github:bazelbuild/rules_webtesting" 17 | ], 18 | "versions": [], 19 | "yanked_versions": {} 20 | } -------------------------------------------------------------------------------- /.bcr/presubmit.yml: -------------------------------------------------------------------------------- 1 | bcr_test_module: 2 | module_path: "" 3 | matrix: 4 | bazel: [ 7.x, 8.x ] 5 | tasks: 6 | web_testing_ubuntu2004: 7 | name: "rules_webtesting test in ubuntu" 8 | platform: ubuntu2004 9 | bazel: ${{ bazel }} 10 | shell_commands: 11 | - "sh ./.bazelci/setup_ubuntu.sh" 12 | test_flags: 13 | - "--test_tag_filters=-noci,-sauce" 14 | test_targets: 15 | - "//..." 16 | web_testing_macos: 17 | name: "rules_webtesting test in macos" 18 | platform: macos 19 | bazel: ${{ bazel }} 20 | test_flags: 21 | - "--test_tag_filters=-noci,-sauce,-chromium-local,-firefox-local" 22 | build_targets: 23 | - "//..." 24 | test_targets: 25 | - "//..." 26 | web_testing_windows: 27 | name: "rules_webtesting test in windows" 28 | platform: windows 29 | bazel: ${{ bazel }} 30 | build_flags: 31 | - "--enable_runfiles" 32 | build_targets: 33 | - "//..." 34 | test_flags: 35 | - "--test_tag_filters=-noci,-sauce" 36 | - "--enable_runfiles" 37 | test_targets: 38 | - "//..." 39 | - "-//go/webdriver:go_default_test_chromium-local" # cannot find runfile "testdata/" in manifest 40 | - "-//go/webtest:go_default_test_chromium-local" # cannot find runfile "testdata/" in manifest 41 | - "-//go/wtl/proxy/driverhub/quithandler:go_default_test_chromium-local" # cannot find runfile "testdata/" in manifest 42 | - "-//go/wtl/proxy/driverhub/scripttimeout:go_default_test_chromium-local" # cannot find runfile "testdata/" in manifest 43 | -------------------------------------------------------------------------------- /.bcr/source.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "integrity": "", 3 | "strip_prefix": "{REPO}-{VERSION}", 4 | "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_webtesting-{TAG}.tar.gz" 5 | } -------------------------------------------------------------------------------- /.bcr/web_testing_go/metadata.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "homepage": "https://github.com/bazelbuild/rules_webtesting", 3 | "maintainers": [ 4 | { 5 | "name": "Michael Rea", 6 | "email": "mtrea@google.com", 7 | "github": "mtrea" 8 | }, 9 | { 10 | "name": "Yuan Tian", 11 | "email": "mollyibot@google.com", 12 | "github": "mollyibot" 13 | } 14 | ], 15 | "repository": [ 16 | "github:bazelbuild/rules_webtesting" 17 | ], 18 | "versions": [], 19 | "yanked_versions": {} 20 | } -------------------------------------------------------------------------------- /.bcr/web_testing_go/presubmit.yml: -------------------------------------------------------------------------------- 1 | bcr_test_module: 2 | module_path: "" 3 | matrix: 4 | bazel: [ 7.x, 8.x ] 5 | tasks: 6 | # Only run web_testing_go tests on linux but not macos and windows 7 | web_testing_go_ubuntu2004: 8 | name: "rules_web_testing_go in ubuntu" 9 | platform: ubuntu2004 10 | bazel: ${{ bazel }} 11 | shell_commands: 12 | - "sh ./.bazelci/setup_ubuntu.sh" 13 | test_flags: 14 | - "--test_tag_filters=-noci,-sauce" 15 | build_targets: [ "//..." ] 16 | test_targets: [ "//..." ] 17 | 18 | -------------------------------------------------------------------------------- /.bcr/web_testing_go/source.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "integrity": "", 3 | "strip_prefix": "{REPO}-{VERSION}/web_testing_go", 4 | "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_webtesting-{TAG}.tar.gz" 5 | } -------------------------------------------------------------------------------- /.bcr/web_testing_java/metadata.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "homepage": "https://github.com/bazelbuild/rules_webtesting", 3 | "maintainers": [ 4 | { 5 | "name": "Michael Rea", 6 | "email": "mtrea@google.com", 7 | "github": "mtrea" 8 | }, 9 | { 10 | "name": "Yuan Tian", 11 | "email": "mollyibot@google.com", 12 | "github": "mollyibot" 13 | } 14 | ], 15 | "repository": [ 16 | "github:bazelbuild/rules_webtesting" 17 | ], 18 | "versions": [], 19 | "yanked_versions": {} 20 | } -------------------------------------------------------------------------------- /.bcr/web_testing_java/presubmit.yml: -------------------------------------------------------------------------------- 1 | bcr_test_module: 2 | module_path: "" 3 | matrix: 4 | bazel: [ 7.x, 8.x ] 5 | tasks: 6 | web_testing_java_ubuntu2004: 7 | name: "rules_web_testing_java in ubuntu" 8 | platform: ubuntu2004 9 | bazel: ${{ bazel }} 10 | shell_commands: 11 | - "sh ./.bazelci/setup_ubuntu.sh" 12 | test_flags: 13 | - "--test_tag_filters=-noci,-sauce" 14 | build_targets: [ "//..." ] 15 | test_targets: [ "//..." ] 16 | web_testing_java_windows: 17 | name: "rules_web_testing_java in windows" 18 | platform: windows 19 | bazel: ${{ bazel }} 20 | test_flags: 21 | - "--test_tag_filters=-noci,-sauce" 22 | build_targets: [ "//..." ] 23 | test_targets: [ "//..." ] 24 | -------------------------------------------------------------------------------- /.bcr/web_testing_java/source.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "integrity": "", 3 | "strip_prefix": "{REPO}-{VERSION}/web_testing_java", 4 | "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_webtesting-{TAG}.tar.gz" 5 | } -------------------------------------------------------------------------------- /.bcr/web_testing_python/metadata.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "homepage": "https://github.com/bazelbuild/rules_webtesting", 3 | "maintainers": [ 4 | { 5 | "name": "Michael Rea", 6 | "email": "mtrea@google.com", 7 | "github": "mtrea" 8 | }, 9 | { 10 | "name": "Yuan Tian", 11 | "email": "mollyibot@google.com", 12 | "github": "mollyibot" 13 | } 14 | ], 15 | "repository": [ 16 | "github:bazelbuild/rules_webtesting" 17 | ], 18 | "versions": [], 19 | "yanked_versions": {} 20 | } -------------------------------------------------------------------------------- /.bcr/web_testing_python/presubmit.yml: -------------------------------------------------------------------------------- 1 | bcr_test_module: 2 | module_path: "" 3 | matrix: 4 | bazel: [ 7.x, 8.x ] 5 | tasks: 6 | web_testing_python_ubuntu2004: 7 | name: "rules_web_testing_python in ubuntu" 8 | platform: ubuntu2004 9 | bazel: ${{ bazel }} 10 | shell_commands: 11 | - "sh ./.bazelci/setup_ubuntu.sh" 12 | test_flags: 13 | - "--test_tag_filters=-noci,-sauce" 14 | build_targets: [ "//..." ] 15 | test_targets: [ "//..." ] 16 | web_testing_python_windows: 17 | name: "rules_web_testing_python in windows" 18 | platform: windows 19 | bazel: ${{ bazel }} 20 | test_flags: 21 | - "--test_tag_filters=-noci,-sauce" 22 | build_targets: [ "//..." ] 23 | test_targets: [ "//..." ] -------------------------------------------------------------------------------- /.bcr/web_testing_python/source.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "integrity": "", 3 | "strip_prefix": "{REPO}-{VERSION}/web_testing_python", 4 | "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_webtesting-{TAG}.tar.gz" 5 | } -------------------------------------------------------------------------------- /.bcr/web_testing_scala/metadata.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "homepage": "https://github.com/bazelbuild/rules_webtesting", 3 | "maintainers": [ 4 | { 5 | "name": "Michael Rea", 6 | "email": "mtrea@google.com", 7 | "github": "mtrea" 8 | }, 9 | { 10 | "name": "Yuan Tian", 11 | "email": "mollyibot@google.com", 12 | "github": "mollyibot" 13 | } 14 | ], 15 | "repository": [ 16 | "github:bazelbuild/rules_webtesting" 17 | ], 18 | "versions": [], 19 | "yanked_versions": {} 20 | } -------------------------------------------------------------------------------- /.bcr/web_testing_scala/presubmit.yml: -------------------------------------------------------------------------------- 1 | bcr_test_module: 2 | module_path: "" 3 | matrix: 4 | bazel: [7.x, 8.x] 5 | tasks: 6 | web_testing_scala_ubuntu2004: 7 | name: "rules_web_testing_scala in ubuntu" 8 | platform: ubuntu2004 9 | bazel: ${{ bazel }} 10 | shell_commands: 11 | - "sh ./.bazelci/setup_ubuntu.sh" 12 | test_flags: 13 | - "--test_tag_filters=-noci,-sauce" 14 | build_targets: [ "//..." ] 15 | test_targets: [ "//..." ] 16 | web_testing_scala_windows: 17 | name: "rules_web_testing_scala in windows" 18 | platform: windows 19 | bazel: ${{ bazel }} 20 | test_flags: 21 | - "--test_tag_filters=-noci,-sauce" 22 | build_targets: [ "//..." ] 23 | test_targets: [ "//..." ] 24 | -------------------------------------------------------------------------------- /.bcr/web_testing_scala/source.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "integrity": "", 3 | "strip_prefix": "{REPO}-{VERSION}/web_testing_scala", 4 | "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_webtesting-{TAG}.tar.gz" 5 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bazel-* 2 | *~ 3 | *.sublime-* 4 | *.pyc 5 | .vs/* 6 | user.bazelrc 7 | MODULE.bazel.lock 8 | 9 | .idea/ 10 | dist/ 11 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This the official list of Bazel authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | 5 | # Names should be added to this file as: 6 | # Name or Organization 7 | # The email address is not required for organizations. 8 | Google Inc. -------------------------------------------------------------------------------- /BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@bazel_gazelle//:def.bzl", "gazelle") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | exports_files(["LICENSE"]) 22 | 23 | gazelle( 24 | name = "gazelle", 25 | prefix = "github.com/bazelbuild/rules_webtesting", 26 | ) 27 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @DrMarcII 2 | -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | Want to contribute? Great! First, read this page (including the small print at the end). 2 | 3 | ### Before you contribute 4 | Before we can use your code, you must sign the 5 | [Google Individual Contributor License Agreement] 6 | (https://cla.developers.google.com/about/google-individual) 7 | (CLA), which you can do online. The CLA is necessary mainly because you own the 8 | copyright to your changes, even after your contribution becomes part of our 9 | codebase, so we need your permission to use and distribute your code. We also 10 | need to be sure of various other things—for instance that you'll tell us if you 11 | know that your code infringes on other people's patents. You don't have to sign 12 | the CLA until after you've submitted your code for review and a member has 13 | approved it, but you must do it before we can put your code into our codebase. 14 | Before you start working on a larger contribution, you should get in touch with 15 | us first through the issue tracker with your idea so that we can help out and 16 | possibly guide you. Coordinating up front makes it much easier to avoid 17 | frustration later on. 18 | 19 | ### Code reviews 20 | All submissions, including submissions by project members, require review. We 21 | use Github pull requests for this purpose. 22 | 23 | ### The small print 24 | Contributions made by corporations are covered by a different agreement than 25 | the one above, the 26 | [Software Grant and Corporate Contributor License Agreement] 27 | (https://cla.developers.google.com/about/google-corporate). 28 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # People who have agreed to one of the CLAs and can contribute patches. 2 | # The AUTHORS file lists the copyright holders; this file 3 | # lists people. For example, Google employees are listed here 4 | # but not in AUTHORS, because Google holds the copyright. 5 | # 6 | # https://developers.google.com/open-source/cla/individual 7 | # https://developers.google.com/open-source/cla/corporate 8 | # 9 | # Names should be added to this file as: 10 | # Name 11 | 12 | Marc Fisher -------------------------------------------------------------------------------- /MODULE.bazel: -------------------------------------------------------------------------------- 1 | module( 2 | name = "rules_webtesting", 3 | version = "0.4.0", 4 | ) 5 | 6 | bazel_dep(name = "bazel_skylib", version = "1.7.1") 7 | 8 | bazel_dep(name = "platforms", version = "0.0.10") 9 | 10 | bazel_dep(name = "rules_shell", version = "0.4.0") 11 | 12 | ##### Go dependencies ##### 13 | bazel_dep(name = "rules_go", version = "0.51.0-rc1", repo_name = "io_bazel_rules_go") 14 | 15 | bazel_dep(name = "gazelle", version = "0.40.0", repo_name = "bazel_gazelle") 16 | 17 | go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps") 18 | 19 | go_deps.from_file(go_mod = "//:go.mod") 20 | 21 | # All *direct* Go dependencies of the module have to be listed explicitly. 22 | use_repo(go_deps, "com_github_gorilla_mux", "com_github_tebeka_selenium") 23 | 24 | ##### Browsers dependencies ##### 25 | browser_repositories = use_extension("//web:extension.bzl", "browser_repositories_extension") 26 | 27 | browser_repositories.install(version = "0.3.4") 28 | 29 | use_repo( 30 | browser_repositories, 31 | "com_saucelabs_sauce_connect_linux_x64", 32 | "com_saucelabs_sauce_connect_macos_x64", 33 | "com_saucelabs_sauce_connect_windows_x64", 34 | "org_chromium_chromedriver_linux_x64", 35 | "org_chromium_chromedriver_macos_arm64", 36 | "org_chromium_chromedriver_macos_x64", 37 | "org_chromium_chromedriver_windows_x64", 38 | "org_chromium_chromium_linux_x64", 39 | "org_chromium_chromium_macos_arm64", # Only available in 0.3.3 40 | "org_chromium_chromium_macos_x64", 41 | "org_chromium_chromium_windows_x64", 42 | "org_mozilla_firefox_linux_x64", 43 | "org_mozilla_firefox_macos_arm64", 44 | "org_mozilla_firefox_macos_x64", 45 | "org_mozilla_geckodriver_linux_x64", 46 | "org_mozilla_geckodriver_macos_arm64", 47 | "org_mozilla_geckodriver_macos_x64", 48 | ) 49 | -------------------------------------------------------------------------------- /browsers/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//web:web.bzl", "browser", "custom_browser") 18 | 19 | package( 20 | default_testonly = True, 21 | default_visibility = ["//visibility:public"], 22 | ) 23 | 24 | licenses(["notice"]) # Apache 2.0 25 | 26 | browser( 27 | name = "firefox-external", 28 | execution_requirements = {"requires-network": ""}, 29 | metadata = "firefox-external.json", 30 | required_tags = [ 31 | "external", 32 | ], 33 | ) 34 | 35 | browser( 36 | name = "chrome-external", 37 | execution_requirements = {"requires-network": ""}, 38 | metadata = "chrome-external.json", 39 | required_tags = [ 40 | "external", 41 | ], 42 | ) 43 | 44 | browser( 45 | name = "disabled", 46 | disabled = "disabled pseudo-browser", 47 | metadata = "disabled.json", 48 | ) 49 | 50 | browser( 51 | name = "chromium-local", 52 | metadata = "chromium-local.json", 53 | required_tags = [ 54 | "native", 55 | ], 56 | deps = [ 57 | "//go/wsl", 58 | "//third_party/chromedriver", 59 | "//third_party/chromium", 60 | ], 61 | ) 62 | 63 | browser( 64 | name = "firefox-local", 65 | disabled = select({ 66 | "//common/conditions:windows_x64": "firefox not supported on windows", 67 | "//conditions:default": None, 68 | }), 69 | metadata = "firefox-local.json", 70 | required_tags = [ 71 | "native", 72 | ], 73 | deps = select({ 74 | "//common/conditions:windows_x64": [], 75 | "//conditions:default": [ 76 | "//go/wsl", 77 | "//third_party/firefox", 78 | "//third_party/geckodriver", 79 | ], 80 | }), 81 | ) 82 | 83 | custom_browser( 84 | name = "chromium-local-1024x768", 85 | browser = ":chromium-local", 86 | metadata = "size.json", 87 | ) 88 | -------------------------------------------------------------------------------- /browsers/chrome-external.json: -------------------------------------------------------------------------------- 1 | { 2 | "environment": "external", 3 | "capabilities": {"browserName": "chrome"} 4 | } 5 | -------------------------------------------------------------------------------- /browsers/chromium-local.json: -------------------------------------------------------------------------------- 1 | { 2 | "environment" : "local", 3 | "capabilities" : { 4 | "browserName" : "chrome", 5 | "goog:chromeOptions" : { 6 | "binary" : "%FILE:CHROMIUM%", 7 | "args" : [ 8 | "--headless", 9 | "--no-sandbox", 10 | "--use-gl=swiftshader-webgl" 11 | ] 12 | }, 13 | "google:wslConfig": { 14 | "binary": "%FILE:CHROMEDRIVER%", 15 | "port":"%WSLPORT:WSL%", 16 | "args": ["--port=%WSLPORT:WSL%"], 17 | "status": true, 18 | "shutdown": true 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /browsers/disabled.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /browsers/firefox-external.json: -------------------------------------------------------------------------------- 1 | { 2 | "environment": "external", 3 | "capabilities": {"browserName": "firefox"} 4 | } 5 | -------------------------------------------------------------------------------- /browsers/firefox-local.json: -------------------------------------------------------------------------------- 1 | { 2 | "environment": "local", 3 | "capabilities": { 4 | "browserName": "firefox", 5 | "moz:firefoxOptions": { 6 | "binary": "%FILE:FIREFOX%", 7 | "args": ["--headless"] 8 | }, 9 | "google:wslConfig": { 10 | "binary": "%FILE:GECKODRIVER%", 11 | "port":"%WSLPORT:WSL%", 12 | "args": [ 13 | "--port=%WSLPORT:WSL%", 14 | "--host=%WSL:HOST_IP%", 15 | "--marionette-port=%WSLPORT:MARIONETTE%" 16 | ], 17 | "env": { 18 | "HOME": "%ENV:TEST_TMPDIR%" 19 | }, 20 | "status": true, 21 | "shutdown": false 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /browsers/sauce/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//web:web.bzl", "browser") 18 | 19 | package( 20 | default_testonly = True, 21 | default_visibility = ["//visibility:public"], 22 | ) 23 | 24 | licenses(["notice"]) # Apache 2.0 25 | 26 | browser( 27 | name = "chrome-win10", 28 | execution_requirements = {"requires-network": ""}, 29 | metadata = "chrome-win10.json", 30 | required_tags = [ 31 | "sauce", 32 | "exclusive", 33 | ], 34 | ) 35 | 36 | browser( 37 | name = "chrome-win10-connect", 38 | execution_requirements = {"requires-network": ""}, 39 | metadata = "chrome-win10-connect.json", 40 | required_tags = [ 41 | "sauce", 42 | "exclusive", 43 | "noci", 44 | ], 45 | deps = ["//third_party/sauceconnect"], 46 | ) 47 | -------------------------------------------------------------------------------- /browsers/sauce/chrome-win10-connect.json: -------------------------------------------------------------------------------- 1 | { 2 | "environment": "sauce", 3 | "capabilities": { 4 | "browserName": "chrome", 5 | "platform": "Windows 10", 6 | "version": "76.0", 7 | "name": "%METADATA:LABEL%", 8 | "tags": ["%METADATA:ENVIRONMENT%", "%METADATA:TEST_LABEL%", "%METADATA:BROWSER_LABEL%", "%METADATA:CONFIG_LABEL%"], 9 | "tunnel-identifier": "%SAUCE:TUNNEL_ID%" 10 | }, 11 | "extension": { 12 | "sauceOptions": { 13 | "username": "bazel_rules_webtesting", 14 | "accessKey": "c5bed09c-a8a6-44c8-af02-a545905f957f", 15 | "tunnelId": "local-%d", 16 | "startConnect": true 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /browsers/sauce/chrome-win10.json: -------------------------------------------------------------------------------- 1 | { 2 | "environment": "sauce", 3 | "capabilities": { 4 | "browserName": "chrome", 5 | "platform": "Windows 10", 6 | "version": "76.0", 7 | "name": "%METADATA:LABEL%", 8 | "build": "%ENV:BUILD_TAG%", 9 | "tags": ["%METADATA:ENVIRONMENT%", "%METADATA:TEST_LABEL%", "%METADATA:BROWSER_LABEL%", "%METADATA:CONFIG_LABEL%"], 10 | "tunnel-identifier": "%SAUCE:TUNNEL_ID%" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /browsers/size.json: -------------------------------------------------------------------------------- 1 | { 2 | "capabilities": { 3 | "goog:chromeOptions": { 4 | "args": ["--window-size=1024,768"] 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /build_files/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | licenses(["notice"]) # Apache 2.0 18 | 19 | exports_files(glob(["BUILD.*"])) 20 | -------------------------------------------------------------------------------- /build_files/metadata.BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//web/internal:executable_name.bzl", "get_platform_executable_name") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | alias( 22 | name = "main", 23 | actual = get_platform_executable_name(), 24 | visibility = ["//visibility:public"], 25 | testonly = True, 26 | ) 27 | -------------------------------------------------------------------------------- /build_files/wsl.BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//web:web.bzl", "web_test_named_executable") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | web_test_named_executable( 22 | name = "wsl", 23 | testonly = True, 24 | alt_name = "WEBDRIVER_SERVER_LIGHT", 25 | executable = "//go/wsl/main", 26 | visibility = ["//visibility:public"], 27 | ) -------------------------------------------------------------------------------- /build_files/wsl_main.BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//web/internal:executable_name.bzl", "get_platform_executable_name") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | alias( 22 | name = "main", 23 | actual = get_platform_executable_name(), 24 | visibility = ["//visibility:public"], 25 | testonly = True, 26 | ) 27 | -------------------------------------------------------------------------------- /build_files/wtl.BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//web/internal:executable_name.bzl", "get_platform_executable_name") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | alias( 22 | name = "main", 23 | actual = get_platform_executable_name(), 24 | visibility = ["//visibility:public"], 25 | testonly = True, 26 | ) 27 | -------------------------------------------------------------------------------- /common/conditions/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | package( 18 | default_visibility = ["//:__subpackages__"], 19 | ) 20 | 21 | config_setting( 22 | name = "linux_x64", 23 | constraint_values = [ 24 | "@platforms//os:linux", 25 | "@platforms//cpu:x86_64", 26 | ], 27 | ) 28 | 29 | config_setting( 30 | name = "macos_x64", 31 | constraint_values = [ 32 | "@platforms//os:macos", 33 | "@platforms//cpu:x86_64", 34 | ], 35 | ) 36 | 37 | config_setting( 38 | name = "macos_arm64", 39 | constraint_values = [ 40 | "@platforms//os:macos", 41 | "@platforms//cpu:aarch64", 42 | ], 43 | ) 44 | 45 | config_setting( 46 | name = "windows_x64", 47 | constraint_values = [ 48 | "@platforms//os:windows", 49 | "@platforms//cpu:x86_64", 50 | ], 51 | ) 52 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/bazelbuild/rules_webtesting 2 | 3 | go 1.17 4 | 5 | require ( 6 | github.com/gorilla/mux v1.8.1 7 | github.com/tebeka/selenium v0.9.9 8 | ) 9 | 10 | require github.com/blang/semver v3.5.1+incompatible // indirect 11 | -------------------------------------------------------------------------------- /go/bazel/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["bazel.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/bazel", 25 | visibility = ["//visibility:public"], 26 | deps = ["//go/cmdhelper:go_default_library"], 27 | ) 28 | -------------------------------------------------------------------------------- /go/cmdhelper/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["cmd_helper.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/cmdhelper", 25 | visibility = ["//go:__subpackages__"], 26 | ) 27 | -------------------------------------------------------------------------------- /go/cmdhelper/cmd_helper.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package cmdhelper provides functions to make working os/exec Command easier. 16 | package cmdhelper 17 | 18 | import ( 19 | "os" 20 | "strings" 21 | ) 22 | 23 | // UpdateEnv takes an environment array, an env var name, and an environment 24 | // var value and updates the current definition of the env var or adds a new 25 | // environment variable definition. 26 | func UpdateEnv(env []string, name, value string) []string { 27 | prefix := name + "=" 28 | 29 | for i := 0; i < len(env); { 30 | if strings.HasPrefix(env[i], prefix) { 31 | env = append(env[:i], env[i+1:]...) 32 | } else { 33 | i++ 34 | } 35 | } 36 | 37 | return append(env, prefix+value) 38 | } 39 | 40 | // BulkUpdateEnv returns a new slice suitable for use with exec.Cmd.Env 41 | // based on env but with environment variables for the keys in update 42 | // added/changed to the values in update. 43 | func BulkUpdateEnv(env []string, update map[string]string) []string { 44 | for name, value := range update { 45 | env = UpdateEnv(env, name, value) 46 | } 47 | return env 48 | } 49 | 50 | // IsTruthyEnv return true if name is set in the environment and has value other than 51 | // 0 or false (case-insensitive). 52 | func IsTruthyEnv(name string) bool { 53 | value := os.Getenv(name) 54 | return value != "" && value != "0" && strings.ToLower(value) != "false" 55 | } 56 | -------------------------------------------------------------------------------- /go/errors/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["errors.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/errors", 25 | visibility = ["//go:__subpackages__"], 26 | ) 27 | 28 | go_test( 29 | name = "go_default_test", 30 | srcs = ["errors_test.go"], 31 | embed = [":go_default_library"], 32 | ) 33 | -------------------------------------------------------------------------------- /go/errors/errors_test.go: -------------------------------------------------------------------------------- 1 | /// Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package errors 16 | 17 | import ( 18 | "errors" 19 | "fmt" 20 | "strings" 21 | "testing" 22 | ) 23 | 24 | func TestNewFromString(t *testing.T) { 25 | fromString := New("fromString", "error") 26 | if Component(fromString) != "fromString" { 27 | t.Errorf(`expected Component(fromString) == "fromString", got %s`, Component(fromString)) 28 | } 29 | if !strings.Contains(fromString.Error(), "error") { 30 | t.Errorf(`expected fromString.Error() contains "error", got %s`, fromString.Error()) 31 | } 32 | 33 | err := errors.New("error") 34 | fromError := New("fromError", err) 35 | if Component(fromError) != "fromError" { 36 | t.Errorf(`expected Component(fromError) == "fromError", got %s`, Component(fromError)) 37 | } 38 | if !strings.Contains(fromError.Error(), "error") { 39 | t.Errorf(`got %v, expected fromError.Error() contains "error"`, fromError.Error()) 40 | } 41 | 42 | if sameComp := New("fromString", fromString); sameComp != fromString { 43 | t.Errorf("expected sameComp == %+v, got %+v", fromString, sameComp) 44 | } 45 | 46 | if newComp := New("newComp", fromString); newComp != fromString { 47 | t.Errorf("expected newComp == %+v, got %+v", fromString, newComp) 48 | } 49 | } 50 | 51 | func TestJoinErrors(t *testing.T) { 52 | testCases := []struct { 53 | name string 54 | input []error 55 | want string 56 | }{ 57 | { 58 | name: "one error", 59 | input: []error{fmt.Errorf("error1")}, 60 | want: "error1", 61 | }, 62 | { 63 | name: "two errors", 64 | input: []error{fmt.Errorf("error1"), fmt.Errorf("error2")}, 65 | want: "errors:\n\terror1\n\terror2", 66 | }, 67 | { 68 | name: "nil and error", 69 | input: []error{nil, fmt.Errorf("error1")}, 70 | want: "error1", 71 | }, 72 | } 73 | 74 | for _, tc := range testCases { 75 | t.Run(tc.name, func(t *testing.T) { 76 | got := JoinErrs(tc.input...).Error() 77 | if got != tc.want { 78 | t.Errorf("got:\n%#v\n\nwant:\n%#v", got, tc.want) 79 | } 80 | }) 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /go/healthreporter/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["health_reporter.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/healthreporter", 25 | visibility = ["//go:__subpackages__"], 26 | deps = ["//go/errors:go_default_library"], 27 | ) 28 | 29 | go_test( 30 | name = "go_default_test", 31 | srcs = ["health_reporter_test.go"], 32 | embed = [":go_default_library"], 33 | deps = ["//go/errors:go_default_library"], 34 | ) 35 | -------------------------------------------------------------------------------- /go/healthreporter/health_reporter.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package healthreporter provides polling wait functions. 16 | package healthreporter 17 | 18 | import ( 19 | "context" 20 | "fmt" 21 | "log" 22 | "time" 23 | 24 | "github.com/bazelbuild/rules_webtesting/go/errors" 25 | ) 26 | 27 | const ( 28 | pollMin = 50 * time.Millisecond 29 | pollMax = time.Second 30 | pollDefault = pollMin 31 | pollCount = 20 32 | ) 33 | 34 | // A HealthReporter knows its name and can check if it is healthy. 35 | type HealthReporter interface { 36 | // Component is the name used in errors. 37 | Name() string 38 | // Healthy returns nil if this is healthy, and an Error describing the problem if not healthy. 39 | // Healthy should respect Context's Done. 40 | Healthy(context.Context) error 41 | } 42 | 43 | // WaitForHealthy waits until ctx is Done or h is Healthy, returning an error 44 | // if h does not become healthy. 45 | func WaitForHealthy(ctx context.Context, h HealthReporter) error { 46 | poll := pollDefault 47 | if deadline, ok := ctx.Deadline(); ok { 48 | poll = deadline.Sub(time.Now()) / pollCount 49 | if poll < pollMin { 50 | poll = pollMin 51 | } 52 | if poll > pollMax { 53 | poll = pollMax 54 | } 55 | } else { 56 | log.Printf("%s WaitForHealthy being called without deadline; will potentially wait forever.", h.Name()) 57 | } 58 | 59 | ticker := time.NewTicker(poll) 60 | defer ticker.Stop() 61 | 62 | for { 63 | err := h.Healthy(ctx) 64 | if err == nil { 65 | return nil 66 | } 67 | if errors.IsPermanent(err) { 68 | return err 69 | } 70 | comp := errors.Component(err) 71 | if comp == errors.DefaultComp { 72 | comp = h.Name() 73 | } 74 | select { 75 | case <-ctx.Done(): 76 | return errors.New(comp, fmt.Errorf("%v waiting for healthy: %v", ctx.Err(), err)) 77 | case <-ticker.C: 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /go/healthreporter/health_reporter_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package healthreporter 16 | 17 | import ( 18 | "context" 19 | "strings" 20 | "testing" 21 | "time" 22 | 23 | "github.com/bazelbuild/rules_webtesting/go/errors" 24 | ) 25 | 26 | func TestWaitForHealthyTimeout(t *testing.T) { 27 | failing := &fakeHealthReporter{errors.New("fake", "error")} 28 | 29 | ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) 30 | defer cancel() 31 | err := WaitForHealthy(ctx, failing) 32 | if err == nil { 33 | t.Fatal("expected err to be non-nil") 34 | } 35 | if !strings.Contains(err.Error(), ctx.Err().Error()) { 36 | t.Errorf(`expected err to contain "%s", but got %s`, ctx.Err().Error(), err.Error()) 37 | } 38 | if !strings.Contains(err.Error(), failing.health.Error()) { 39 | t.Errorf(`expected err to contain "%s", but got %s`, failing.health.Error(), err.Error()) 40 | } 41 | if errors.Component(err) != "fake" { 42 | t.Errorf(`expected err.Component to be "%s", but got %s`, "fake", errors.Component(err)) 43 | } 44 | } 45 | 46 | func TestWaitForHealthyCancelled(t *testing.T) { 47 | failing := &fakeHealthReporter{errors.New("fake", "error")} 48 | 49 | ctx, cancel := context.WithCancel(context.Background()) 50 | cancel() 51 | err := WaitForHealthy(ctx, failing) 52 | if err == nil { 53 | t.Fatal("expected err to be non-nil") 54 | } 55 | if !strings.Contains(err.Error(), ctx.Err().Error()) { 56 | t.Errorf(`expected err to contain "%s", but got %s`, ctx.Err().Error(), err.Error()) 57 | } 58 | if errors.Component(err) != "fake" { 59 | t.Errorf(`expected err.Component to be "%s", but got %s`, "fake", errors.Component(err)) 60 | } 61 | } 62 | 63 | func TestWaitForHealthySuccess(t *testing.T) { 64 | successful := &fakeHealthReporter{} 65 | 66 | err := WaitForHealthy(context.Background(), successful) 67 | if err != nil { 68 | t.Fatalf("expected err to be nil, but got %v", err) 69 | } 70 | } 71 | 72 | type fakeHealthReporter struct { 73 | health error 74 | } 75 | 76 | func (f *fakeHealthReporter) Name() string { 77 | return "fakeHealthReporter" 78 | } 79 | 80 | func (f *fakeHealthReporter) Healthy(context.Context) error { 81 | return f.health 82 | } 83 | -------------------------------------------------------------------------------- /go/httphelper/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["http_helper.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/httphelper", 25 | visibility = ["//go:__subpackages__"], 26 | ) 27 | 28 | go_test( 29 | name = "go_default_test", 30 | srcs = ["http_helper_test.go"], 31 | embed = [":go_default_library"], 32 | ) 33 | -------------------------------------------------------------------------------- /go/httphelper/http_helper_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package httphelper 16 | 17 | import ( 18 | "os" 19 | "strings" 20 | "testing" 21 | ) 22 | 23 | func TestFQDN(t *testing.T) { 24 | fqdn, err := FQDN() 25 | 26 | if err != nil { 27 | t.Error(err) 28 | } 29 | 30 | name, _ := os.Hostname() 31 | name = strings.ToLower(name) 32 | 33 | if !strings.HasPrefix(fqdn, name) && fqdn != "localhost" { 34 | t.Errorf("Got %q, expected localhost or to start with %q", fqdn, name) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /go/metadata/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = [ 24 | "metadata.go", 25 | "web_test_files.go", 26 | ], 27 | importpath = "github.com/bazelbuild/rules_webtesting/go/metadata", 28 | visibility = ["//visibility:public"], 29 | deps = [ 30 | "//go/bazel:go_default_library", 31 | "//go/httphelper:go_default_library", 32 | "//go/metadata/capabilities:go_default_library", 33 | ], 34 | ) 35 | 36 | go_test( 37 | name = "go_default_test", 38 | srcs = [ 39 | "extension_test.go", 40 | "metadata_test.go", 41 | ], 42 | data = ["//testdata"], 43 | embed = [":go_default_library"], 44 | deps = ["@rules_webtesting//go/bazel:go_default_library"], 45 | ) 46 | -------------------------------------------------------------------------------- /go/metadata/capabilities/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["capabilities.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/metadata/capabilities", 25 | visibility = ["//go:__subpackages__"], 26 | ) 27 | 28 | go_test( 29 | name = "go_default_test", 30 | srcs = ["capabilities_test.go"], 31 | embed = [":go_default_library"], 32 | ) 33 | -------------------------------------------------------------------------------- /go/metadata/main/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") 18 | load("@rules_shell//shell:sh_test.bzl", "sh_test") 19 | load("//web/internal:executable_name.bzl", "get_platform_executable_name") 20 | 21 | licenses(["notice"]) # Apache 2.0 22 | 23 | go_library( 24 | name = "go_default_library", 25 | srcs = ["merger.go"], 26 | importpath = "github.com/bazelbuild/rules_webtesting/go/metadata/main", 27 | visibility = ["//go:__subpackages__"], 28 | deps = ["//go/metadata:go_default_library"], 29 | ) 30 | 31 | go_binary( 32 | name = "main", 33 | testonly = True, 34 | embed = [":go_default_library"], 35 | visibility = ["//visibility:public"], 36 | out = get_platform_executable_name(), 37 | ) 38 | 39 | sh_test( 40 | name = "merger_test", 41 | srcs = ["merger_test.sh"], 42 | data = [ 43 | "@bazel_tools//tools/bash/runfiles", 44 | "//testdata", 45 | ":main", 46 | ], 47 | # Pass the executable path so that the test can resolve the merger 48 | # entry-point in a platform-agnostic way. 49 | args = ["$(rootpath :main)"], 50 | tags = ["noci"], 51 | 52 | ) 53 | -------------------------------------------------------------------------------- /go/metadata/main/merger.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Binary merger takes multiple metadata files and merges them to produce a single 16 | // metadata file. 17 | package main 18 | 19 | import ( 20 | "flag" 21 | "log" 22 | 23 | "github.com/bazelbuild/rules_webtesting/go/metadata" 24 | ) 25 | 26 | var output = flag.String("output", "", "output file for generated metadata") 27 | 28 | func main() { 29 | flag.Parse() 30 | 31 | data := &metadata.Metadata{} 32 | 33 | for _, file := range flag.Args() { 34 | m, err := metadata.FromFile(file, nil) 35 | if err != nil { 36 | log.Fatalf("Error reading %q: %v", file, err) 37 | } 38 | data, err = metadata.Merge(data, m) 39 | if err != nil { 40 | log.Fatalf("Error merging file %q: %v", file, err) 41 | } 42 | } 43 | 44 | if err := data.ToFile(*output); err != nil { 45 | log.Fatalf("Error writing %s: %v", *output, err) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /go/portpicker/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["port_picker.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/portpicker", 25 | visibility = ["//go:__subpackages__"], 26 | ) 27 | -------------------------------------------------------------------------------- /go/portpicker/port_picker.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package portpicker provides methods for picking unused TCP ports. 16 | package portpicker 17 | 18 | import ( 19 | "errors" 20 | "io" 21 | "net" 22 | "strconv" 23 | "sync" 24 | ) 25 | 26 | var ( 27 | mu sync.Mutex 28 | claimedPorts = map[int]bool{} 29 | ) 30 | 31 | // PickUnusedPort picks an unused TCP port. 32 | func PickUnusedPort() (int, error) { 33 | mu.Lock() 34 | defer mu.Unlock() 35 | var listeners []io.Closer 36 | defer func() { 37 | for _, c := range listeners { 38 | c.Close() 39 | } 40 | }() 41 | 42 | for i := 0; i <= len(claimedPorts); i++ { 43 | l, err := net.Listen("tcp", ":0") 44 | if err != nil { 45 | return 0, err 46 | } 47 | listeners = append(listeners, l) 48 | 49 | _, p, err := net.SplitHostPort(l.Addr().String()) 50 | if err != nil { 51 | return 0, err 52 | } 53 | 54 | port, err := strconv.Atoi(p) 55 | if err != nil { 56 | return 0, err 57 | } 58 | 59 | if !claimedPorts[port] { 60 | claimedPorts[port] = true 61 | return port, nil 62 | } 63 | } 64 | return 0, errors.New("unable to get a port") 65 | } 66 | 67 | // RecycleUnusedPort makes a port claimable by a call to PickUnusedPort. 68 | func RecycleUnusedPort(port int) error { 69 | mu.Lock() 70 | defer mu.Unlock() 71 | delete(claimedPorts, port) 72 | return nil 73 | } 74 | -------------------------------------------------------------------------------- /go/web/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 18 | load("@rules_webtesting//web:web.bzl", "web_test_config") 19 | 20 | package( 21 | default_testonly = True, 22 | default_visibility = ["//go:__subpackages__"], 23 | ) 24 | 25 | bzl_library( 26 | name = "go", 27 | srcs = ["go.bzl"], 28 | deps = [ 29 | "@rules_webtesting//web/internal:wrap_web_test_suite", 30 | # should depend on @io_bazel_rules_go//go:def.bzl 31 | ], 32 | ) 33 | -------------------------------------------------------------------------------- /go/web/go.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Web Test rules for Go.""" 15 | 16 | load("@io_bazel_rules_go//go:def.bzl", "go_test") 17 | load("@rules_webtesting//web/internal:constants.bzl", "DEFAULT_WRAPPED_TEST_TAGS") 18 | load("@rules_webtesting//web/internal:wrap_web_test_suite.bzl", "wrap_web_test_suite") 19 | 20 | def go_web_test_suite(name, go_test_tags = DEFAULT_WRAPPED_TEST_TAGS, **kwargs): 21 | """Defines a test_suite of web_test targets that wrap a go_test target. 22 | 23 | Args: 24 | name: The base name of the test. 25 | go_test_tags: A list of test tag strings to use for the go_test target. 26 | **kwargs: Arguments for wrapped_web_test_suite 27 | """ 28 | wrap_web_test_suite( 29 | name = name, 30 | rule = go_test, 31 | wrapped_test_tags = go_test_tags, 32 | **kwargs 33 | ) 34 | -------------------------------------------------------------------------------- /go/webdriver/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//go/web:go.bzl", "go_web_test_suite") 18 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 19 | 20 | licenses(["notice"]) # Apache 2.0 21 | 22 | go_library( 23 | name = "go_default_library", 24 | srcs = [ 25 | "webdriver.go", 26 | "webdriver_error.go", 27 | ], 28 | importpath = "github.com/bazelbuild/rules_webtesting/go/webdriver", 29 | visibility = ["//go:__subpackages__"], 30 | deps = [ 31 | "//go/bazel:go_default_library", 32 | "//go/errors:go_default_library", 33 | "//go/healthreporter:go_default_library", 34 | "//go/metadata/capabilities:go_default_library", 35 | "//go/portpicker:go_default_library", 36 | ], 37 | ) 38 | 39 | go_web_test_suite( 40 | name = "go_default_test", 41 | srcs = ["webdriver_test.go"], 42 | browsers = [ 43 | "//browsers:chromium-local", 44 | "//browsers:firefox-local", 45 | "//browsers/sauce:chrome-win10", 46 | "//browsers/sauce:chrome-win10-connect", 47 | ], 48 | data = ["//testdata"], 49 | embed = [":go_default_library"], 50 | deps = ["//go/webtest:go_default_library"], 51 | ) 52 | -------------------------------------------------------------------------------- /go/webtest/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//go/web:go.bzl", "go_web_test_suite") 18 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 19 | 20 | licenses(["notice"]) # Apache 2.0 21 | 22 | go_library( 23 | name = "go_default_library", 24 | srcs = ["webtest.go"], 25 | importpath = "github.com/bazelbuild/rules_webtesting/go/webtest", 26 | visibility = ["//visibility:public"], 27 | deps = [ 28 | "//go/bazel:go_default_library", 29 | "//go/metadata:go_default_library", 30 | "@com_github_tebeka_selenium//:go_default_library", 31 | ], 32 | ) 33 | 34 | go_web_test_suite( 35 | name = "go_default_test", 36 | srcs = [ 37 | "browserinfo_test.go", 38 | "webtest_test.go", 39 | ], 40 | browsers = [ 41 | "//browsers:chromium-local", 42 | "//browsers:firefox-local", 43 | "//browsers/sauce:chrome-win10", 44 | "//browsers/sauce:chrome-win10-connect", 45 | ], 46 | data = ["//testdata"], 47 | embed = [":go_default_library"], 48 | deps = ["@com_github_tebeka_selenium//:go_default_library"], 49 | ) 50 | -------------------------------------------------------------------------------- /go/webtest/browserinfo_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package webtest 16 | 17 | import "testing" 18 | 19 | func TestBrowserInfo(t *testing.T) { 20 | i, err := newInfo("testdata/all-fields.json") 21 | if err != nil { 22 | t.Fatal(err) 23 | } 24 | if i.BrowserLabel != "//browsers:figaro" { 25 | t.Errorf(`got BrowserLabel = %q, expected "//browsers:figaro"`, i.BrowserLabel) 26 | } 27 | if i.Environment != "chromeos" { 28 | t.Errorf(`got Environment = %q, expected "chromeos"`, i.Environment) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /go/wsl/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//web:web.bzl", "web_test_named_executable") 18 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 19 | 20 | licenses(["notice"]) # Apache 2.0 21 | 22 | web_test_named_executable( 23 | name = "wsl", 24 | testonly = True, 25 | alt_name = "WEBDRIVER_SERVER_LIGHT", 26 | executable = "//go/wsl/main", 27 | visibility = ["//visibility:public"], 28 | ) 29 | 30 | go_library( 31 | name = "go_default_library", 32 | srcs = ["wsl.go"], 33 | importpath = "github.com/bazelbuild/rules_webtesting/go/wsl", 34 | visibility = [":__subpackages__"], 35 | deps = [ 36 | "//go/httphelper:go_default_library", 37 | "//go/wsl/hub:go_default_library", 38 | "//go/wsl/upload:go_default_library", 39 | ], 40 | ) 41 | 42 | go_test( 43 | name = "go_default_test", 44 | srcs = ["wsl_test.go"], 45 | data = ["//testdata"], 46 | embed = [":go_default_library"], 47 | deps = [ 48 | "//go/bazel:go_default_library", 49 | "//go/portpicker:go_default_library", 50 | ], 51 | ) 52 | -------------------------------------------------------------------------------- /go/wsl/driver/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["driver.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/wsl/driver", 25 | visibility = ["//go/wsl:__subpackages__"], 26 | deps = [ 27 | "//go/cmdhelper:go_default_library", 28 | "//go/httphelper:go_default_library", 29 | "//go/metadata/capabilities:go_default_library", 30 | "//go/webdriver:go_default_library", 31 | ], 32 | ) 33 | -------------------------------------------------------------------------------- /go/wsl/hub/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["hub.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/wsl/hub", 25 | visibility = ["//go/wsl:__subpackages__"], 26 | deps = [ 27 | "//go/httphelper:go_default_library", 28 | "//go/metadata/capabilities:go_default_library", 29 | "//go/wsl/driver:go_default_library", 30 | "//go/wsl/resolver:go_default_library", 31 | ], 32 | ) 33 | -------------------------------------------------------------------------------- /go/wsl/main/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") 18 | load("//web/internal:executable_name.bzl", "get_platform_executable_name") 19 | 20 | licenses(["notice"]) # Apache 2.0 21 | 22 | go_library( 23 | name = "go_default_library", 24 | srcs = ["main.go"], 25 | importpath = "github.com/bazelbuild/rules_webtesting/go/wsl/main", 26 | visibility = ["//go/wsl:__subpackages__"], 27 | deps = ["//go/wsl:go_default_library"], 28 | ) 29 | 30 | go_binary( 31 | name = "main", 32 | embed = [":go_default_library"], 33 | visibility = ["//visibility:public"], 34 | out = get_platform_executable_name(), 35 | ) 36 | -------------------------------------------------------------------------------- /go/wsl/main/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // WSL (Webdriver Server Light) is a lightweight replacement for Selenium Server. 16 | package main 17 | 18 | import ( 19 | "flag" 20 | "log" 21 | "os" 22 | 23 | "github.com/bazelbuild/rules_webtesting/go/wsl" 24 | ) 25 | 26 | var ( 27 | port = flag.Int("port", 4444, "Port to start WSL on.") 28 | downloadRoot = flag.String("download_root", "", "Directory served at /google/staticfile/.") 29 | uploadRoot = flag.String("upload_root", "", "Directory to which files sent to /session//upload will be uploaded.") 30 | logFile = flag.String("log_file", "", "File for WSL logs.") 31 | localHost = flag.String("local_host", "localhost", "Name to use for localhost.") 32 | ) 33 | 34 | func main() { 35 | flag.Parse() 36 | 37 | if *logFile != "" { 38 | out, err := os.Create(*logFile) 39 | if err != nil { 40 | log.Fatalf("unable to open log file: %v", err) 41 | } 42 | defer out.Close() 43 | log.SetOutput(out) 44 | } 45 | 46 | log.SetFlags(log.Flags() | log.Lmicroseconds) 47 | wsl.Run(*localHost, *port, *downloadRoot, *uploadRoot) 48 | } 49 | -------------------------------------------------------------------------------- /go/wsl/resolver/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["resolver.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/wsl/resolver", 25 | visibility = ["//visibility:public"], 26 | deps = [ 27 | "//go/metadata/capabilities:go_default_library", 28 | "//go/portpicker:go_default_library", 29 | ], 30 | ) 31 | -------------------------------------------------------------------------------- /go/wsl/upload/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["upload.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/wsl/upload", 25 | visibility = ["//go/wsl:__subpackages__"], 26 | deps = ["//go/httphelper:go_default_library"], 27 | ) 28 | 29 | go_test( 30 | name = "go_default_test", 31 | srcs = ["upload_test.go"], 32 | embed = [":go_default_library"], 33 | deps = ["//go/bazel:go_default_library"], 34 | ) 35 | -------------------------------------------------------------------------------- /go/wtl/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["wtl.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl", 25 | visibility = [":__subpackages__"], 26 | deps = [ 27 | "//go/bazel:go_default_library", 28 | "//go/cmdhelper:go_default_library", 29 | "//go/errors:go_default_library", 30 | "//go/metadata:go_default_library", 31 | "//go/portpicker:go_default_library", 32 | "//go/wtl/diagnostics:go_default_library", 33 | "//go/wtl/environment:go_default_library", 34 | "//go/wtl/environment/external:go_default_library", 35 | "//go/wtl/environment/local:go_default_library", 36 | "//go/wtl/environment/sauce:go_default_library", 37 | "//go/wtl/proxy:go_default_library", 38 | "//go/wtl/proxy/driverhub:go_default_library", 39 | "//go/wtl/proxy/driverhub/drivermu:go_default_library", 40 | "//go/wtl/proxy/driverhub/quithandler:go_default_library", 41 | "//go/wtl/proxy/driverhub/scripttimeout:go_default_library", 42 | "//go/wtl/proxy/healthz:go_default_library", 43 | ], 44 | ) 45 | -------------------------------------------------------------------------------- /go/wtl/diagnostics/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["diagnostics.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/diagnostics", 25 | visibility = ["//go/wtl:__subpackages__"], 26 | deps = ["//go/errors:go_default_library"], 27 | ) 28 | -------------------------------------------------------------------------------- /go/wtl/diagnostics/diagnostics.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package diagnostics provides the Diagnostics interface for reporting various 16 | // test statistics as well as a no-op implementation of the interface. 17 | package diagnostics 18 | 19 | import ( 20 | "log" 21 | "time" 22 | 23 | "github.com/bazelbuild/rules_webtesting/go/errors" 24 | ) 25 | 26 | // Diagnostics manages and outputs a test diagnostics. 27 | type Diagnostics interface { 28 | // Name is the name of the component used in error messages. 29 | Name() string 30 | // Timing reports timing info. 31 | Timing(component, description, detail string, begin, end time.Time) error 32 | // Severe reports an error that is highly likely to cause problems in tests. 33 | Severe(err error) error 34 | // Warning reports a error that is unlikely to cause problems in tests, but 35 | // that you want to track anyway. 36 | Warning(err error) error 37 | // Close closes this diagnostics object. 38 | Close() error 39 | } 40 | 41 | type noOPDiagnostics struct { 42 | closed bool 43 | } 44 | 45 | // NoOP creates a new empty Diagnostics object. 46 | func NoOP() Diagnostics { 47 | return &noOPDiagnostics{} 48 | } 49 | 50 | // Name is the name of the component used in error messages. 51 | func (d *noOPDiagnostics) Name() string { 52 | return "No-OP Diagnostics" 53 | } 54 | 55 | // Timing reports timing info. 56 | func (d *noOPDiagnostics) Timing(_, _, _ string, _, _ time.Time) error { 57 | if d.closed { 58 | return errors.New(d.Name(), "cannot add timing data after diagnostics are closed") 59 | } 60 | return nil 61 | } 62 | 63 | // Severe reports an error that is highly likely to cause problems in tests. 64 | func (d *noOPDiagnostics) Severe(err error) error { 65 | if d.closed { 66 | return errors.New(d.Name(), "cannot add errors after diagnostics are closed") 67 | } 68 | log.Print(err) 69 | return nil 70 | } 71 | 72 | // Warning reports a error that is unlikely to cause problems in tests, but 73 | // that you want to track anyway. 74 | func (d *noOPDiagnostics) Warning(err error) error { 75 | if d.closed { 76 | return errors.New(d.Name(), "cannot add errors after diagnostics are closed") 77 | } 78 | log.Print(err) 79 | return nil 80 | } 81 | 82 | // Close closes this diagnostics object. 83 | func (d *noOPDiagnostics) Close() error { 84 | d.closed = true 85 | return nil 86 | } 87 | 88 | // String returns a string representation of the diagnostics. 89 | func (d *noOPDiagnostics) String() string { 90 | return "No-OP Diagnostics" 91 | } 92 | -------------------------------------------------------------------------------- /go/wtl/environment/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["environment.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/environment", 25 | visibility = ["//go/wtl:__subpackages__"], 26 | deps = [ 27 | "//go/errors:go_default_library", 28 | "//go/healthreporter:go_default_library", 29 | "//go/metadata:go_default_library", 30 | "//go/metadata/capabilities:go_default_library", 31 | "//go/wtl/diagnostics:go_default_library", 32 | ], 33 | ) 34 | -------------------------------------------------------------------------------- /go/wtl/environment/external/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["external.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/environment/external", 25 | visibility = ["//go/wtl:__subpackages__"], 26 | deps = [ 27 | "//go/errors:go_default_library", 28 | "//go/metadata:go_default_library", 29 | "//go/wtl/diagnostics:go_default_library", 30 | "//go/wtl/environment:go_default_library", 31 | ], 32 | ) 33 | -------------------------------------------------------------------------------- /go/wtl/environment/external/external.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package external works with an externally started WebDriver server 16 | // located at EXTERNAL_WEBDRIVER_SERVER_ADDRESS. 17 | package external 18 | 19 | import ( 20 | "context" 21 | "fmt" 22 | "os" 23 | 24 | "github.com/bazelbuild/rules_webtesting/go/errors" 25 | "github.com/bazelbuild/rules_webtesting/go/metadata" 26 | "github.com/bazelbuild/rules_webtesting/go/wtl/diagnostics" 27 | "github.com/bazelbuild/rules_webtesting/go/wtl/environment" 28 | ) 29 | 30 | const ( 31 | name = "External WebDriver Environment" 32 | addressEnvVar = "EXTERNAL_WEBDRIVER_SERVER_ADDRESS" 33 | ) 34 | 35 | type external struct { 36 | *environment.Base 37 | address string 38 | } 39 | 40 | // NewEnv creates a new environment that uses an externally started Selenium Server. 41 | func NewEnv(m *metadata.Metadata, d diagnostics.Diagnostics) (environment.Env, error) { 42 | address, ok := os.LookupEnv(addressEnvVar) 43 | if !ok { 44 | return nil, errors.New(name, fmt.Errorf("environment variable %q not set", addressEnvVar)) 45 | } 46 | 47 | base, err := environment.NewBase(name, m, d) 48 | if err != nil { 49 | return nil, err 50 | } 51 | 52 | return &external{ 53 | Base: base, 54 | address: address, 55 | }, nil 56 | } 57 | 58 | // WDAddress returns the user-provided selenium address. 59 | func (e *external) WDAddress(context.Context) string { 60 | return e.address 61 | } 62 | -------------------------------------------------------------------------------- /go/wtl/environment/local/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["local.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/environment/local", 25 | visibility = ["//go/wtl:__subpackages__"], 26 | deps = [ 27 | "//go/metadata:go_default_library", 28 | "//go/wtl/diagnostics:go_default_library", 29 | "//go/wtl/environment:go_default_library", 30 | "//go/wtl/service:go_default_library", 31 | "//go/wtl/service/wsl:go_default_library", 32 | ], 33 | ) 34 | -------------------------------------------------------------------------------- /go/wtl/environment/local/local.go: -------------------------------------------------------------------------------- 1 | // Package local provides a basic environment for web tests locally. 2 | package local 3 | 4 | import ( 5 | "context" 6 | "fmt" 7 | 8 | "github.com/bazelbuild/rules_webtesting/go/metadata" 9 | "github.com/bazelbuild/rules_webtesting/go/wtl/diagnostics" 10 | "github.com/bazelbuild/rules_webtesting/go/wtl/environment" 11 | "github.com/bazelbuild/rules_webtesting/go/wtl/service" 12 | "github.com/bazelbuild/rules_webtesting/go/wtl/service/wsl" 13 | ) 14 | 15 | const ( 16 | compName = "local environment" 17 | ) 18 | 19 | type local struct { 20 | *environment.Base 21 | wsl *service.Server 22 | } 23 | 24 | // NewEnv creates a new environment for launching a local browser using WSL. 25 | func NewEnv(m *metadata.Metadata, d diagnostics.Diagnostics) (environment.Env, error) { 26 | base, err := environment.NewBase(compName, m, d) 27 | if err != nil { 28 | return nil, err 29 | } 30 | wsl, err := wsl.New(d, m) 31 | if err != nil { 32 | return nil, err 33 | } 34 | 35 | return &local{ 36 | Base: base, 37 | wsl: wsl, 38 | }, nil 39 | } 40 | 41 | func (l *local) SetUp(ctx context.Context) error { 42 | if err := l.Base.SetUp(ctx); err != nil { 43 | return err 44 | } 45 | return l.wsl.Start(ctx) 46 | } 47 | 48 | func (l *local) TearDown(ctx context.Context) error { 49 | if err := l.Base.TearDown(ctx); err != nil { 50 | return err 51 | } 52 | return l.wsl.Stop(ctx) 53 | } 54 | 55 | func (l *local) WDAddress(context.Context) string { 56 | return fmt.Sprintf("http://%s/", l.wsl.Address()) 57 | } 58 | 59 | func (l *local) Healthy(ctx context.Context) error { 60 | if err := l.Base.Healthy(ctx); err != nil { 61 | return err 62 | } 63 | return l.wsl.Healthy(ctx) 64 | } 65 | -------------------------------------------------------------------------------- /go/wtl/environment/sauce/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["sauce.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/environment/sauce", 25 | visibility = ["//go/wtl:__subpackages__"], 26 | deps = [ 27 | "//go/metadata:go_default_library", 28 | "//go/metadata/capabilities:go_default_library", 29 | "//go/wtl/diagnostics:go_default_library", 30 | "//go/wtl/environment:go_default_library", 31 | "//go/wtl/service/sauce:go_default_library", 32 | ], 33 | ) 34 | -------------------------------------------------------------------------------- /go/wtl/main/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") 18 | load("//web/internal:executable_name.bzl", "get_platform_executable_name") 19 | 20 | licenses(["notice"]) # Apache 2.0 21 | 22 | go_library( 23 | name = "go_default_library", 24 | srcs = ["main.go"], 25 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/main", 26 | visibility = ["//go/wtl:__subpackages__"], 27 | deps = [ 28 | "//go/wtl:go_default_library", 29 | "//go/wtl/diagnostics:go_default_library", 30 | ], 31 | ) 32 | 33 | go_binary( 34 | name = "main", 35 | testonly = True, 36 | embed = [":go_default_library"], 37 | visibility = ["//visibility:public"], 38 | out = get_platform_executable_name(), 39 | ) 40 | -------------------------------------------------------------------------------- /go/wtl/main/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Binary launcher is used to manage the envrionment for web tests and start the underlying test. 16 | package main 17 | 18 | import ( 19 | "flag" 20 | "os" 21 | 22 | "github.com/bazelbuild/rules_webtesting/go/wtl" 23 | "github.com/bazelbuild/rules_webtesting/go/wtl/diagnostics" 24 | ) 25 | 26 | var ( 27 | test = flag.String("test", "", "Test to run.") 28 | metadataFileFlag = flag.String("metadata", "", "Metadata file for the browser.") 29 | debuggerPort = flag.Int("debugger_port", 0, "Port to start WTL debugger on.") 30 | httpPort = flag.Int("http_port", 0, "Port to start WTL HTTP Proxy on.") 31 | httpsPort = flag.Int("https_port", 0, "Port to start WTL HTTPS Proxy on.") 32 | ) 33 | 34 | func main() { 35 | flag.Parse() 36 | 37 | d := diagnostics.NoOP() 38 | 39 | status := wtl.Run(d, *test, *metadataFileFlag, *httpPort, *httpsPort, *debuggerPort) 40 | 41 | d.Close() 42 | os.Exit(status) 43 | } 44 | -------------------------------------------------------------------------------- /go/wtl/proxy/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//go/web:go.bzl", "go_web_test_suite") 18 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 19 | 20 | licenses(["notice"]) # Apache 2.0 21 | 22 | go_library( 23 | name = "go_default_library", 24 | srcs = ["proxy.go"], 25 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/proxy", 26 | visibility = ["//go/wtl:__subpackages__"], 27 | deps = [ 28 | "//go/errors:go_default_library", 29 | "//go/healthreporter:go_default_library", 30 | "//go/httphelper:go_default_library", 31 | "//go/metadata:go_default_library", 32 | "//go/wtl/diagnostics:go_default_library", 33 | "//go/wtl/environment:go_default_library", 34 | ], 35 | ) 36 | 37 | go_web_test_suite( 38 | name = "go_default_test", 39 | srcs = ["proxy_test.go"], 40 | browsers = [ 41 | "//browsers:chromium-local", 42 | "//browsers:firefox-local", 43 | "//browsers/sauce:chrome-win10", 44 | "//browsers/sauce:chrome-win10-connect", 45 | ], 46 | config = "//testdata:https", 47 | deps = ["//go/httphelper:go_default_library"], 48 | ) 49 | -------------------------------------------------------------------------------- /go/wtl/proxy/driverhub/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = [ 24 | "driver_hub.go", 25 | "driver_responses.go", 26 | "driver_session.go", 27 | ], 28 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/proxy/driverhub", 29 | visibility = ["//go/wtl:__subpackages__"], 30 | deps = [ 31 | "//go/errors:go_default_library", 32 | "//go/healthreporter:go_default_library", 33 | "//go/httphelper:go_default_library", 34 | "//go/metadata:go_default_library", 35 | "//go/metadata/capabilities:go_default_library", 36 | "//go/webdriver:go_default_library", 37 | "//go/wtl/diagnostics:go_default_library", 38 | "//go/wtl/environment:go_default_library", 39 | "//go/wtl/proxy:go_default_library", 40 | "//go/wtl/proxy/driverhub/debugger:go_default_library", 41 | "@com_github_gorilla_mux//:go_default_library", 42 | ], 43 | ) 44 | -------------------------------------------------------------------------------- /go/wtl/proxy/driverhub/debugger/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["debugger.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/proxy/driverhub/debugger", 25 | visibility = ["//go/wtl:__subpackages__"], 26 | deps = [ 27 | "//go/errors:go_default_library", 28 | ], 29 | ) 30 | 31 | go_test( 32 | name = "go_default_test", 33 | srcs = ["debugger_test.go"], 34 | embed = [":go_default_library"], 35 | ) 36 | -------------------------------------------------------------------------------- /go/wtl/proxy/driverhub/drivermu/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["driver_mu.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/proxy/driverhub/drivermu", 25 | visibility = ["//go/wtl:__subpackages__"], 26 | deps = [ 27 | "//go/metadata/capabilities:go_default_library", 28 | "//go/wtl/proxy/driverhub:go_default_library", 29 | ], 30 | ) 31 | -------------------------------------------------------------------------------- /go/wtl/proxy/driverhub/drivermu/driver_mu.go: -------------------------------------------------------------------------------- 1 | // Package drivermu implements a handler that temporally serializes all commands to a session. 2 | package drivermu 3 | 4 | import ( 5 | "context" 6 | "sync" 7 | 8 | "github.com/bazelbuild/rules_webtesting/go/metadata/capabilities" 9 | "github.com/bazelbuild/rules_webtesting/go/wtl/proxy/driverhub" 10 | ) 11 | 12 | // ProviderFunc provides a handler that temporally serializes all commands to a session. 13 | func ProviderFunc(_ *driverhub.WebDriverSession, _ *capabilities.Capabilities, base driverhub.HandlerFunc) (driverhub.HandlerFunc, bool) { 14 | var mu sync.Mutex 15 | 16 | return func(ctx context.Context, rq driverhub.Request) (driverhub.Response, error) { 17 | mu.Lock() 18 | defer mu.Unlock() 19 | return base(ctx, rq) 20 | }, true 21 | } 22 | -------------------------------------------------------------------------------- /go/wtl/proxy/driverhub/quithandler/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//go/web:go.bzl", "go_web_test_suite") 18 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 19 | 20 | licenses(["notice"]) # Apache 2.0 21 | 22 | go_library( 23 | name = "go_default_library", 24 | srcs = ["quit_handler.go"], 25 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/proxy/driverhub/quithandler", 26 | visibility = ["//go/wtl:__subpackages__"], 27 | deps = [ 28 | "//go/metadata/capabilities:go_default_library", 29 | "//go/wtl/proxy/driverhub:go_default_library", 30 | ], 31 | ) 32 | 33 | go_web_test_suite( 34 | name = "go_default_test", 35 | srcs = ["quit_handler_test.go"], 36 | browsers = [ 37 | "//browsers:chromium-local", 38 | "//browsers:firefox-local", 39 | "//browsers/sauce:chrome-win10", 40 | "//browsers/sauce:chrome-win10-connect", 41 | ], 42 | data = ["//testdata"], 43 | deps = [ 44 | "//go/bazel:go_default_library", 45 | "//go/httphelper:go_default_library", 46 | "//go/portpicker:go_default_library", 47 | "//go/webtest:go_default_library", 48 | "@com_github_tebeka_selenium//:go_default_library", 49 | ], 50 | ) 51 | -------------------------------------------------------------------------------- /go/wtl/proxy/driverhub/quithandler/quit_handler.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package quithandler checks if a window close command is closing the last window and treats it 16 | // as a quit if it is. 17 | package quithandler 18 | 19 | import ( 20 | "context" 21 | "net/http" 22 | 23 | "github.com/bazelbuild/rules_webtesting/go/metadata/capabilities" 24 | "github.com/bazelbuild/rules_webtesting/go/wtl/proxy/driverhub" 25 | ) 26 | 27 | // ProviderFunc provides a handler for quit and close commands that end the session within the environment when the browser exits. 28 | func ProviderFunc(session *driverhub.WebDriverSession, _ *capabilities.Capabilities, base driverhub.HandlerFunc) (driverhub.HandlerFunc, bool) { 29 | return func(ctx context.Context, rq driverhub.Request) (driverhub.Response, error) { 30 | // If quit command, then quit. 31 | if rq.Method == http.MethodDelete && len(rq.Path) == 0 { 32 | return session.Quit(ctx, rq) 33 | } 34 | 35 | // If not window close command, then forward as normal 36 | if rq.Method != http.MethodDelete || len(rq.Path) != 1 || rq.Path[0] != "window" { 37 | return base(ctx, rq) 38 | } 39 | 40 | // If closing last window, then quit. 41 | if windows, err := session.WindowHandles(ctx); err != nil { 42 | return driverhub.ResponseFromError(err) 43 | } else if len(windows) == 1 { 44 | return session.Quit(ctx, rq) 45 | } 46 | 47 | // Otherwise forward the close window 48 | return base(ctx, rq) 49 | }, true 50 | } 51 | -------------------------------------------------------------------------------- /go/wtl/proxy/driverhub/scripttimeout/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//go/web:go.bzl", "go_web_test_suite") 18 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 19 | 20 | licenses(["notice"]) # Apache 2.0 21 | 22 | go_library( 23 | name = "go_default_library", 24 | srcs = ["script_timeout.go"], 25 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/proxy/driverhub/scripttimeout", 26 | visibility = ["//go/wtl:__subpackages__"], 27 | deps = [ 28 | "//go/metadata/capabilities:go_default_library", 29 | "//go/wtl/proxy/driverhub:go_default_library", 30 | ], 31 | ) 32 | 33 | go_web_test_suite( 34 | name = "go_default_test", 35 | srcs = ["script_timeout_test.go"], 36 | browsers = [ 37 | "//browsers:chromium-local", 38 | "//browsers:firefox-local", 39 | "//browsers/sauce:chrome-win10", 40 | "//browsers/sauce:chrome-win10-connect", 41 | ], 42 | data = ["//testdata"], 43 | deps = [ 44 | "//go/bazel:go_default_library", 45 | "//go/portpicker:go_default_library", 46 | "//go/webtest:go_default_library", 47 | "@com_github_tebeka_selenium//:go_default_library", 48 | ], 49 | ) 50 | -------------------------------------------------------------------------------- /go/wtl/proxy/driverhub/scripttimeout/script_timeout_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package scripttimeout 16 | 17 | import ( 18 | "fmt" 19 | "log" 20 | "net/http" 21 | "os" 22 | "testing" 23 | "time" 24 | 25 | "github.com/bazelbuild/rules_webtesting/go/bazel" 26 | "github.com/bazelbuild/rules_webtesting/go/portpicker" 27 | "github.com/bazelbuild/rules_webtesting/go/webtest" 28 | "github.com/tebeka/selenium" 29 | ) 30 | 31 | var testpage = "" 32 | 33 | func TestMain(m *testing.M) { 34 | port, err := portpicker.PickUnusedPort() 35 | if err != nil { 36 | log.Fatal(err) 37 | } 38 | 39 | dir, err := bazel.Runfile("testdata/") 40 | if err != nil { 41 | log.Fatal(err) 42 | } 43 | 44 | go func() { 45 | log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), http.FileServer(http.Dir(dir)))) 46 | }() 47 | 48 | testpage = fmt.Sprintf("http://localhost:%d/testpage.html", port) 49 | 50 | os.Exit(m.Run()) 51 | } 52 | 53 | func TestSetScriptTimeout(t *testing.T) { 54 | // This test only superficially tests script timeout functionality (e.g. that the timeout still gets set). 55 | driver, err := webtest.NewWebDriverSession(selenium.Capabilities{}) 56 | if err != nil { 57 | t.Fatal(err) 58 | } 59 | 60 | defer driver.Quit() 61 | 62 | if err := driver.Get(testpage); err != nil { 63 | t.Fatal(err) 64 | } 65 | 66 | if err := driver.SetAsyncScriptTimeout(1 * time.Second); err != nil { 67 | t.Fatal(err) 68 | } 69 | 70 | start := time.Now() 71 | if _, err := driver.ExecuteScriptAsync("return;", []interface{}{}); err == nil { 72 | t.Fatal("got nil err, expected timeout err") 73 | } 74 | if run := time.Now().Sub(start); run < 1*time.Second { 75 | t.Fatalf("got runtime %v, expected to be at least 1 seconds", run) 76 | } 77 | 78 | if err := driver.SetAsyncScriptTimeout(5 * time.Second); err != nil { 79 | t.Fatal(err) 80 | } 81 | 82 | start = time.Now() 83 | if _, err := driver.ExecuteScriptAsync("return;", []interface{}{}); err == nil { 84 | t.Fatal("got nil err, expected timeout err") 85 | } 86 | if run := time.Now().Sub(start); run < 5*time.Second { 87 | t.Fatalf("got runtime %v, expected to be at least 1 seconds", run) 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /go/wtl/proxy/healthz/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["healthz.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/proxy/healthz", 25 | visibility = ["//go/wtl:__subpackages__"], 26 | deps = [ 27 | "//go/httphelper:go_default_library", 28 | "//go/wtl/proxy:go_default_library", 29 | ], 30 | ) 31 | -------------------------------------------------------------------------------- /go/wtl/proxy/healthz/healthz.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package healthz provides an HTTPHandler that always returns the string "ok". 16 | package healthz 17 | 18 | import ( 19 | "context" 20 | "io" 21 | "net/http" 22 | 23 | "github.com/bazelbuild/rules_webtesting/go/httphelper" 24 | "github.com/bazelbuild/rules_webtesting/go/wtl/proxy" 25 | ) 26 | 27 | type healthz struct{} 28 | 29 | // HTTPHandlerProvider returns a HTTPHandlerProvider for handling healthz requests. 30 | func HTTPHandlerProvider(*proxy.Proxy) (proxy.HTTPHandler, error) { 31 | return &healthz{}, nil 32 | } 33 | 34 | func (h *healthz) Shutdown(context.Context) error { 35 | return nil 36 | } 37 | 38 | func (h *healthz) ServeHTTP(w http.ResponseWriter, _ *http.Request) { 39 | w.Header().Set("Content-Type", "text/plain") 40 | httphelper.SetDefaultResponseHeaders(w.Header()) 41 | w.WriteHeader(http.StatusOK) 42 | io.WriteString(w, "ok") 43 | } 44 | 45 | func (*healthz) Name() string { 46 | return "healthz http handler" 47 | } 48 | 49 | func (*healthz) Healthy(context.Context) error { 50 | return nil 51 | } 52 | -------------------------------------------------------------------------------- /go/wtl/proxy/proxy_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package proxy 16 | 17 | import ( 18 | "context" 19 | "fmt" 20 | "net/http" 21 | "os" 22 | "testing" 23 | 24 | "github.com/bazelbuild/rules_webtesting/go/httphelper" 25 | ) 26 | 27 | func TestHTTPSProxy(t *testing.T) { 28 | address, ok := os.LookupEnv("WEB_TEST_HTTPS_SERVER") 29 | if !ok { 30 | t.Fatal("expected environment variable WEB_TEST_HTTPS_SERVER to be defined") 31 | } 32 | 33 | ctx := context.Background() 34 | 35 | url := fmt.Sprintf("%s/healthz", address) 36 | resp, err := httphelper.Get(ctx, url) 37 | if err != nil { 38 | t.Fatal(err) 39 | } 40 | resp.Body.Close() 41 | if resp.StatusCode != http.StatusOK { 42 | t.Fatalf("Got status code %d expected %d", resp.StatusCode, http.StatusOK) 43 | } 44 | } 45 | 46 | func TestHTTPProxy(t *testing.T) { 47 | address, ok := os.LookupEnv("WEB_TEST_HTTP_SERVER") 48 | if !ok { 49 | t.Fatal("expected environment variable WEB_TEST_HTTP_SERVER to be defined") 50 | } 51 | 52 | ctx := context.Background() 53 | 54 | url := fmt.Sprintf("%s/healthz", address) 55 | resp, err := httphelper.Get(ctx, url) 56 | if err != nil { 57 | t.Fatal(err) 58 | } 59 | resp.Body.Close() 60 | if resp.StatusCode != http.StatusOK { 61 | t.Fatalf("Got status code %d expected %d", resp.StatusCode, http.StatusOK) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /go/wtl/service/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = [ 24 | "cmd.go", 25 | "server.go", 26 | "service.go", 27 | ], 28 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/service", 29 | visibility = ["//go/wtl:__subpackages__"], 30 | deps = [ 31 | "//go/cmdhelper:go_default_library", 32 | "//go/errors:go_default_library", 33 | "//go/healthreporter:go_default_library", 34 | "//go/httphelper:go_default_library", 35 | "//go/portpicker:go_default_library", 36 | "//go/wtl/diagnostics:go_default_library", 37 | ], 38 | ) 39 | -------------------------------------------------------------------------------- /go/wtl/service/sauce/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["connect.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/service/sauce", 25 | visibility = ["//visibility:public"], 26 | deps = [ 27 | "//go/errors:go_default_library", 28 | "//go/metadata:go_default_library", 29 | "//go/portpicker:go_default_library", 30 | ], 31 | ) 32 | -------------------------------------------------------------------------------- /go/wtl/service/service.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package service provides the Service interface for managing the life-cycle 16 | // of a single binary. 17 | package service 18 | 19 | import ( 20 | "context" 21 | "sync" 22 | 23 | "github.com/bazelbuild/rules_webtesting/go/errors" 24 | "github.com/bazelbuild/rules_webtesting/go/wtl/diagnostics" 25 | ) 26 | 27 | // Base is a base struct for defining a service. 28 | type Base struct { 29 | diagnostics.Diagnostics 30 | name string 31 | mu sync.RWMutex 32 | started bool 33 | stopped bool 34 | } 35 | 36 | // NewBase creates a new Base service with the given component name. 37 | func NewBase(name string, d diagnostics.Diagnostics) *Base { 38 | return &Base{Diagnostics: d, name: name} 39 | } 40 | 41 | // Start makes this service as started, failing if it has already been started. 42 | func (b *Base) Start(context.Context) error { 43 | b.mu.Lock() 44 | defer b.mu.Unlock() 45 | if b.started { 46 | return errors.NewPermanent(b.Name(), "cannot be started; it has already been started once") 47 | } 48 | b.started = true 49 | return nil 50 | } 51 | 52 | // Stop makes this service as stopped, failing if it hasn't been started or has already been stopped. 53 | func (b *Base) Stop(context.Context) error { 54 | b.mu.Lock() 55 | defer b.mu.Unlock() 56 | if !b.started { 57 | return errors.NewPermanent(b.Name(), "cannot be stopped; it was never started") 58 | } 59 | if b.stopped { 60 | return errors.NewPermanent(b.Name(), "cannot be stopped; it was already stopped once") 61 | } 62 | b.stopped = true 63 | return nil 64 | } 65 | 66 | // Healthy returns nil if this service has been started and has not been stopped. 67 | func (b *Base) Healthy(context.Context) error { 68 | b.mu.RLock() 69 | defer b.mu.RUnlock() 70 | if !b.started { 71 | return errors.NewPermanent(b.Name(), "has not been started") 72 | } 73 | if b.stopped { 74 | return errors.NewPermanent(b.Name(), "has been stopped") 75 | } 76 | return nil 77 | } 78 | 79 | // Name returns the component name used in error messages. 80 | func (b *Base) Name() string { 81 | return b.name 82 | } 83 | -------------------------------------------------------------------------------- /go/wtl/service/wsl/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | go_library( 22 | name = "go_default_library", 23 | srcs = ["wsl.go"], 24 | importpath = "github.com/bazelbuild/rules_webtesting/go/wtl/service/wsl", 25 | visibility = ["//go/wtl:__subpackages__"], 26 | deps = [ 27 | "//go/errors:go_default_library", 28 | "//go/metadata:go_default_library", 29 | "//go/wtl/diagnostics:go_default_library", 30 | "//go/wtl/service:go_default_library", 31 | ], 32 | ) 33 | -------------------------------------------------------------------------------- /go/wtl/service/wsl/wsl.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package wsl provides a Service for launching WebDriver Server Light (WSL). 16 | package wsl 17 | 18 | import ( 19 | "time" 20 | 21 | "github.com/bazelbuild/rules_webtesting/go/errors" 22 | "github.com/bazelbuild/rules_webtesting/go/metadata" 23 | "github.com/bazelbuild/rules_webtesting/go/wtl/diagnostics" 24 | "github.com/bazelbuild/rules_webtesting/go/wtl/service" 25 | ) 26 | 27 | const ( 28 | compName = "WSL Service" 29 | wslNamedFile = "WEBDRIVER_SERVER_LIGHT" 30 | ) 31 | 32 | // New creates a new service.Server instance that manages chromedriver. 33 | func New(d diagnostics.Diagnostics, m *metadata.Metadata) (*service.Server, error) { 34 | wslPath, err := m.GetFilePath(wslNamedFile) 35 | if err != nil { 36 | return nil, errors.New(compName, err) 37 | } 38 | 39 | server, err := service.NewServer( 40 | compName, 41 | d, 42 | wslPath, 43 | "http://%s/healthz", 44 | false, 45 | 1*time.Second, 46 | nil, 47 | "--port={port}") 48 | if err != nil { 49 | return nil, err 50 | } 51 | return server, nil 52 | } 53 | -------------------------------------------------------------------------------- /sauce.md: -------------------------------------------------------------------------------- 1 | # Running Web Tests with Sauce Labs 2 | 3 | There are two Sauce browsers defined and used by tests. 4 | 5 | 1. //browsers/sauce:chrome-win10, requires that SauceConnect is already 6 | running. 7 | 8 | 2. //browsers/sauce:chrome-win10-connect, will start an instance of 9 | SauceConnect for each browser target. 10 | 11 | ## //browsers/sauce:chrome-win10 tests 12 | 13 | Before starting the tests you need to export some environment variables and 14 | start Sauce Connect. You can dowload Sauce Connect at 15 | https://wiki.saucelabs.com/display/DOCS/Setting+Up+Sauce+Connect+Proxy 16 | 17 | In a separate terminal run the following: 18 | 19 | ```sh 20 | export SAUCE_USERNAME= 21 | export SAUCE_ACCESS_KEY= 22 | export TUNNEL_IDENTIFIER= 23 | sc -i $TUNNEL_IDENTIFIER 24 | ``` 25 | 26 | Wait for the message: "Sauce Connect is up, you may start your tests." 27 | 28 | Then in the terminal where you are going to run Bazel do the following: 29 | 30 | ```sh 31 | export SAUCE_USERNAME= 32 | export SAUCE_ACCESS_KEY= 33 | export TUNNEL_IDENTIFIER= 34 | export BUILD_TAG= 35 | ``` 36 | 37 | Then to run the tests, use the following: 38 | 39 | ```sh 40 | bazel test --test_tag_filters=chrome-win10 --test_output=streamed ... 41 | ``` 42 | 43 | ## //browsers/sauce:chrome-win10-connect tests 44 | 45 | To run the tests, use the following: 46 | 47 | ```sh 48 | bazel test --test_tag_filters=chrome-win10-connect --test_output=streamed ... 49 | ``` 50 | -------------------------------------------------------------------------------- /testdata/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//web:web.bzl", "web_test_files", "web_test_config") 18 | 19 | package(default_testonly = True) 20 | 21 | licenses(["notice"]) # Apache 2.0 22 | 23 | filegroup( 24 | name = "testdata", 25 | srcs = glob(["*"]), 26 | visibility = ["//visibility:public"], 27 | ) 28 | 29 | web_test_files( 30 | name = "keys", 31 | files = { 32 | "key.pem": "PROXY_TLS_KEY", 33 | "cert.pem": "PROXY_TLS_CERT", 34 | }, 35 | ) 36 | 37 | web_test_config( 38 | name = "https", 39 | visibility = ["//:__subpackages__"], 40 | deps = [ 41 | ":keys", 42 | "//web:default_config", 43 | ], 44 | ) 45 | -------------------------------------------------------------------------------- /testdata/all-fields.json: -------------------------------------------------------------------------------- 1 | { 2 | "capabilities": {}, 3 | "environment": "chromeos", 4 | "browserLabel": "//browsers:figaro", 5 | "testLabel": "//go/wtl:tests", 6 | "namedExecutables": {} 7 | } 8 | -------------------------------------------------------------------------------- /testdata/android-browser-gingerbread-nexus-s.json: -------------------------------------------------------------------------------- 1 | { 2 | "capabilities": { 3 | "goog:chromeOptions": { 4 | "mobileEmulation": { 5 | "userAgent": "Mozilla/5.0 (Linux; U; Android 2.3.7; en-us; Nexus S Build/GRI20) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", 6 | "deviceMetrics": { 7 | "pixelRatio": 2, 8 | "height": 400, 9 | "width": 240 10 | } 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /testdata/bad-named-files.json: -------------------------------------------------------------------------------- 1 | { 2 | "webTestFiles" : [ 3 | {"namedFiles" : {"a" : "A"}}, 4 | {"archiveFile" : "A", "namedFiles" : {"a" : "A"}} 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /testdata/cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFXTCCA0WgAwIBAgIJAJrc5FuV957pMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV 3 | BAYTAlVTMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX 4 | aWRnaXRzIFB0eSBMdGQwHhcNMTcwNTE3MTgzMTU0WhcNMjAwMjExMTgzMTU0WjBF 5 | MQswCQYDVQQGEwJVUzETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50 6 | ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIIC 7 | CgKCAgEA9nmH0yrl3E3vmiVmevYOtRwC28+1kr27qxGNGT6UfZKWpXdRm/asLXFW 8 | IIjNI++io+tKDJjAko6KXtGdAIoice+p14J/rKASwuVhgM4+zyiayEgBrSxjav8a 9 | X5wMvnwYP9JtD9F1DQM37gkaAnCUf0jclAfpr9PI2SLKwLOLxh1qHCQgtgJRqEX6 10 | 0wPBCo75P6cBpz79XWAMoiL2k3oACcd80oCD3++FhU4b3eDujpsdqtQS/Zw356dp 11 | 55SD2Q9YMTQzlTCHt0FO4313WnwzQnemBn8CCPsUISrfSybgdEKo8WEiYRO/pPfW 12 | v4Md/ilSq4OzfIjV5l8yv+oAlY7sR6zN/pQBNyWe9XBm3yYuIOitm1xyeuH8e5fK 13 | j6SSk0SUwCa+YqdH1LGr03ZiI4e1ygJWSmeOGnagJVrVN+u0mTONYjoHrpS1bV8z 14 | cB9RMO58O5eChozCoOhj1dMpmjaq1wy0b3SM+ohDK4edfFotScy1+HYqdnsLmODv 15 | eX1PWOB4QazLcjVpQEkUfX21Y3/14Sr6BPsAaPjywZDZAsCs6dAE0x7qg33kFjka 16 | TruFk0AwXOyCKpS7ZZUexqfZI0sMOQpwDJuabBDDM5CFZbnp5p1abLWJ0CBo59zP 17 | KoM9gJHA/Nc4OWAG2pGxINMAdKlkVP2h+j1I86xl6NeW39Tgn+0CAwEAAaNQME4w 18 | HQYDVR0OBBYEFGUrLVfpI2NTfnYWqlr3urZAKV0xMB8GA1UdIwQYMBaAFGUrLVfp 19 | I2NTfnYWqlr3urZAKV0xMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggIB 20 | AKtjNUaLx9/44PwVx/LWLXsWup41AdnDsFvYIjCf+nBkT3nfOwm2WH91tB9jvVoE 21 | FpjRG1VeB7SeyLjTn+DnLRQWFXuKzPpO6vMBQAQVvubLTNNSH6hp+VyKMDXDram/ 22 | ILoWzoEv7YeGBo78MV6c7BwuQB/cL7zmDyDlcxB1e5VIgVGs/IKdeM/4KfflSmbp 23 | XlLRPuwmHOvJlqFjzxEYS//PXqJquk4abomSKjCxAxGvx4GZW9kkqrIBmU8pqM1S 24 | 356x0e9ezPY7fhdFRlemFE56sJTXXmkZJSUizb4GrA7dExNl2EM5EIgNpKwo0gWE 25 | QagrxCjrAA1AAtMVunPsZpp9obpCry+SBHqWZ7FkYaZPv/0GLW4Ymag/5d3Lfo+e 26 | ymDdWzdqzGbitd4+sutskdcBJ3bPl3dVHwtDVnPU7DH1bOTWk5SCFvhX9okYshYR 27 | QPGYVoTqOolDLmGgZftkLgXMe5NTwQdHqEYGfEX8yxu56EKU6Vdi+xJJWon3vQM2 28 | voPoArYcioV8O4LXtjG6f6/eMZCrF/j5abbYvohQmdnOpJ4E8AHkdBBZOz/7ANGs 29 | +z8UMRcP4O9nOo4qdw8f0EkSE8nswK/Q5wCSuagzbvSMMBfqdCu4aPj2ElRQoYgK 30 | Gu31kBaMsbsOpdfjmNDtwYNcI4/Vq0mMP/AfXlRIigQm 31 | -----END CERTIFICATE----- 32 | -------------------------------------------------------------------------------- /testdata/chrome-linux.json: -------------------------------------------------------------------------------- 1 | {"capabilities": { 2 | "browserName": "chrome", 3 | "javascriptEnabled": true, 4 | "platform": "UNIX" 5 | }} 6 | -------------------------------------------------------------------------------- /testdata/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazelbuild/rules_webtesting/c89ebef152d102fd3470e10df4d461dadadfb674/testdata/example.png -------------------------------------------------------------------------------- /testdata/extension.json: -------------------------------------------------------------------------------- 1 | { 2 | "capabilities": {}, 3 | "environment": "chromeos", 4 | "browserLabel": "//browsers:figaro", 5 | "testLabel": "//go/wtl:tests", 6 | "namedExecutables": {}, 7 | "extension": { 8 | "ExtensionField1": "hello", 9 | "ExtensionField2": 1024 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /testdata/merge-from-file-result.json: -------------------------------------------------------------------------------- 1 | { 2 | "capabilities": { 3 | "browserName": "chrome", 4 | "javascriptEnabled": true, 5 | "platform": "UNIX", 6 | "goog:chromeOptions": { 7 | "mobileEmulation": { 8 | "userAgent": "Mozilla/5.0 (Linux; U; Android 2.3.7; en-us; Nexus S Build/GRI20) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", 9 | "deviceMetrics": { 10 | "pixelRatio": 2, 11 | "height": 400, 12 | "width": 240 13 | } 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /testdata/merger-result.json: -------------------------------------------------------------------------------- 1 | { 2 | "capabilities": { 3 | "browserName": "chrome", 4 | "goog:chromeOptions": { 5 | "mobileEmulation": { 6 | "deviceMetrics": { 7 | "height": 400, 8 | "pixelRatio": 2, 9 | "width": 240 10 | }, 11 | "userAgent": "Mozilla/5.0 (Linux; U; Android 2.3.7; en-us; Nexus S Build/GRI20) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1" 12 | } 13 | }, 14 | "javascriptEnabled": true, 15 | "platform": "UNIX" 16 | }, 17 | "extension": {} 18 | } 19 | -------------------------------------------------------------------------------- /testdata/named-files1.json: -------------------------------------------------------------------------------- 1 | { "webTestFiles" : [ {"namedFiles" : {"A" : "a"}} ] } 2 | -------------------------------------------------------------------------------- /testdata/named-files2.json: -------------------------------------------------------------------------------- 1 | { "webTestFiles" : [ {"namedFiles" : {"A" : "b"}} ] } -------------------------------------------------------------------------------- /testdata/testpage.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | Test Page 20 | 21 | 22 | 23 | 24 |
25 | before inner divs 26 |
Div 1
27 |
Div 2
28 |
29 | Hello World
again.
30 |
31 |
32 | 33 | 34 | -------------------------------------------------------------------------------- /testdata/webdriver.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | WebDriver 20 | 21 | 22 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /testdata/webdriver_autofocus.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | WebDriver 20 | 21 | 22 |
23 | 24 | 25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /third_party/chromedriver/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | 18 | licenses([ 19 | "notice", 20 | "reciprocal", 21 | ]) 22 | 23 | exports_files(["LICENSE"]) 24 | 25 | alias( 26 | name = "chromedriver", 27 | testonly = True, 28 | actual = select({ 29 | "//common/conditions:linux_x64": "@org_chromium_chromedriver_linux_x64//:metadata", 30 | "//common/conditions:macos_x64": "@org_chromium_chromedriver_macos_x64//:metadata", 31 | "//common/conditions:macos_arm64": "@org_chromium_chromedriver_macos_arm64//:metadata", 32 | "//common/conditions:windows_x64": "@org_chromium_chromedriver_windows_x64//:metadata", 33 | }), 34 | visibility = ["//browsers:__subpackages__"], 35 | ) 36 | -------------------------------------------------------------------------------- /third_party/chromium/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | licenses(["by_exception_only"]) 18 | 19 | exports_files(["LICENSE"]) 20 | 21 | alias( 22 | name = "chromium", 23 | testonly = True, 24 | actual = select({ 25 | "//common/conditions:linux_x64": "@org_chromium_chromium_linux_x64//:metadata", 26 | "//common/conditions:macos_x64": "@org_chromium_chromium_macos_x64//:metadata", 27 | "//common/conditions:macos_arm64": "@org_chromium_chromium_macos_arm64//:metadata", 28 | "//common/conditions:windows_x64": "@org_chromium_chromium_windows_x64//:metadata", 29 | }), 30 | visibility = ["//browsers:__subpackages__"], 31 | ) 32 | -------------------------------------------------------------------------------- /third_party/firefox/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | 18 | licenses(["reciprocal"]) # MPL 2.0 19 | 20 | exports_files(["LICENSE"]) 21 | 22 | alias( 23 | name = "firefox", 24 | testonly = True, 25 | tags = ["manual"], 26 | actual = select({ 27 | "//common/conditions:linux_x64": "@org_mozilla_firefox_linux_x64//:metadata", 28 | "//common/conditions:macos_x64": "@org_mozilla_firefox_macos_x64//:metadata", 29 | "//common/conditions:macos_arm64": "@org_mozilla_firefox_macos_arm64//:metadata", 30 | "//common/conditions:windows_x64": "@org_mozilla_firefox_windows_x64//:metadata", 31 | }), 32 | visibility = ["//browsers:__subpackages__"], 33 | ) 34 | -------------------------------------------------------------------------------- /third_party/geckodriver/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | 18 | licenses(["reciprocal"]) # MPL 2.0 19 | 20 | exports_files(["LICENSE"]) 21 | 22 | alias( 23 | name = "geckodriver", 24 | testonly = True, 25 | tags = ["manual"], 26 | actual = select({ 27 | "//common/conditions:linux_x64": "@org_mozilla_geckodriver_linux_x64//:metadata", 28 | "//common/conditions:macos_x64": "@org_mozilla_geckodriver_macos_x64//:metadata", 29 | "//common/conditions:macos_arm64": "@org_mozilla_geckodriver_macos_arm64//:metadata", 30 | "//common/conditions:windows_x64": "@org_mozilla_geckodriver_windows_x64//:metadata", 31 | }), 32 | visibility = ["//browsers:__subpackages__"], 33 | ) 34 | -------------------------------------------------------------------------------- /third_party/sauceconnect/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | 18 | licenses(["by_exception_only"]) # SauceLabs EULA 19 | 20 | exports_files(["license.html"]) 21 | 22 | alias( 23 | name = "sauceconnect", 24 | testonly = True, 25 | actual = select({ 26 | "//common/conditions:linux_x64": "@com_saucelabs_sauce_connect_linux_x64//:metadata", 27 | "//common/conditions:macos_x64": "@com_saucelabs_sauce_connect_macos_x64//:metadata", 28 | "//common/conditions:windows_x64": "@com_saucelabs_sauce_connect_windows_x64//:metadata", 29 | # TODO: Consider wiring up binaries for SauceConnect arm64 darwin if available. 30 | }, no_match_error = "Sauce Connect is not yet supported for Darwin ARM64."), 31 | visibility = ["//browsers:__subpackages__"], 32 | ) 33 | -------------------------------------------------------------------------------- /tools/copy.bara.sky: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Copybara workflow to create a releasable directory. 16 | Is used from releaser.sh script. 17 | """ 18 | 19 | core.workflow( 20 | name = "release", 21 | origin = folder.origin(materialize_outside_symlinks = True), 22 | destination = folder.destination(), 23 | authoring = authoring.pass_thru("Marc Fisher "), 24 | origin_files = glob( 25 | [ 26 | # Source paths to include 27 | "*", 28 | "browsers/**", 29 | "build_files/**", 30 | "common/**", 31 | "go/bazel/**", 32 | "go/cmdhelper/**", 33 | "go/httphelper/**", 34 | "go/metadata/**", 35 | "go/portpicker/**", 36 | "go/webtest/**", 37 | "java/**", 38 | "javatests/**", 39 | "scalatests/**", 40 | "testdata/**", 41 | "testing/**", 42 | "third_party/**", 43 | "web/**", 44 | 45 | # binaries to include 46 | "bazel-bin/go/metadata/main/main_*", 47 | "bazel-bin/go/wsl/main/main_*", 48 | "bazel-bin/go/wtl/main/main_*", 49 | ], 50 | exclude = [".bazelrc", "go/metadata/main/**", "**/*.runfiles_manifest"], 51 | ), 52 | transformations = [ 53 | core.move("bazel-bin/go/metadata/main", "go/metadata/main"), 54 | core.move("bazel-bin/go/wsl/main", "go/wsl/main"), 55 | core.move("bazel-bin/go/wtl/main", "go/wtl/main"), 56 | core.move("build_files/metadata.BUILD", "go/metadata/main/BUILD.bazel"), 57 | core.move("build_files/wsl.BUILD", "go/wsl/BUILD.bazel"), 58 | core.move("build_files/wsl_main.BUILD", "go/wsl/main/BUILD.bazel"), 59 | core.move("build_files/wtl.BUILD", "go/wtl/main/BUILD.bazel"), 60 | ], 61 | ) 62 | -------------------------------------------------------------------------------- /tools/releaser.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2019 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Shell script for creating a release directory. 18 | 19 | copybaraBin=$(which copybara) 20 | 21 | # If Copybara is not available in the `PATH`, we try using Copybara 22 | # from a path where it is supposed to exist (Googlers-only). 23 | if [[ -z "${copybaraBin}" ]]; then 24 | copybaraBin=/google/data/ro/teams/copybara/copybara 25 | fi 26 | 27 | cd "$(dirname $0)/.." 28 | pwd 29 | 30 | bazel build -c opt --stamp \ 31 | --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64 \ 32 | //go/metadata/main \ 33 | //go/wsl/main \ 34 | //go/wtl/main 35 | 36 | bazel build -c opt --stamp \ 37 | --platforms=@io_bazel_rules_go//go/toolchain:darwin_arm64 \ 38 | //go/metadata/main \ 39 | //go/wsl/main \ 40 | //go/wtl/main 41 | 42 | bazel build -c opt --stamp \ 43 | --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 \ 44 | //go/metadata/main \ 45 | //go/wsl/main \ 46 | //go/wtl/main 47 | 48 | bazel build -c opt --stamp \ 49 | --platforms=@io_bazel_rules_go//go/toolchain:windows_amd64 \ 50 | //go/metadata/main \ 51 | //go/wsl/main \ 52 | //go/wtl/main 53 | 54 | tmpDir="$PWD/dist" 55 | outputDir="${tmpDir}/release-artifact" 56 | archiveDir="${tmpDir}/rules_webtesting.tar.gz" 57 | 58 | # Create a temporary directory for storing the release artifacts. 59 | rm -Rf ${tmpDir} 60 | mkdir -p ${tmpDir} 61 | 62 | # Build the release artifact directory using the Copybara `release` workflow. 63 | ${copybaraBin} --folder-dir="${outputDir}" migrate tools/copy.bara.sky "release" $PWD 64 | 65 | # Create the release output tarball. 66 | tar -cvzf ${archiveDir} -C ${outputDir} . 67 | 68 | echo "Release tarball has been stored in: ${archiveDir}" 69 | echo "Attach this tarball to the Github release entry." 70 | -------------------------------------------------------------------------------- /web/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load(":web.bzl", "web_test_config") 18 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 19 | 20 | package( 21 | default_testonly = True, 22 | default_visibility = ["//visibility:public"], 23 | ) 24 | 25 | licenses(["notice"]) # Apache 2.0 26 | 27 | web_test_config( 28 | name = "default_config", 29 | visibility = ["//visibility:public"], 30 | ) 31 | 32 | bzl_library( 33 | name = "web", 34 | srcs = ["web.bzl"], 35 | deps = [ 36 | "//web/internal:browser", 37 | "//web/internal:constants", 38 | "//web/internal:custom_browser", 39 | "//web/internal:platform_archive", 40 | "//web/internal:platform_metadata", 41 | "//web/internal:web_test", 42 | "//web/internal:web_test_config", 43 | "//web/internal:web_test_files", 44 | "//web/internal:web_test_named_executable", 45 | "//web/internal:web_test_named_file", 46 | "@bazel_skylib//lib:types", 47 | ], 48 | ) 49 | -------------------------------------------------------------------------------- /web/internal/constants.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Constants used in other build rules.""" 15 | 16 | DEFAULT_WRAPPED_TEST_TAGS = ("manual", "noci") 17 | 18 | DEFAULT_TEST_SUITE_TAGS = ("manual",) 19 | 20 | DEFAULT_WEB_TEST_SUITE_TAGS = { 21 | "chrome-external": [ 22 | "external", 23 | ], 24 | "chromium-local": [ 25 | "native", 26 | ], 27 | "chromium-local-1024x768": [ 28 | "native", 29 | ], 30 | "chrome-win10": [ 31 | "exclusive", 32 | "sauce", 33 | ], 34 | "chrome-win10-connect": [ 35 | "exclusive", 36 | "noci", 37 | "sauce", 38 | ], 39 | "firefox-external": [ 40 | "external", 41 | ], 42 | "firefox-local": [ 43 | "native", 44 | ], 45 | } 46 | -------------------------------------------------------------------------------- /web/internal/convert_dmg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2018 Google Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | ################################################################################ 17 | # 18 | 19 | DMGFILE=$1 20 | OUTFILE=$2 21 | mkdir -p tmp 22 | VOLUME=$(hdiutil attach "${DMGFILE}" | tail -1 | awk '{print $3}') 23 | cp -r "${VOLUME}/"*.app tmp 24 | hdiutil detach "${VOLUME}" >/dev/null 25 | cd tmp 26 | zip -r "../${OUTFILE}" * 27 | cd .. 28 | rm -rf tmp 29 | rm "${DMGFILE}" 30 | -------------------------------------------------------------------------------- /web/internal/executable_name.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | def get_platform_executable_name(): 16 | """ 17 | Retrieves the binary name for an executable based on the current platform. 18 | 19 | This is helpful when shipping binaries within the release package as otherwise 20 | Go binaries for example might have the same name for various platforms. A consistent 21 | way of naming executables for specific platforms allows them to be shipped in the 22 | release output, where the binaries can be referenced using the known file names. 23 | """ 24 | return select({ 25 | "//common/conditions:linux_x64": "main_linux_x64", 26 | "//common/conditions:macos_x64": "main_darwin_x64", 27 | "//common/conditions:macos_arm64": "main_darwin_arm64", 28 | "//common/conditions:windows_x64": "main_windows_x64.exe", 29 | }) 30 | -------------------------------------------------------------------------------- /web/internal/files.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """A library of functions for working with runfiles.""" 15 | 16 | def _long_path(ctx, file): 17 | """Constructs a path relative to TEST_SRCDIR for accessing the file. 18 | 19 | Args: 20 | ctx: a Skylark rule context. 21 | file: a File object. The file should appear in the runfiles for the 22 | test. 23 | 24 | Returns: 25 | A string path relative to TEST_SRCDIR suitable for use in tests and 26 | testing infrastructure. 27 | """ 28 | if file.short_path[:3] == "../": 29 | # sometimes a file"s short_path is ..// 30 | # then we just need to trim the ../ 31 | return file.short_path[3:] 32 | if file.owner and file.owner.workspace_root: 33 | # if the file has an owner and that owner has a workspace_root, 34 | # prepend it. 35 | return (file.owner.workspace_root + "/" + file.short_path) 36 | 37 | # otherwise assume the file is in the same workspace as the current rule. 38 | 39 | return (ctx.workspace_name + "/" + file.short_path) 40 | 41 | files = struct(long_path = _long_path) 42 | -------------------------------------------------------------------------------- /web/internal/noop_web_test.sh.template: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 Google Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | ################################################################################ 17 | # 18 | 19 | tee -a "$TEST_WARNINGS_OUTPUT_FILE" << EOF 20 | This test always %TEMPLATED_success%. Your test was not run. 21 | 22 | This dummy test was inserted in place of the web test you intended 23 | to run because: 24 | %TEMPLATED_reason% 25 | EOF 26 | 27 | exit %TEMPLATED_status% 28 | -------------------------------------------------------------------------------- /web/internal/provider.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Definition of WebTestInfo provider.""" 15 | 16 | WebTestInfo = provider( 17 | doc = "Provider for web_test information", 18 | fields = [ 19 | "disabled", 20 | "environment", 21 | "execution_requirements", 22 | "metadata", 23 | "required_tags", 24 | ], 25 | ) 26 | -------------------------------------------------------------------------------- /web/internal/runfiles.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Runfiles modules contains utility functions for working with runfiles.""" 15 | 16 | def _collect(ctx, files = [], targets = []): 17 | """Builds a runfiles object with transitive files from all targets. 18 | 19 | Args: 20 | ctx: Context object for the rule where this being used. 21 | files: a list of File object to include in the runfiles. 22 | targets: a list of Target object from which runfiles will be collected. 23 | 24 | Returns: 25 | A configured runfiles object that include data and default runfiles for the 26 | rule, all transitive runfiles from targets, and all files from files. 27 | """ 28 | transitive_runfiles = depset() 29 | dep_files = depset() 30 | default_runfiles = [] 31 | data_runfiles = [] 32 | 33 | for target in targets: 34 | if hasattr(target, "transitive_runfiles"): 35 | transitive_runfiles = depset( 36 | transitive = [transitive_runfiles, target.transitive_runfiles], 37 | ) 38 | if hasattr(target, "default_runfiles"): 39 | default_runfiles += [target.default_runfiles] 40 | if hasattr(target, "data_runfiles"): 41 | data_runfiles += [target.data_runfiles] 42 | if hasattr(target, "files"): 43 | dep_files = depset(transitive = [dep_files, target.files]) 44 | 45 | result = ctx.runfiles( 46 | collect_data = True, 47 | collect_default = True, 48 | files = files + dep_files.to_list(), 49 | transitive_files = transitive_runfiles, 50 | ) 51 | 52 | for default in default_runfiles: 53 | result = result.merge(default) 54 | 55 | for data in data_runfiles: 56 | result = result.merge(data) 57 | 58 | return result 59 | 60 | runfiles = struct(collect = _collect) 61 | -------------------------------------------------------------------------------- /web/internal/web_test_config.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """web_test_config.bzl defines the web_test_config rule. 15 | 16 | The web_test_config rules provides configuration information 17 | such as additional capabilities. 18 | 19 | DO NOT load this file. Use "@io_bazel_rules_web//web:web.bzl". 20 | """ 21 | 22 | load(":metadata.bzl", "metadata") 23 | load(":provider.bzl", "WebTestInfo") 24 | 25 | def _web_test_config_impl(ctx): 26 | """Implementation of the web_test_config rule.""" 27 | metadata_files = [] 28 | 29 | if ctx.attr.metadata: 30 | metadata_files = [ctx.file.metadata] 31 | 32 | metadata_files += [dep[WebTestInfo].metadata for dep in ctx.attr.deps] 33 | 34 | if metadata_files: 35 | metadata.merge_files( 36 | ctx = ctx, 37 | merger = ctx.executable.merger, 38 | output = ctx.outputs.web_test_metadata, 39 | inputs = metadata_files, 40 | ) 41 | else: 42 | metadata.create_file(ctx = ctx, output = ctx.outputs.web_test_metadata) 43 | 44 | return [ 45 | DefaultInfo( 46 | runfiles = ctx.runfiles(collect_data = True, collect_default = True), 47 | ), 48 | WebTestInfo(metadata = ctx.outputs.web_test_metadata), 49 | ] 50 | 51 | web_test_config = rule( 52 | attrs = { 53 | "data": attr.label_list( 54 | doc = "Runtime dependencies for this configuration.", 55 | allow_files = True, 56 | ), 57 | "deps": attr.label_list( 58 | doc = "Other web_test-related rules that this rule depends on.", 59 | providers = [WebTestInfo], 60 | ), 61 | "merger": attr.label( 62 | doc = "The metadata merger binary.", 63 | default = Label("//go/metadata/main"), 64 | allow_files = True, 65 | cfg = "exec", 66 | executable = True, 67 | ), 68 | "metadata": attr.label( 69 | doc = "A web_test metadata file.", 70 | allow_single_file = [".json"], 71 | ), 72 | }, 73 | doc = "A configuration that can be used across multiple web_tests.", 74 | outputs = {"web_test_metadata": "%{name}.gen.json"}, 75 | implementation = _web_test_config_impl, 76 | ) 77 | -------------------------------------------------------------------------------- /web/internal/web_test_files.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """A rule for configuring a set of named files. 15 | 16 | DO NOT load this file. Use "@io_bazel_rules_web//web:web.bzl". 17 | """ 18 | 19 | load(":metadata.bzl", "metadata") 20 | load(":provider.bzl", "WebTestInfo") 21 | 22 | def _web_test_files_impl(ctx): 23 | named_files = {} 24 | runfiles = depset() 25 | 26 | for target, name in ctx.attr.files.items(): 27 | if name in named_files: 28 | fail("%s appears multiple times." % name, "files") 29 | if len(target.files.to_list()) != 1: 30 | fail("%s refers to multiple files." % target.label, "files") 31 | named_files[name] = target.files.to_list()[0] 32 | runfiles = depset(transitive = [target.files, runfiles]) 33 | 34 | metadata.create_file( 35 | ctx = ctx, 36 | output = ctx.outputs.web_test_metadata, 37 | web_test_files = [ 38 | metadata.web_test_files(ctx = ctx, named_files = named_files), 39 | ], 40 | ) 41 | 42 | return [ 43 | DefaultInfo( 44 | runfiles = ctx.runfiles( 45 | collect_data = True, 46 | collect_default = True, 47 | files = runfiles.to_list(), 48 | ), 49 | ), 50 | WebTestInfo(metadata = ctx.outputs.web_test_metadata), 51 | ] 52 | 53 | web_test_files = rule( 54 | attrs = { 55 | "files": attr.label_keyed_string_dict( 56 | doc = "A map of files to names.", 57 | mandatory = True, 58 | allow_files = True, 59 | allow_empty = False, 60 | ), 61 | }, 62 | doc = "Specifies a set of named files.", 63 | outputs = {"web_test_metadata": "%{name}.gen.json"}, 64 | implementation = _web_test_files_impl, 65 | ) 66 | -------------------------------------------------------------------------------- /web/internal/web_test_named_executable.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """A rule for defining executables that can be located by name. 15 | 16 | DO NOT load this file. Use "@io_bazel_rules_web//web:web.bzl". 17 | """ 18 | 19 | load(":metadata.bzl", "metadata") 20 | load(":provider.bzl", "WebTestInfo") 21 | load(":runfiles.bzl", "runfiles") 22 | 23 | def _web_test_named_executable_impl(ctx): 24 | name = ctx.attr.alt_name or ctx.label.name 25 | 26 | metadata.create_file( 27 | ctx = ctx, 28 | output = ctx.outputs.web_test_metadata, 29 | web_test_files = [ 30 | metadata.web_test_files( 31 | ctx = ctx, 32 | named_files = {name: ctx.executable.executable}, 33 | ), 34 | ], 35 | ) 36 | 37 | return [ 38 | DefaultInfo( 39 | runfiles = runfiles.collect(ctx = ctx, targets = [ctx.attr.executable]), 40 | ), 41 | WebTestInfo(metadata = ctx.outputs.web_test_metadata), 42 | ] 43 | 44 | web_test_named_executable = rule( 45 | attrs = { 46 | "alt_name": attr.string(doc = "If supplied, is used instead of name."), 47 | "executable": attr.label( 48 | doc = "The executable that will be returned for name.", 49 | allow_files = True, 50 | executable = True, 51 | cfg = "target", 52 | mandatory = True, 53 | ), 54 | }, 55 | doc = "Defines an executable that can be located by name.", 56 | outputs = {"web_test_metadata": "%{name}.gen.json"}, 57 | implementation = _web_test_named_executable_impl, 58 | ) 59 | -------------------------------------------------------------------------------- /web/internal/web_test_named_file.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """A rule for defining files that can be located by name. 15 | 16 | DO NOT load this file. Use "@io_bazel_rules_web//web:web.bzl". 17 | """ 18 | 19 | load(":metadata.bzl", "metadata") 20 | load(":provider.bzl", "WebTestInfo") 21 | 22 | def _web_test_named_file_impl(ctx): 23 | name = ctx.attr.alt_name or ctx.label.name 24 | 25 | metadata.create_file( 26 | ctx = ctx, 27 | output = ctx.outputs.web_test_metadata, 28 | web_test_files = [ 29 | metadata.web_test_files(ctx = ctx, named_files = {name: ctx.file.file}), 30 | ], 31 | ) 32 | 33 | return [ 34 | DefaultInfo( 35 | runfiles = ctx.runfiles( 36 | collect_data = True, 37 | collect_default = True, 38 | files = [ctx.file.file], 39 | ), 40 | ), 41 | WebTestInfo(metadata = ctx.outputs.web_test_metadata), 42 | ] 43 | 44 | web_test_named_file = rule( 45 | attrs = { 46 | "alt_name": attr.string(doc = "If supplied, is used instead of name."), 47 | "file": attr.label( 48 | doc = "The file that will be returned for name.", 49 | allow_single_file = True, 50 | mandatory = True, 51 | ), 52 | }, 53 | doc = "Defines a file that can be located by name.", 54 | outputs = {"web_test_metadata": "%{name}.gen.json"}, 55 | implementation = _web_test_named_file_impl, 56 | ) 57 | -------------------------------------------------------------------------------- /web/versioned/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 18 | 19 | package( 20 | default_testonly = True, 21 | default_visibility = ["//visibility:public"], 22 | ) 23 | 24 | bzl_library( 25 | name = "browsers-0.3.1", 26 | srcs = ["browsers-0.3.1.bzl"], 27 | deps = [ 28 | "//web:web", 29 | ], 30 | ) 31 | 32 | bzl_library( 33 | name = "browsers-0.3.2", 34 | srcs = ["browsers-0.3.2.bzl"], 35 | deps = [ 36 | "//web:web", 37 | ], 38 | ) 39 | 40 | bzl_library( 41 | name = "browsers-0.3.3", 42 | srcs = ["browsers-0.3.3.bzl"], 43 | deps = [ 44 | "//web:web", 45 | ], 46 | ) 47 | 48 | bzl_library( 49 | name = "browsers-0.3.4", 50 | srcs = ["browsers-0.3.4.bzl"], 51 | deps = [ 52 | "//web:web", 53 | ], 54 | ) 55 | -------------------------------------------------------------------------------- /web_testing_go/.bazelci/setup_ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2025 Google Inc. All Rights Reserved 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS-IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Script that can be used by CI server for testing rules_webtesting builds. 17 | set -ex 18 | 19 | sudo apt -y update 20 | sudo apt -y install libasound2 \ 21 | libdbus-glib-1-2 \ 22 | libatk-bridge2.0-0 \ 23 | libatk1.0-0 \ 24 | libc6 \ 25 | libcairo2 \ 26 | libcups2 \ 27 | libdbus-1-3 \ 28 | libexpat1 \ 29 | libfontconfig1 \ 30 | libgbm1 \ 31 | libgcc1 \ 32 | libglib2.0-0 \ 33 | libgtk-3-0 \ 34 | libnspr4 \ 35 | libnss3 \ 36 | libpango-1.0-0 \ 37 | libpangocairo-1.0-0 \ 38 | libstdc++6 \ 39 | libx11-6 \ 40 | libx11-xcb1 \ 41 | libxcb1 \ 42 | libxcomposite1 \ 43 | libxcursor1 \ 44 | libxdamage1 \ 45 | libxext6 \ 46 | libxfixes3 \ 47 | libxi6 \ 48 | libxrandr2 \ 49 | libxrender1 \ 50 | libxss1 \ 51 | libxtst6 \ 52 | libgtk-3-0 53 | -------------------------------------------------------------------------------- /web_testing_go/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@bazel_gazelle//:def.bzl", "gazelle") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | exports_files(["LICENSE"]) 22 | 23 | gazelle( 24 | name = "gazelle", 25 | prefix = "github.com/bazelbuild/rules_webtesting", 26 | ) 27 | -------------------------------------------------------------------------------- /web_testing_go/MODULE.bazel: -------------------------------------------------------------------------------- 1 | module( 2 | name = "rules_web_testing_go", 3 | version = "0.4.0", 4 | ) 5 | 6 | bazel_dep( 7 | name = "rules_webtesting", 8 | ) 9 | 10 | local_path_override( 11 | module_name = "rules_webtesting", 12 | path = "..", 13 | ) 14 | 15 | bazel_dep( 16 | name = "bazel_skylib", 17 | version = "1.7.1", 18 | ) 19 | 20 | bazel_dep( 21 | name = "rules_go", 22 | version = "0.51.0-rc1", 23 | repo_name = "io_bazel_rules_go", 24 | ) 25 | 26 | bazel_dep(name = "gazelle", version = "0.40.0", repo_name = "bazel_gazelle") 27 | 28 | go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps") 29 | 30 | go_deps.from_file(go_mod = "@rules_webtesting//:go.mod") 31 | 32 | # All *direct* Go dependencies of the module have to be listed explicitly. 33 | use_repo(go_deps, "com_github_gorilla_mux", "com_github_tebeka_selenium") -------------------------------------------------------------------------------- /web_testing_go/testdata/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | 18 | package(default_testonly = True) 19 | 20 | licenses(["notice"]) # Apache 2.0 21 | 22 | filegroup( 23 | name = "testdata", 24 | srcs = glob(["*"]), 25 | visibility = ["//visibility:public"], 26 | ) 27 | -------------------------------------------------------------------------------- /web_testing_go/testdata/all-fields.json: -------------------------------------------------------------------------------- 1 | ../../testdata/all-fields.json -------------------------------------------------------------------------------- /web_testing_go/web/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 18 | load("@rules_webtesting//web:web.bzl", "web_test_config") 19 | 20 | package( 21 | default_testonly = True, 22 | default_visibility = ["//visibility:public"], 23 | ) 24 | 25 | bzl_library( 26 | name = "go", 27 | srcs = ["go.bzl"], 28 | deps = [ 29 | "@rules_webtesting//web/internal:wrap_web_test_suite", 30 | # should depend on @io_bazel_rules_go//go:def.bzl 31 | ], 32 | ) 33 | -------------------------------------------------------------------------------- /web_testing_go/web/go.bzl: -------------------------------------------------------------------------------- 1 | ../../go/web/go.bzl -------------------------------------------------------------------------------- /web_testing_go/webtest/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//web:go.bzl", "go_web_test_suite") 18 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 19 | 20 | licenses(["notice"]) # Apache 2.0 21 | 22 | go_library( 23 | name = "go_default_library", 24 | srcs = ["webtest.go"], 25 | importpath = "github.com/bazelbuild/rules_webtesting/web_testing_go/webtest", 26 | visibility = ["//visibility:public"], 27 | deps = [ 28 | "@rules_webtesting//go/bazel:go_default_library", 29 | "@rules_webtesting//go/metadata:go_default_library", 30 | "@com_github_tebeka_selenium//:go_default_library", 31 | ], 32 | ) 33 | 34 | go_web_test_suite( 35 | name = "go_default_test", 36 | srcs = [ 37 | "browserinfo_test.go", 38 | "webtest_test.go", 39 | ], 40 | browsers = [ 41 | "@rules_webtesting//browsers:chromium-local", 42 | "@rules_webtesting//browsers:firefox-local", 43 | "@rules_webtesting//browsers/sauce:chrome-win10", 44 | "@rules_webtesting//browsers/sauce:chrome-win10-connect", 45 | ], 46 | data = ["//testdata"], 47 | embed = [":go_default_library"], 48 | deps = ["@com_github_tebeka_selenium//:go_default_library"], 49 | ) 50 | -------------------------------------------------------------------------------- /web_testing_go/webtest/browserinfo_test.go: -------------------------------------------------------------------------------- 1 | ../../go/webtest/browserinfo_test.go -------------------------------------------------------------------------------- /web_testing_go/webtest/webtest.go: -------------------------------------------------------------------------------- 1 | ../../go/webtest/webtest.go -------------------------------------------------------------------------------- /web_testing_go/webtest/webtest_test.go: -------------------------------------------------------------------------------- 1 | ../../go/webtest/webtest_test.go -------------------------------------------------------------------------------- /web_testing_java/.bazelci/setup_ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2025 Google Inc. All Rights Reserved 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS-IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Script that can be used by CI server for testing rules_webtesting builds. 17 | set -ex 18 | 19 | sudo apt -y update 20 | sudo apt -y install libasound2 \ 21 | libdbus-glib-1-2 \ 22 | libatk-bridge2.0-0 \ 23 | libatk1.0-0 \ 24 | libc6 \ 25 | libcairo2 \ 26 | libcups2 \ 27 | libdbus-1-3 \ 28 | libexpat1 \ 29 | libfontconfig1 \ 30 | libgbm1 \ 31 | libgcc1 \ 32 | libglib2.0-0 \ 33 | libgtk-3-0 \ 34 | libnspr4 \ 35 | libnss3 \ 36 | libpango-1.0-0 \ 37 | libpangocairo-1.0-0 \ 38 | libstdc++6 \ 39 | libx11-6 \ 40 | libx11-xcb1 \ 41 | libxcb1 \ 42 | libxcomposite1 \ 43 | libxcursor1 \ 44 | libxdamage1 \ 45 | libxext6 \ 46 | libxfixes3 \ 47 | libxi6 \ 48 | libxrandr2 \ 49 | libxrender1 \ 50 | libxss1 \ 51 | libxtst6 \ 52 | libgtk-3-0 53 | -------------------------------------------------------------------------------- /web_testing_java/MODULE.bazel: -------------------------------------------------------------------------------- 1 | module( 2 | name = "rules_web_testing_java", 3 | version = "0.4.0", 4 | ) 5 | 6 | bazel_dep( 7 | name = "rules_webtesting", 8 | ) 9 | 10 | local_path_override( 11 | module_name = "rules_webtesting", 12 | path = "..", 13 | ) 14 | 15 | bazel_dep( 16 | name = "bazel_skylib", 17 | version = "1.7.1", 18 | ) 19 | 20 | bazel_dep(name = "rules_java", version = "7.2.0") 21 | 22 | bazel_dep( 23 | name = "rules_jvm_external", 24 | version = "6.6", 25 | ) 26 | 27 | maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") 28 | 29 | maven.install( 30 | artifacts = [ 31 | "com.google.guava:guava:33.2.1-jre", 32 | "org.seleniumhq.selenium:selenium-remote-driver:4.27.0", 33 | "org.seleniumhq.selenium:selenium-api:4.27.0", 34 | "junit:junit:4.13.2", 35 | ], 36 | ) 37 | 38 | use_repo(maven, "maven") 39 | -------------------------------------------------------------------------------- /web_testing_java/java/com/google/testing/bazel/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@rules_java//java:defs.bzl", "java_library") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | java_library( 22 | name = "bazel", 23 | srcs = glob(["*.java"]), 24 | visibility = ["//visibility:public"], 25 | deps = ["@maven//:com_google_guava_guava",], 26 | ) 27 | -------------------------------------------------------------------------------- /web_testing_java/java/com/google/testing/web/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | 18 | load("@rules_java//java:defs.bzl", "java_library") 19 | 20 | licenses(["notice"]) # Apache 2.0 21 | 22 | java_library( 23 | name = "web", 24 | testonly = True, 25 | srcs = glob(["*.java"]), 26 | visibility = ["//visibility:public"], 27 | deps = [ 28 | "@maven//:org_seleniumhq_selenium_selenium_api", 29 | "@maven//:org_seleniumhq_selenium_selenium_remote_driver", 30 | ], 31 | ) 32 | -------------------------------------------------------------------------------- /web_testing_java/javatests/com/google/testing/web/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//web:java.bzl", "java_web_test_suite") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | java_web_test_suite( 22 | name = "WebTestTest", 23 | srcs = ["WebTestTest.java"], 24 | browsers = [ 25 | "@rules_webtesting//browsers:chromium-local", 26 | "@rules_webtesting//browsers:firefox-local", 27 | "@rules_webtesting//browsers/sauce:chrome-win10", 28 | "@rules_webtesting//browsers/sauce:chrome-win10-connect", 29 | ], 30 | deps = [ 31 | "//java/com/google/testing/web", 32 | "@maven//:junit_junit", 33 | "@maven//:org_seleniumhq_selenium_selenium_api", 34 | ], 35 | ) 36 | -------------------------------------------------------------------------------- /web_testing_java/javatests/com/google/testing/web/WebTestTest.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ////////////////////////////////////////////////////////////////////////////// 16 | // 17 | package com.google.testing.web; 18 | 19 | import org.junit.Test; 20 | import org.junit.runner.RunWith; 21 | import org.junit.runners.JUnit4; 22 | import org.openqa.selenium.WebDriver; 23 | 24 | @RunWith(JUnit4.class) 25 | public class WebTestTest { 26 | 27 | @Test 28 | public void newWebDriverSession() { 29 | WebTest wt = new WebTest(); 30 | WebDriver driver = wt.newWebDriverSession(); 31 | driver.get(wt.HTTPAddress().resolve("/healthz").toString()); 32 | driver.quit(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /web_testing_java/web/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 18 | load("@rules_webtesting//web:web.bzl", "web_test_config") 19 | 20 | package( 21 | default_testonly = True, 22 | default_visibility = ["//visibility:public"], 23 | ) 24 | 25 | bzl_library( 26 | name = "java", 27 | srcs = ["java.bzl"], 28 | deps = ["@rules_webtesting//web/internal:wrap_web_test_suite"], 29 | ) 30 | -------------------------------------------------------------------------------- /web_testing_java/web/java.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Web Test rules for Java.""" 15 | 16 | load("@rules_webtesting//web/internal:constants.bzl", "DEFAULT_WRAPPED_TEST_TAGS") 17 | load("@rules_webtesting//web/internal:wrap_web_test_suite.bzl", "wrap_web_test_suite") 18 | 19 | def java_web_test_suite(name, java_test_tags = DEFAULT_WRAPPED_TEST_TAGS, test_class = None, **kwargs): 20 | """Defines a test_suite of web_test targets that wrap a java_test target. 21 | 22 | Args: 23 | name: The base name of the test. 24 | java_test_tags: A list of test tag strings to use for the java_test target. 25 | test_class: Optional; default computed from name and blaze package. 26 | **kwargs: Arguments for wrapped_web_test_suite 27 | """ 28 | if test_class == None: 29 | test_package = native.package_name().replace("javatests/", "") 30 | test_package = test_package.replace("/", ".") 31 | test_class = test_package + "." + name 32 | 33 | wrap_web_test_suite( 34 | name = name, 35 | rule = native.java_test, 36 | test_class = test_class, 37 | wrapped_test_tags = java_test_tags, 38 | **kwargs 39 | ) 40 | -------------------------------------------------------------------------------- /web_testing_python/.bazelci/setup_ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2025 Google Inc. All Rights Reserved 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS-IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Script that can be used by CI server for testing rules_webtesting builds. 17 | set -ex 18 | 19 | sudo apt -y update 20 | sudo apt -y install libasound2 \ 21 | libdbus-glib-1-2 \ 22 | libatk-bridge2.0-0 \ 23 | libatk1.0-0 \ 24 | libc6 \ 25 | libcairo2 \ 26 | libcups2 \ 27 | libdbus-1-3 \ 28 | libexpat1 \ 29 | libfontconfig1 \ 30 | libgbm1 \ 31 | libgcc1 \ 32 | libglib2.0-0 \ 33 | libgtk-3-0 \ 34 | libnspr4 \ 35 | libnss3 \ 36 | libpango-1.0-0 \ 37 | libpangocairo-1.0-0 \ 38 | libstdc++6 \ 39 | libx11-6 \ 40 | libx11-xcb1 \ 41 | libxcb1 \ 42 | libxcomposite1 \ 43 | libxcursor1 \ 44 | libxdamage1 \ 45 | libxext6 \ 46 | libxfixes3 \ 47 | libxi6 \ 48 | libxrandr2 \ 49 | libxrender1 \ 50 | libxss1 \ 51 | libxtst6 \ 52 | libgtk-3-0 53 | -------------------------------------------------------------------------------- /web_testing_python/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@python_versions//3.11:defs.bzl", "compile_pip_requirements") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | exports_files(["LICENSE"]) 22 | 23 | compile_pip_requirements( 24 | name = "requirements", 25 | requirements_in = "requirements.in", 26 | requirements_txt = "requirements_lock.txt", 27 | requirements_windows = "requirements_lock_windows.txt", 28 | ) 29 | -------------------------------------------------------------------------------- /web_testing_python/MODULE.bazel: -------------------------------------------------------------------------------- 1 | module( 2 | name = "rules_web_testing_python", 3 | version = "0.4.0", 4 | ) 5 | 6 | bazel_dep( 7 | name = "bazel_skylib", 8 | version = "1.7.1", 9 | ) 10 | 11 | bazel_dep( 12 | name = "rules_webtesting", 13 | ) 14 | 15 | local_path_override( 16 | module_name = "rules_webtesting", 17 | path = "..", 18 | ) 19 | 20 | bazel_dep( 21 | name = "rules_python", 22 | version = "1.0.0", 23 | ) 24 | 25 | python = use_extension("@rules_python//python/extensions:python.bzl", "python") 26 | 27 | python.toolchain( 28 | is_default = True, 29 | python_version = "3.11", 30 | ) 31 | 32 | use_repo(python, "python_3_11", "python_versions") 33 | 34 | pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") 35 | 36 | pip.parse( 37 | hub_name = "rules_webtesting_py_deps", 38 | python_version = "3.11", 39 | requirements_lock = "//:requirements_lock.txt", 40 | requirements_windows = "requirements_lock_windows.txt", 41 | ) 42 | 43 | use_repo(pip, "rules_webtesting_py_deps") 44 | -------------------------------------------------------------------------------- /web_testing_python/requirements.in: -------------------------------------------------------------------------------- 1 | selenium==3.141.0 2 | -------------------------------------------------------------------------------- /web_testing_python/requirements_lock.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with Python 3.11 3 | # by the following command: 4 | # 5 | # bazel run //:requirements.update 6 | # 7 | selenium==3.141.0 \ 8 | --hash=sha256:2d7131d7bc5a5b99a2d9b04aaf2612c411b03b8ca1b1ee8d3de5845a9be2cb3c \ 9 | --hash=sha256:deaf32b60ad91a4611b98d8002757f29e6f2c2d5fcaf202e1c9ad06d6772300d 10 | # via -r requirements.in 11 | urllib3==2.2.3 \ 12 | --hash=sha256:ca899ca043dcb1bafa3e262d73aa25c465bfb49e0bd9dd5d59f1d0acba2f8fac \ 13 | --hash=sha256:e7d814a81dad81e6caf2ec9fdedb284ecc9c73076b62654547cc64ccdcae26e9 14 | # via selenium 15 | -------------------------------------------------------------------------------- /web_testing_python/requirements_lock_windows.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile with Python 3.11 3 | # by the following command: 4 | # 5 | # bazel run //:requirements.update 6 | # 7 | selenium==3.141.0 \ 8 | --hash=sha256:2d7131d7bc5a5b99a2d9b04aaf2612c411b03b8ca1b1ee8d3de5845a9be2cb3c \ 9 | --hash=sha256:deaf32b60ad91a4611b98d8002757f29e6f2c2d5fcaf202e1c9ad06d6772300d 10 | # via -r requirements.in 11 | urllib3==2.2.3 \ 12 | --hash=sha256:ca899ca043dcb1bafa3e262d73aa25c465bfb49e0bd9dd5d59f1d0acba2f8fac \ 13 | --hash=sha256:e7d814a81dad81e6caf2ec9fdedb284ecc9c73076b62654547cc64ccdcae26e9 14 | # via selenium 15 | -------------------------------------------------------------------------------- /web_testing_python/testing/web/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//web:py.bzl", "py_web_test_suite") 18 | load("@rules_python//python:defs.bzl", "py_library") 19 | 20 | licenses(["notice"]) # Apache 2.0 21 | 22 | py_library( 23 | name = "web", 24 | testonly = True, 25 | srcs = glob( 26 | ["*.py"], 27 | exclude = ["*_test.py"], 28 | ), 29 | visibility = ["//visibility:public"], 30 | deps = [ 31 | "@rules_webtesting_py_deps//selenium", 32 | ], 33 | ) 34 | 35 | py_web_test_suite( 36 | name = "webtest_test", 37 | srcs = ["webtest_test.py"], 38 | browsers = [ 39 | "@rules_webtesting//browsers:chromium-local", 40 | "@rules_webtesting//browsers:firefox-local", 41 | "@rules_webtesting//browsers/sauce:chrome-win10", 42 | "@rules_webtesting//browsers/sauce:chrome-win10-connect", 43 | ], 44 | tags = { 45 | "chromium-local": [ 46 | "native", 47 | ], 48 | "chrome-win10": [ 49 | "exclusive", 50 | "sauce", 51 | "notravis", 52 | ], 53 | "chrome-win10-connect": [ 54 | "exclusive", 55 | "noci", 56 | "sauce", 57 | ], 58 | "firefox-local": [ 59 | "native", 60 | ], 61 | }, 62 | deps = [":web"], 63 | ) 64 | -------------------------------------------------------------------------------- /web_testing_python/testing/web/debugger/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | licenses(["notice"]) # Apache 2.0 18 | 19 | load("@rules_python//python:defs.bzl", "py_binary") 20 | 21 | py_binary( 22 | name = "debugger", 23 | srcs = glob(["*.py"]), 24 | ) 25 | -------------------------------------------------------------------------------- /web_testing_python/testing/web/webtest.py: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Browser provisioning and information API. 15 | 16 | Provision a browser: 17 | from testing.web import webtest 18 | 19 | driver = webtest.new_webdriver_session() 20 | 21 | Provision a browser with capabilities: 22 | capabilities = {"webdriver.logging.profiler.enabled": true} 23 | driver = webtest.new_webdriver_session(capabilities) 24 | """ 25 | import os 26 | 27 | from selenium.webdriver.remote import remote_connection 28 | from selenium.webdriver.remote import webdriver 29 | 30 | 31 | def new_webdriver_session(capabilities=None): 32 | """Provisions a new WebDriver session. 33 | 34 | Args: 35 | capabilities: a dict with the json capabilities desired for this browser 36 | session. 37 | 38 | Returns: 39 | A new WebDriver connected to a browser defined by the web test 40 | environment. 41 | """ 42 | capabilities = capabilities or {} 43 | address = os.environ['WEB_TEST_WEBDRIVER_SERVER'].rstrip('/') 44 | 45 | # Set the timeout for WebDriver http requests so that the socket default 46 | # timeout is not used. 47 | remote_connection.RemoteConnection.set_timeout(450) 48 | 49 | return webdriver.WebDriver(address, desired_capabilities=capabilities) 50 | 51 | 52 | def http_address(): 53 | """Return the HTTP address of WTL.""" 54 | return os.environ['WEB_TEST_HTTP_SERVER'] 55 | 56 | 57 | def https_address(): 58 | """Return the HTTPS address of WTL.""" 59 | return os.environ['WEB_TEST_HTTPS_SERVER'] 60 | -------------------------------------------------------------------------------- /web_testing_python/testing/web/webtest_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Tests for testing.web.webtest.""" 15 | 16 | import unittest 17 | 18 | from testing.web import webtest 19 | 20 | 21 | class BrowserTest(unittest.TestCase): 22 | 23 | def testBrowserProvisioningNoCaps(self): 24 | driver = webtest.new_webdriver_session() 25 | 26 | try: 27 | driver.get(webtest.http_address() + "/healthz") 28 | self.assertTrue(driver.current_url) 29 | finally: 30 | driver.quit() 31 | 32 | def testBrowserProvisioningWithCaps(self): 33 | capabilities = { 34 | "acceptInsecureCerts": False, 35 | "pageLoadStrategy": "normal", 36 | } 37 | driver = webtest.new_webdriver_session(capabilities) 38 | 39 | try: 40 | driver.get(webtest.http_address() + "/healthz") 41 | self.assertTrue(driver.current_url) 42 | finally: 43 | driver.quit() 44 | 45 | 46 | if __name__ == "__main__": 47 | unittest.main() 48 | -------------------------------------------------------------------------------- /web_testing_python/web/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 18 | load("@rules_webtesting//web:web.bzl", "web_test_config") 19 | 20 | package( 21 | default_testonly = True, 22 | default_visibility = ["//visibility:public"], 23 | ) 24 | 25 | bzl_library( 26 | name = "py", 27 | srcs = ["py.bzl"], 28 | deps = ["@rules_webtesting//web/internal:wrap_web_test_suite"], 29 | ) 30 | -------------------------------------------------------------------------------- /web_testing_python/web/py.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Web Test rules for Python.""" 15 | 16 | load("@rules_webtesting//web/internal:constants.bzl", "DEFAULT_WRAPPED_TEST_TAGS") 17 | load("@rules_webtesting//web/internal:wrap_web_test_suite.bzl", "wrap_web_test_suite") 18 | 19 | def py_web_test_suite(name, py_test_tags = DEFAULT_WRAPPED_TEST_TAGS, main = None, **kwargs): 20 | """Defines a test_suite of web_test targets that wrap a py_test target. 21 | 22 | Args: 23 | name: The base name of the test. 24 | py_test_tags: A list of test tag strings to use for the py_test target. 25 | main: Optional; default computed from name. 26 | **kwargs: Arguments for wrapped_web_test_suite 27 | """ 28 | if main == None: 29 | main = name + ".py" 30 | 31 | wrap_web_test_suite( 32 | name = name, 33 | main = main, 34 | rule = native.py_test, 35 | wrapped_test_tags = py_test_tags, 36 | **kwargs 37 | ) 38 | -------------------------------------------------------------------------------- /web_testing_scala/.bazelci/setup_ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2025 Google Inc. All Rights Reserved 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS-IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Script that can be used by CI server for testing rules_webtesting builds. 17 | set -ex 18 | 19 | sudo apt -y update 20 | sudo apt -y install libasound2 \ 21 | libdbus-glib-1-2 \ 22 | libatk-bridge2.0-0 \ 23 | libatk1.0-0 \ 24 | libc6 \ 25 | libcairo2 \ 26 | libcups2 \ 27 | libdbus-1-3 \ 28 | libexpat1 \ 29 | libfontconfig1 \ 30 | libgbm1 \ 31 | libgcc1 \ 32 | libglib2.0-0 \ 33 | libgtk-3-0 \ 34 | libnspr4 \ 35 | libnss3 \ 36 | libpango-1.0-0 \ 37 | libpangocairo-1.0-0 \ 38 | libstdc++6 \ 39 | libx11-6 \ 40 | libx11-xcb1 \ 41 | libxcb1 \ 42 | libxcomposite1 \ 43 | libxcursor1 \ 44 | libxdamage1 \ 45 | libxext6 \ 46 | libxfixes3 \ 47 | libxi6 \ 48 | libxrandr2 \ 49 | libxrender1 \ 50 | libxss1 \ 51 | libxtst6 \ 52 | libgtk-3-0 53 | -------------------------------------------------------------------------------- /web_testing_scala/MODULE.bazel: -------------------------------------------------------------------------------- 1 | module( 2 | name = "rules_web_testing_scala", 3 | version = "0.4.0", 4 | ) 5 | 6 | bazel_dep( 7 | name = "rules_webtesting", 8 | ) 9 | 10 | local_path_override( 11 | module_name = "rules_webtesting", 12 | path = "..", 13 | ) 14 | 15 | bazel_dep( 16 | name = "rules_web_testing_java", 17 | ) 18 | 19 | local_path_override( 20 | module_name = "rules_web_testing_java", 21 | path = "../web_testing_java", 22 | ) 23 | 24 | bazel_dep( 25 | name = "bazel_skylib", 26 | version = "1.7.1", 27 | ) 28 | 29 | ##### Scala dependencies ##### 30 | bazel_dep( 31 | name = "rules_scala", 32 | repo_name = "io_bazel_rules_scala", 33 | ) 34 | 35 | # TODO: Switch to a release version once it's available in BCR. 36 | # Otherwise, the root module has to declare the same override. 37 | git_override( 38 | module_name = "rules_scala", 39 | commit = "219e63983e8e483e66ebf70372969ba227382001", 40 | remote = "https://github.com/mbland/rules_scala", 41 | ) 42 | 43 | scala_deps = use_extension( 44 | "@io_bazel_rules_scala//scala/extensions:deps.bzl", 45 | "scala_deps", 46 | ) 47 | 48 | scala_deps.settings( 49 | fetch_sources = True, 50 | ) 51 | 52 | scala_deps.toolchains( 53 | scalatest = True, 54 | ) 55 | 56 | ##### Java dependencies ##### 57 | bazel_dep( 58 | name = "rules_jvm_external", 59 | version = "6.6", 60 | ) 61 | 62 | maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") 63 | 64 | maven.install( 65 | artifacts = [ 66 | "com.google.guava:guava:33.2.1-jre", 67 | "org.seleniumhq.selenium:selenium-remote-driver:4.27.0", 68 | "org.seleniumhq.selenium:selenium-api:4.27.0", 69 | "junit:junit:4.13.2", 70 | ], 71 | ) 72 | 73 | use_repo(maven, "maven") 74 | -------------------------------------------------------------------------------- /web_testing_scala/scalatests/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("//web:scala.bzl", "scala_web_test_suite") 18 | 19 | licenses(["notice"]) # Apache 2.0 20 | 21 | scala_web_test_suite( 22 | name = "WebTestTest", 23 | srcs = ["WebTestTest.scala"], 24 | browsers = [ 25 | "@rules_webtesting//browsers:chromium-local", 26 | "@rules_webtesting//browsers:firefox-local", 27 | "@rules_webtesting//browsers/sauce:chrome-win10", 28 | "@rules_webtesting//browsers/sauce:chrome-win10-connect", 29 | ], 30 | deps = [ 31 | "@maven//:junit_junit", 32 | "@maven//:org_seleniumhq_selenium_selenium_api", 33 | "@rules_web_testing_java//java/com/google/testing/web", 34 | ], 35 | ) 36 | -------------------------------------------------------------------------------- /web_testing_scala/scalatests/WebTestTest.scala: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // ////////////////////////////////////////////////////////////////////////////// 16 | // 17 | package com.google.testing.web; 18 | 19 | import org.openqa.selenium.WebDriver 20 | import org.scalatest.wordspec._ 21 | 22 | class WebTestTest extends AnyWordSpec { 23 | 24 | "A WebDriver" should { 25 | "start and stop" in { 26 | val driver = new WebTest().newWebDriverSession() 27 | driver.quit() 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /web_testing_scala/web/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | ################################################################################ 16 | # 17 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 18 | load("@rules_webtesting//web:web.bzl", "web_test_config") 19 | 20 | package( 21 | default_testonly = True, 22 | default_visibility = ["//visibility:public"], 23 | ) 24 | 25 | bzl_library( 26 | name = "scala", 27 | srcs = ["scala.bzl"], 28 | deps = [ 29 | "@rules_webtesting//web/internal:wrap_web_test_suite", 30 | # should depend on @io_bazel_rules_scala//scala:scala.bzl 31 | ], 32 | ) 33 | -------------------------------------------------------------------------------- /web_testing_scala/web/scala.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Web Test rules for Java.""" 15 | 16 | load("@io_bazel_rules_scala//scala:scala.bzl", "scala_test") 17 | load("@rules_webtesting//web/internal:constants.bzl", "DEFAULT_WRAPPED_TEST_TAGS") 18 | load("@rules_webtesting//web/internal:wrap_web_test_suite.bzl", "wrap_web_test_suite") 19 | 20 | def scala_web_test_suite(name, scala_test_tags = DEFAULT_WRAPPED_TEST_TAGS, **kwargs): 21 | """Defines a test_suite of web_test targets that wrap a java_test target. 22 | 23 | Args: 24 | name: The base name of the test. 25 | scala_test_tags: A list of test tag strings to use for the scala_test 26 | target. 27 | **kwargs: Arguments for wrapped_web_test_suite 28 | """ 29 | wrap_web_test_suite( 30 | name = name, 31 | rule = scala_test, 32 | wrapped_test_tags = scala_test_tags, 33 | **kwargs 34 | ) 35 | --------------------------------------------------------------------------------