Recently Microsoft Windows improved their Linux subsystem support with the release of WSL (Windows Subsystem for Linux) 2. This update greatly improves the subsystem performance and available features. These improvements mean, amongst other things, that you can now run your Selenium based tests on the subsystem.
You may ask why on earth would you want to run Selenium based test on the WSL 2 subsystem. There are three main answer to this question. First, this helps assure that your tests can run cross OS. Cross OS support means you have more options and flexibility for running your tests. Second, the tests run much faster. The Linux subsystem has relatively low overhead and surprisingly good performance. And yes, I have found that tests run faster on WSL 2 than on the host Windows OS itself. The final/real reason is because we can.
Notes* The setup outlined in this post only works for headless versions of Chrome or Firefox. I suspect, but have not confirmed, that with extra work you may be able to run tests with running headless.
How to Set This Up for Yourself
You will need the Windows 10 2004 update installed.
I also recommend installing the Windows Terminal as this will make working with your Linux distro easier long term.
Enable Subsystem Features
Using PowerShell to enable the VM and Subsystem features.
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Install latest Linux kernel
Download and install the latest Linux kernel.
Set WSL 2 default
Using PowerShell as admin and run the following commands:
wsl --set-default-version 2
Install and Setup Linux Distro
Go to the window store and install the latest version of Ubuntu
Make sure the distro is using WSL 2
Using PowerShell to make sure the distro is using version 2.
wsl -l -v
Launch the distro.
Setup the admin user.
Install .Net Core SDK
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb sudo apt-get update sudo apt-get install apt-transport-https sudo apt-get update sudo apt-get install dotnet-sdk-3.1
sudo apt install ./google-chrome-stable_current_amd64.deb
Download and install VS Code from: https://code.visualstudio.com/
Add VS Code extensions
Add the C# and Remote WSL extensions.
Optionally you may want to install the .Net Core Test Explorer.
VS Code WSL setup
Connect to the distro
Click the remote icon in the lower left.
Select new window using distro.
Create and open work directory
Open the terminal.
Make a new working directory.
Open the working directory.
For this example we will be using an early release of MAQS 6 (https://github.com/Magenic/MAQS) which supports Mac and Linux out of the box. I have selected MAQS for this post because it creates easy/runnable tests without requiring me to write a lot of code.
Setup a MAQS project
Install the MAQS templates
dotnet new --install Magenic.Maqs.Templates
Create a new Selenium solution
Run: dotnet new Maqs.Selenium
dotnet new Maqs.Selenium
Updated the Browser setting in the appsettings.json file
Run your tests with the test explorer or CLI
Once you get over the initial hump of setting everything up, running your tests on the WSL 2 distro is very fast and easy.
Test run durations
Running 30 tests in parallel against headless Chrome