Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save titusfortner/47d0d660c19cda96210985b6e496f8b2 to your computer and use it in GitHub Desktop.
Save titusfortner/47d0d660c19cda96210985b6e496f8b2 to your computer and use it in GitHub Desktop.
Building Selenium on Windows 10

Guide #1: http://jimevansmusic.blogspot.com/2020/04/setting-up-windows-development.html
Guide #2: https://gist.github.com/titusfortner/aec103e9b02709f771497fdb8b21154c

Set Up Command Line Environment

  • Launch Powershell as Administrator
  • Enable Developer Mode : reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"
  • Enable UNC Path support: reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor" /t REG_DWORD /f /v "DisableUNCCheck" /d "1"
  • Install Microsoft Visual Studio 2022 Community Edition:
  • Launch Developer Powershell as Administrator
  • Install Chocolatey (package manager): https://chocolatey.org/install
  • Install Git: choco install git
  • Install OpenJDK 11: choco install openjdk11
  • Install Bazelisk: choco install bazelisk
  • Install Buildifier: choco install buildifier
  • Install MSYS2: choco install msys2 --params "/InstallDir=C:\tools\msys64"
  • Add System Environment Variables:
    • Prefix PATH with "C:\tools\msys64\usr\bin"
    • Set BAZEL_SH to "C:\tools\msys64\usr\bin\bash.exe"
    • Set BAZEL_VC to "C:\Program Files\Microsoft Visual Studio\2022\Community\VC" (this might be in x86 folder instead)
    • Set BAZEL_VC_FULL_VERSION to version of command line tools (e.g. - 14.35.32215)
      • NOTE: This value should be set to the name of the folder found inside the $BAZEL_VC/Tools/MSVC folder
  • Create a projects root folder and navigate into it: [IO.Directory]::CreateDirectory("Projects"); cd Projects
  • Clone the Selenium project repo: git clone https://github.com/SeleniumHQ/selenium
  • Navigate into Selenium repo: cd selenium
  • When running tests, specify the Java Runtime Version with this command line option: --java_runtime_version=17

Install and Configure IDE

  • Install IntellJ IDEA Community Edition
  • Launch IntelliJ IDEA
  • Install Bazel for IntelliJ plugin
  • Configure Bazel setting:
    • Bazel binary location: C:\ProgramData\chocolatey\bin\bazelisk.exe
    • Buildifier binary location: C:\ProgramData\chocolatey\lib\buildifier\buildifier.exe
  • To run tests, specify the Java Runtime Version with this Run Configuration Bazel Flag: --java_runtime_version=17

Regarding Required Registry Setting and Java Runtime Version

By default, the Windows file system has a 260-character limit on the length of file paths. However, Windows 10 provides the ability to recognize UNC (Universal Naming Convention) file path prefixes, including the \\?\ prefix which enables specification of extended paths up to 32,767 characters long. The ironically-named DisableUNCCheck setting established by one of the early steps in the setup process described above enables support for extended file paths, which Bazel uses to avoid default path length limitations that might otherwise result in build failures due to path truncation.

In a related issue, support for UNC path specifications in Java 11 is defective, resulting in failures when executing command line utilities like jar. This defect has been resolved in subsequent releases of Java, working as expected in Java 17. The Selenium project is currently configured to run its Java unit tests in Java 11, which can result in test compilation failures like this:

exited with error code 1
Executing tests from //java/test/org/openqa/selenium/grid/node/config:NodeOptionsTest
-----------------------------------------------------------------------------
LAUNCHER ERROR: Couldn't create classpath jar: C:\Users\...

The source of this failure appears to be path truncation in the jar utility, which causes the test run to fail during the build phase. This can be avoided by overriding the default Java Runtime Version with this Bazel option: --java_runtime_version=17

This option should be specified for both command line execution in Developer Powershell, and in IntelliJ IDEA in the Run/Debug Configuration in the Bazel flags field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment