Loading repository data…
Loading repository data…
SeleniumHQ / repository
A browser automation framework and ecosystem.
Selenium is an umbrella project encapsulating a variety of tools and libraries enabling web browser automation. Selenium specifically provides an infrastructure for the W3C WebDriver specification — a platform and language-neutral coding interface compatible with all major web browsers.
The project is made possible by volunteer contributors who've generously donated thousands of hours in code development and upkeep.
This README is for developers interested in contributing to the project. For people looking to get started using Selenium, please check out our User Manual for detailed examples and descriptions, and if you get stuck, there are several ways to Get Help.
Please read CONTRIBUTING.md before submitting your pull requests.
These are the requirements to create your own local dev environment to contribute to Selenium.
.bazelversion file and transparently passes through all
command-line arguments to the real Bazel binary.JAVA_HOME environment variable to location of Java executable (the JDK not the JRE)javac. This command won't exist if you only have the JRE
installed. If you're met with a list of command-line options, you're referencing the JDK properly.xcode-select --installbuild --host_platform=//:rosetta to the .bazelrc.local file. We are working
to make sure this isn't required in the long run.Several years ago Jim Evans published a great article on Setting Up a Windows Development Environment for the Selenium .NET Language Bindings; This article is out of date, but it includes more detailed descriptions and screenshots that some people might find useful.
This script will ensure a complete ready to execute developer environment. (nothing is installed or set that is already present unless otherwise prompted)
Set-ExecutionPolicy Bypass -Scope Process -Force to allow running the script in the processSet-ExecutionPolicy -ExecutionPolicy RemoteSigned
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"
PATH environment variable (e.g., "C:\tools\msys64\usr\bin")bash.exe location as the BAZEL_SH environment variable (e.g., "C:\tools\msys64\usr\bin\bash.exe")BAZEL_VC environment variable (e.g. "C:\Program Files\Microsoft Visual Studio\2022\Community\VC")BAZEL_VC_FULL_VERSION environment variable (this can be discovered from the directory name in "$BAZEL_VC\Tools\MSVC\<BAZEL_VC_FULL_VERSION>")reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor" /t REG_DWORD /f /v "DisableUNCCheck" /d "1"
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem" /t REG_DWORD /f /v "LongPathsEnabled" /d "1"
fsutil 8dot3name set 0C:/tmp instead of nested inside project directory:
selenium/.bazelrc.windows.localIf you want to contribute to the project, but do not want to set up your own local dev environment, there are two alternatives available.
Rather than creating your own local dev environment, GitPod provides a ready to use environment for you.
As an alternative you can build a Dev Container - basically a docker container - suitable for building and testing Selenium using the devcontainer.json in the .devcontainer directory. Supporting IDEs like VS Code or IntelliJ IDEA should point you to how such a container can be created.
You can also build a Docker image suitable for building and testing Selenium using the Dockerfile in the dev image directory.
Bazel keeps its build outputs and downloaded dependencies under each checkout by default, which means working from multiple worktrees re-downloads dependencies and rebuilds artifacts. Pointing Bazel at user-level caches avoids that.
Add the following to /path/to/your/home/.bazelrc
common --disk_cache=/path/to/your/home/.cache/bazel-disk
common --repository_cache=/path/to/your/home/.cache/bazel-repo
--disk_cache stores compiled action outputs; --repository_cache stores downloaded external
dependencies (e.g. http_archive tarballs). Both directories grow unbounded over time — prune them
periodically if disk space matters. Keep the cache on the same filesystem as your checkouts so Bazel
can hardlink instead of copy.
Bazel also creates a separate output base (compiled outputs, analysis cache, and the Bazel server) per checkout path. Unlike the caches above, it is not removed when you delete a worktree — so frequently created and discarded worktrees leak gigabytes of stale output.
On macOS/Linux, make a worktree self-cleaning by pointing its output base inside the worktree. Add
this to that worktree's .bazelrc.local:
startup --output_base=.local/bazel-out
.local/ is gitignored and excluded in .bazelignore, so removing the worktree removes its output
base with it. The shared --disk_cache/--repository_cache above still keep downloads and action
outputs shared across worktrees.
(Windows users should instead keep startup --output_user_root=C:/tmp in .bazelrc.windows.local as
described above, to avoid path-length limits — do not nest the output base deeper inside the repo on
Windows.)
Selenium is built using a common build tool called Bazel, to allow us to easily manage dependency downloads, generate required binaries, build and release packages, and execute tests; all in a fast, efficient manner. For a more detailed discussion, read Simon Stewart's article on Building Selenium
Often we wrap Bazel commands with our custom Rake wrapper. These are run with the ./go command.
The common Bazel commands are:
bazel build — evaluates dependencies, compiles source files and generates output files for the specified target.
It's used to create executable binaries, libraries, or other artifacts.bazel run — builds the target and then executes it.
It's typically used for targets that produce executable binaries.bazel test — builds and runs the target in a context with additional testing functionalitybazel query — identifies available targets for the provided path.Each module that can be built is defined in a BUILD.bazel file. To execute the module you refer to it starting with a
//, then include the relative path to the file that defines it, then :, then the name of the target.
For example, the target to build the Grid is named executable-grid and it is
defined in the 'selenium/java/src/org/openqa/selenium/grid/BAZEL.build' file.
So to build the grid you would run: bazel build //java/src/org/openqa/selenium/grid:executable-grid.
The Bazel documentation has a handy guide for various shortcuts and all the ways to build multiple targets, which Selenium makes frequent use of.
To build everything for a given language:
bazel build //<language>/...
To build just the grid there is an alias name to use (the log will show where the output jar is located):
bazel build grid
To make things more simple, building each of the bindings is available with this ./go command:
./go <language>:build
Most of the team uses Intellij for their day-to-day editing. If you're working in IntelliJ, then we highly recommend installing the Bazel IJ plugin which is documented on its own site.
To use Selenium with the IntelliJ Bazel plugin, import the repository as a Bazel project, and select the project
view file from the scripts directory. ij.bazelproject for Mac/Linux and ij-win.bazelproject for Windows.
We also use Google Java Format for linting, so using the Google Java Formatter Plugin is useful;
there are a few steps to get it working, so read their configuration documentation.
There is also an auto-formatting script that can be run: ./scripts/format.sh
While Selenium is not built with Maven, you can build and install the Selenium pieces
for Maven to use locally by deploying to your local maven repository (~/.m2/repository), using:
./go java:install
De