Running 30 tests in parallel against headless Chrome
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.
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.
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
Reference: https://docs.microsoft.com/en-us/windows/wsl/install-win10
Download and install the latest Linux kernel.
Reference: https://docs.microsoft.com/en-us/windows/wsl/wsl2-kernel
Using PowerShell as admin and run the following commands:
wsl --set-default-version 2
Go to the window store and install the latest version of Ubuntu:
Using PowerShell to make sure the distro is using version 2.
wsl -l -v
Launch the distro.
Setup the admin user.
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
Reference: https://docs.microsoft.com/en-us/dotnet/core/install/linux-package-manager-ubuntu-2004
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb sudo apt install ./google-chrome-stable_current_amd64.deb
Download and install VS Code from: https://code.visualstudio.com/
Add the C# and Remote WSL extensions.
Optionally you may want to install the .Net Core Test Explorer.
Click the remote icon in the lower left.
Select new window using distro.
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.
dotnet new --install Magenic.Maqs.Templates
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.
dotnet test
Once you get over the initial hump of setting everything up, running your tests on the WSL 2 distro is very fast and easy.
UBUNTU | WINDOWS 10 |
---|---|
12.0812 | 57.5372 |
11.4818 | 60.162 |
11.0410 | 57.0518 |
11.5882 | 60.762 |
Running 30 tests in parallel against headless Chrome
One of our experts will be contacting you directly within the next business day.
Return To Home