Playwright: Difference between revisions

Tags: Mobile edit Mobile web edit
Using flake: In fact this was not working.
Tags: Mobile edit Mobile web edit
 
(One intermediate revision by the same user not shown)
Line 14: Line 14:
       vscode # if you want vscode
       vscode # if you want vscode
       nodejs_latest
       nodejs_latest
       playwright-driver.browsers
       playwright-driver.browsers # !!! Make sure it has the same version as npm's version!!
     ];
     ];


Line 21: Line 21:
       export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true
       export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true
       export PLAYWRIGHT_HOST_PLATFORM_OVERRIDE="ubuntu-24.04" # Seems like it is not needed?
       export PLAYWRIGHT_HOST_PLATFORM_OVERRIDE="ubuntu-24.04" # Seems like it is not needed?
      # These lines are needed if the npm-installed version of playwright (in package[-lock].json)
      # does not match the nix version of playwright contained in pkgs.
      # (by default each playwright version hardcoded a specific version of the browser for extra compatibility)
      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
     '';
     '';
}
}
</syntaxHighlight>
</syntaxHighlight>


{{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. 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 ==
== Using flake ==
Line 58: Line 51:
           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_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"
         '';
         '';
       };
       };