Playwright: Difference between revisions

add link
Tags: Mobile edit Mobile web edit
Tags: Mobile edit Mobile web edit
Line 33: Line 33:


{{Note|The version of Playwright in Nixpkgs and your node developer environment (in <code>package[-lock].json</code>) must match unless you define <code>PLAYWRIGHT_LAUNCH_OPTIONS_EXECUTABLE_PATH</code> as shown above to force playwright to use a different browser than the hardcoded version. See also [https://discourse.nixos.org/t/running-playwright-tests/25655 this discussion].}}
{{Note|The version of Playwright in Nixpkgs and your node developer environment (in <code>package[-lock].json</code>) must match unless you define <code>PLAYWRIGHT_LAUNCH_OPTIONS_EXECUTABLE_PATH</code> as shown above to force playwright to use a different browser than the hardcoded version. 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;
          export PLAYWRIGHT_NODEJS_PATH=${pkgs.nodejs_latest}/bin/node
          playwright_chromium_revision="$(${pkgs.jq}/bin/jq --raw-output '.browsers[] | select(.name == "chromium").revision' ${pkgs.playwright-driver}/browsers.json)"
          export PLAYWRIGHT_LAUNCH_OPTIONS_EXECUTABLE_PATH=${pkgs.playwright-driver.browsers}/chromium-$playwright_chromium_revision/chrome-linux/chrome
          echo "Using $PLAYWRIGHT_LAUNCH_OPTIONS_EXECUTABLE_PATH"
        '';
      };
    };
    # Declared systems that your flake supports. These will be enumerated in perSystem
    systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
  };
}
</syntaxHighlight>


== Using Devenv ==
== Using Devenv ==