Contributing • Installing • Building • Developing • Testing • Documenting • Releasing
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.
- Bazelisk, a Bazel wrapper that automatically downloads
the version of Bazel specified in
.bazelversionfile and transparently passes through all command-line arguments to the real Bazel binary. - Java JDK version 17 or greater (e.g., Java 17 Temurin)
- Set
JAVA_HOMEenvironment variable to location of Java executable (the JDK not the JRE) - To test this, try running the command
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.
- Set
- Xcode including the command-line tools. Install the latest version using:
xcode-select --install - Rosetta for Apple Silicon Macs. Add
build --host_platform=//:rosettato the.bazelrc.localfile. 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.
Click to see Current Windows Setup Requirements
This script will ensure a complete ready to execute developer environment. (nothing is installed or set that is already present unless otherwise prompted)
- Open Powershell as an Administrator
- Execute:
Set-ExecutionPolicy Bypass -Scope Process -Forceto allow running the script in the process - Navigate to the directory you want to clone Selenium in, or the parent directory of an already cloned Selenium repo
- Download and execute this script in the powershell terminal: [scripts/dev-environment-setup.ps1]`
- Allow running scripts in Selenium in general:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned - Enable Developer Mode:
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1" - Install MSYS2, which is an alternative shell environment that provides Unix-like commands
- Add bin directory to
PATHenvironment variable (e.g.,"C:\tools\msys64\usr\bin") - Add
bash.exelocation as theBAZEL_SHenvironment variable (e.g.,"C:\tools\msys64\usr\bin\bash.exe")
- Add bin directory to
- Install the latest version of Visual Studio Community
- Use the visual studio installer to modify and add the "Desktop development with C++" Workload
- Add Visual C++ build tools installation directory location to
BAZEL_VCenvironment variable (e.g."C:\Program Files\Microsoft Visual Studio\2022\Community\VC") - Add Visual C++ Build tools version to
BAZEL_VC_FULL_VERSIONenvironment variable (this can be discovered from the directory name in"$BAZEL_VC\Tools\MSVC\<BAZEL_VC_FULL_VERSION>")
- Add support for long file names (bazel has a lot of nested directories that can exceed default limits in Windows)
- Enable Long Paths support with these 2 registry commands:
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"
- Allow Bazel to create short name versions of long file paths:
fsutil 8dot3name set 0 - Set bazel output to
C:/tmpinstead of nested inside project directory:- Create a file
selenium/.bazelrc.windows.local - Add "startup --output_user_root=C:/tmp" to the file
- Create a file
If 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.
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 gridTo make things more simple, building each of the bindings is available with this ./go command:
./go <language>:buildMost 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:installDependencies are defined in the file MODULE.bazel.
To update a dependency, modify the version in the MODULE.bazel file and run:
RULES_JVM_EXTERNAL_REPIN=1 bazel run @maven//:pinTo automatically update and pin new dependencies, run:
./go java:updateWe follow the PEP8 Style Guide for Python Code (except we use a 120 character line length).
This is checked and enforced with ruff, a linting/formatting tool.
There is also an auto-formatting script that can be run: ./scripts/format.sh
To run Python code locally without building/installing the package, you must first install the dependencies:
pip install -r py/requirements_lock.txtThen, build the generated files and copy them into your local source tree:
./go py:local_devAfter that, you can import the selenium package directly from source from the py directory.
Instead of running from source, you can build and install the selenium package (wheel) locally:
./go py:installThis will attempt to install into the global Python site-packages directory,
which might not be writable. To avoid this, you should create and activate a
virtual environment
before installing.
Instead of using irb, you can create an interactive REPL with all gems loaded using: bazel run //rb:console
If you want to debug code, you can do it via debug gem:
- Add
binding.breakto the code where you want the debugger to start. - Run tests with
ruby_debugconfiguration:bazel test --config ruby_debug <test>. - When debugger starts, run the following in a separate terminal to connect to debugger:
bazel-selenium/external/bundle/bin/rdbg -AIf you want to use RubyMine for development, you can configure it use Bazel artifacts:
- Open
rb/as a main project directory. - From the
selenium(parent) directory, run./go rb:local_devto create up-to-date artifacts. - In Settings / Languages & Frameworks / Ruby SDK and Gems add new Interpreter pointing to
../bazel-selenium/external/rules_ruby++ruby+ruby/dist/bin/ruby. - You should now be able to run and debug any spec. It uses Chrome by default, but you can alter it using environment variables specified in Ruby Testing section below.
Rust Bazel dependencies are generated directly from rust/Cargo.toml and rust/Cargo.lock.
There are a number of bazel configurations specific for testing.
Here are examples of arguments we make use of in testing the Selenium code:
--pin_browsers=false- use Selenium Manager to locate browsers/drivers--headless- run browsers in headless mode (supported be Chrome, Edge and Firefox)--flaky_test_attempts 3- re-run failed tests up to 3 times--local_test_jobs 1- control parallelism of tests--cache_test_results=no,-t-- disable caching of test results and re-runs all of them--test_output all- print all output from the tests, not just errors--test_output streamed- run all tests one by one and print its output immediately--test_env FOO=bar- pass extra environment variable to test process--run_under="xvfb-run -a"- prefix to insert before the execution
Selenium tests can be filtered by size:
- small — typically unit tests where no browser is opened
- large — typically tests that actually drive a browser
- medium — tests that are more involved than simple unit tests, but not fully driving a browser
These can be filtered using the test_size_filters argument like this:
bazel test //<language>/... --test_size_filters=smallTests can also be filtered by tag like:
bazel test //<language>/... --test_tag_filters=this,-not-thisIf there are multiple --test_tag_filters, only the last one is considered,
so be careful if also using an inherited config
Language specific testing guides can be found in a TESTING.md file in the applicable directory.
Click to see Linux Testing Requirements
By default, Bazel runs these tests in your current X-server UI. If you prefer, you can alternatively run them in a virtual or nested X-server.
- Run the X server
Xvfb :99orXnest :99 - Run a window manager, for example,
DISPLAY=:99 jwm - Run the tests you are interested in:
bazel test --test_env=DISPLAY=:99 //java/... --test_tag_filters=chromeAn easy way to run tests in a virtual X-server is to use Bazel's --run_under
functionality:
bazel test --run_under="xvfb-run -a" //java/...
API documentation can be found here:
To update API documentation for a specific language: ./go <language>:docs
To update all documentation: ./go all:docs
The full process for doing a release can be found in the wiki
Releasing is a combination of building and publishing, which often requires coordination of multiple executions
and additional processing.
As discussed in the Building section, we use Rake tasks with the ./go command for these things.
These ./go commands include the --stamp argument to provide necessary information about the constructed asset.
You can build and release everything with:
./go all:releaseTo build and release a specific language:
./go <language>:releaseIf you have access to the Selenium EngFlow repository, you can have the assets built remotely and downloaded locally using:
./go all:release['--config', 'release']