Playwright: Difference between revisions

imported>Pbek
Mention not installed browsers versions
Break out visual studio code part into its own section
Line 1: Line 1:
== Installing browsers for playwright under NixOS ==
== Installing browsers for playwright under NixOS ==
Normally, at first run, playwright will tell you to run <code>playwright install</code>. The purpose of this is to install browsers for you that it can then use for testing. The installation itself will technically work. Unfortunately, the installed browsers will not be suitable to be used inside NixOS. This is due to the fact that dependencies will not be at places where the browsers expect them to be. To mitigate this problem, nixpkgs has a package called <code>playwright-driver.browsers</code>. Before you start your script, make sure to set
 
Normally, at first run, [https://playwright.dev/ playwright] will tell you to run <code>playwright install</code>. The purpose of this is to install browsers for you that it can then use for testing. The installation itself will technically work. Unfortunately, the installed browsers will not be suitable to be used inside NixOS. This is due to the fact that dependencies will not be at places where the browsers expect them to be. To mitigate this problem, nixpkgs has a package called <code>playwright-driver.browsers</code>. Before you start your script, make sure to set
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
export PLAYWRIGHT_BROWSERS_PATH=/path/to/drivers
export PLAYWRIGHT_BROWSERS_PATH=/path/to/drivers
</syntaxHighlight>
</syntaxHighlight>


You can for example put this <code>shell.nix</code> in the directory with your playwright tests:
You can for example put this <code>shell.nix</code> in the directory with your playwright-related code:


<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
{ pkgs ? import <nixpkgs> {} }:
{ pkgs ? import <nixpkgs> {} }:
   pkgs.mkShell {
   pkgs.mkShell {
     nativeBuildInputs = with pkgs; [
     nativeBuildInputs = [
       vscode
       pkgs.playwright-driver.browsers
      playwright-driver.browsers
     ];
     ];


Line 22: Line 22:
</syntaxHighlight>
</syntaxHighlight>


You can then just run <code>nix-shell --run "code ."</code> to open Visual Studio Code in that directory.
== Playwright with Visual Studio Code ==
 
If you are using playwright with [https://wiki.nixos.org/wiki/Visual_Studio_Code Visual Studio Code], you may want to add <code>vscode</code> to the package list shown earlier. With Visual Studio Code installed you can run <code>nix-shell --run "code ."</code> to open your playwright-related directory.


Don't forget to install the <code>Playwright Test for VSCode</code> extension in Visual Studio Code.
Don't forget to install the <code>Playwright Test for VSCode</code> extension in Visual Studio Code.