Playwright: Difference between revisions

Increased clarity, added summary of Playwright
Tags: Mobile edit Mobile web edit
Joshbuker (talk | contribs)
Fix shell.nix example not setting allowUnfree = true, which can cause it to fail in some situations
 
(6 intermediate revisions by 2 users not shown)
Line 8: Line 8:
An example <code>shell.nix</code> that installs [[ Visual Studio Code ]] and Playwright.
An example <code>shell.nix</code> that installs [[ Visual Studio Code ]] and Playwright.


<syntaxHighlight lang=nix>
<syntaxhighlight lang="nix">
{ pkgs ? import <nixpkgs> {} }:
{ pkgs ? import <nixpkgs> { config.allowUnfree = true; } }:
   pkgs.mkShell {
   pkgs.mkShell {
     nativeBuildInputs = with pkgs; [
     nativeBuildInputs = with pkgs; [
       vscode
       vscode # if you want vscode
       playwright-driver.browsers
      nodejs_latest
       playwright-driver.browsers # !!! Make sure it has the same version as npm's version!!
     ];
     ];


Line 19: Line 20:
       export PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-driver.browsers}
       export PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-driver.browsers}
       export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true
       export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true
       export PLAYWRIGHT_HOST_PLATFORM_OVERRIDE="ubuntu-24.04"
       export PLAYWRIGHT_HOST_PLATFORM_OVERRIDE="ubuntu-24.04" # Seems like it is not needed?
     '';
     '';
}
}
</syntaxhighlight>
{{Note|The version of Playwright in Nixpkgs and your node developer environment (in <code>package[-lock].json</code>) must match. See [https://www.nixhub.io/packages/playwright nixhub] to see if there is a version that matches npm in nixpkgs, if not you can also downgrade npm's version via <code>npm install playwright@nixversion</code>. See also [https://discourse.nixos.org/t/running-playwright-tests/25655 this discussion].}}
== Using flake ==
This can easily be adapted within a flake like:
<syntaxHighlight lang=nix>
{
  description = "A very basic flake";
  inputs = {
    flake-parts.url = "github:hercules-ci/flake-parts";
    nixpkgs.url = "github:nixos/nixpkgs";
  };
 
  outputs = { flake-parts, ... } @ inputs: flake-parts.lib.mkFlake { inherit inputs; } {
    perSystem = { config, self', inputs', pkgs, system, ... }: {
      devShells.default = pkgs.mkShell {
        nativeBuildInputs = with pkgs; [
          nodejs_latest
          playwright-driver.browsers
        ];
        shellHook = ''
          export PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-driver.browsers}
          export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true;
        '';
      };
    };
    # Declared systems that your flake supports. These will be enumerated in perSystem
    systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
  };
}
</syntaxHighlight>
</syntaxHighlight>
{{Note|The version of Playwright in Nixpkgs and your developer environment must match.}}


== Using Devenv ==
== Using Devenv ==
Line 269: Line 304:
</syntaxHighlight>
</syntaxHighlight>


=== Hints ===
=== Notes ===
* VSCode plugin playwright currently does not support bun. Stick to nodejs for now if you are a GUI guy.
* The [https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright Playwright Test for VSCode] extension does not currently support Bun. The Node.js runtime may be used instead.
* playwright version 1.58 seems to be the first version where the command <code>bun --bun playwright test</code> works
* Playwright version 1.58 is the first version where the command <code>bun --bun playwright test</code> works.
* see also https://github.com/MBanucu/bun-playwright-nix
* see also https://github.com/MBanucu/bun-playwright-nix