# Running playwright tests

**URL:** https://discourse.nixos.org/t/running-playwright-tests/25655
**Category:** Help
**Created:** [February 21, 2023, 4:11pm UTC](https://discourse.nixos.org/t/running-playwright-tests/25655 "2023-02-21T16:11:26Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![jmoggr](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jmoggr/32/8598_2.png) [@jmoggr](https://discourse.nixos.org/u/jmoggr)
#### Post date: [February 21, 2023, 4:11pm UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/1 "2023-02-21T16:11:26Z")

</div>

Hello,

I am unable to get playwright to run tests.

I am able to get the playwright cli command to run using the following commands:

```auto
export PLAYWRIGHT_BROWSERS_PATH=$(nix build --print-out-paths nixpkgs#playwright.browsers)
nix shell nixpkgs#playwright
playwright open nixos.org

```

However the playwright cli is missing the `test` command

Using playwright through npm/yarn also has problems:

`yarn playwright install-deps` expects apt, so it does not work

```auto
yarn playwright install
yarn playright test

```

produces errors like:

> ```
> browserType.launch: 
> ╔══════════════════════════════════════════════════════╗
> ║ Host system is missing dependencies to run browsers. 
> ║ Missing libraries:                                   
> ║ libgobject-2.0.so.0                              
> ║ libglib-2.0.so.0                                 
> 
> ```

```auto
export PLAYWRIGHT_BROWSERS_PATH=$(nix build --print-out-paths nixpkgs#playwright
.browsers)
yarn playwright test

```

produces errors like:

> Executable doesn’t exist at /nix/store/21isr8iwrdkhdhdyjw4jfxmwv0cn5zja-playwright-browsers/chromium-1045/chrome-linux/chrome

Short of a fix, is there a common workaround for problems like this? I often run into these kinds of problems when using npm/yarn and beating my head against nix is hurting my productivity.

Any help would be much appreciated.

Sources:

> <https://github.com/microsoft/playwright/issues/5501>
>
> \*\*Context:\*\*
> \- Playwright Version: 1.8.0
> \- Operating System: Linux
> \- Node.js …version: 12
> \- Browser: All
> 
> 
> \*\*Describe the bug\*\*
> 
> Running Playwright in Nix Shell throws \`missing dependencies\` error. Even after explicitly adding the missing dependencies suggested by "launch doctor", the same error is thrown. 
> 
> \`\`\`
> Error: browserType.launch: Host system is missing dependencies!
> \--
>   | Missing libraries we didn't find packages for:
>   | libexpat.so.1
>   | libxshmfence.so.1
> \`\`\`
> 
> Probably, I'm hitting this error from \[here\](https://github.com/microsoft/playwright/blob/a9faa9c941fa0b0383d68dff2fb7ef825bd258ea/src/server/validateDependencies.ts#L250). Nix has it's own \`ldconfig\` and it's not found in \`sbin\`.

> <https://github.com/NixOS/nixpkgs/issues/215450>
>
> \*\*\*DISCLAIMER: I just installed NixOS for the first time (about a week ago) and …I am IN LOVE!!! (and have a lot of passion right now) so excuse any over the top excitment\*\*\*
> 
> \### Steps To Reproduce
> 
> Steps to reproduce the behavior:
> 1. build \`playwright\` on NixOS via the \`configuration.nix\`
> 2. run the required \`playwright install\` command after install
> 3. you will get a warning that \`BEWARE: your OS is not officially supported by Playwright; downloading fallback build.\`
> 4. if you try to run any \`playwright\` commands after that you get the error (see at the end):
> 
> 
> \### Additional context
> 
> \[Here is the BUG on the playwright's github package\](https://github.com/microsoft/playwright/issues/5501)\](https://github.com/microsoft/playwright/issues/5501)
> 
> It sounds like they are willing to support NixOS if only someone from the Nix community will help them with the dependency management. 
> 
> \# (This is what Nix does best people! Let's do this!)
> 
> \### Notify maintainers
> 
> @techknowlogick 
> @yrd 
> @SuperSandro2000 
> 
> \### Metadata
> 
> 
> \`\`\`
> playwright open
> 
> ╔══════════════════════════════════════════════════════╗
> ║ Host system is missing dependencies to run browsers. ║
> ║ Missing libraries: ║
> ║ libgobject-2.0.so.0 ║
> ║ libglib-2.0.so.0 ║
> ║ libnss3.so ║
> ║ libnssutil3.so ║
> ║ libsmime3.so ║
> ║ libnspr4.so ║
> ║ libatk-1.0.so.0 ║
> ║ libatk-bridge-2.0.so.0 ║
> ║ libcups.so.2 ║
> ║ libgio-2.0.so.0 ║
> ║ libdrm.so.2 ║
> ║ libdbus-1.so.3 ║
> ║ libatspi.so.0 ║
> ║ libX11.so.6 ║
> ║ libXcomposite.so.1 ║
> ║ libXdamage.so.1 ║
> ║ libXext.so.6 ║
> ║ libXfixes.so.3 ║
> ║ libXrandr.so.2 ║
> ║ libgbm.so.1 ║
> ║ libexpat.so.1 ║
> ║ libxcb.so.1 ║
> ║ libxkbcommon.so.0 ║
> ║ libpango-1.0.so.0 ║
> ║ libcairo.so.2 ║
> ║ libasound.so.2 ║
> ║ libwayland-client.so.0 ║
> ╚══════════════════════════════════════════════════════╝
> 
> \`\`\`

---

<div class="post-metadata">

### Author: ![annymosse](https://discourse.nixos.org/user_avatar/discourse.nixos.org/annymosse/32/8606_2.png) [@annymosse](https://discourse.nixos.org/u/annymosse)
#### Post date: [February 22, 2023, 10:40am UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/2 "2023-02-22T10:40:46Z")

</div>

I’m facing same issues and after checking source code of the following packages : [python39Packages.playwright](https://search.nixos.org/packages?channel=22.11&from=0&size=50&sort=relevance&type=packages&query=playwright) , [playwright](https://search.nixos.org/packages?channel=22.11&from=0&size=50&sort=relevance&type=packages&query=playwright) and [python310Packages.playwright](https://search.nixos.org/packages?channel=22.11&from=0&size=50&sort=relevance&type=packages&query=playwright) I found all of them pointing into same source code [https://github.com/NixOS/nixpkgs/blob/a3d745e701c337e65ef467d5a9400d9336a303a1/pkgs/development/python-modules/playwright/default.nix](https://github.com/NixOS/nixpkgs/blob/a3d745e701c337e65ef467d5a9400d9336a303a1/pkgs/development/python-modules/playwright/default.nix) and it’s related to python only.

Also it still show the missed libs after including them:

```nix
  buildInputs = with nixpkgs; [
   ###### Playwright deps
    # libgobject-2.0.so.0
    # libglib-2.0.so.0
    # libgio-2.0.so.0
    glib
    # libnss3.so
    # libnssutil3.so
    # libsmime3.so
    nss
    # libnspr4.so
    nspr
    # libatk-1.0.so.0
    # libatk-bridge-2.0.so.0
    # libatspi.so.0
    at-spi2-core
    # libcups.so.2
    cups
    # libdrm.so.2
    libdrm
    # libdbus-1.so.3
    dbus
    # libX11.so.6
    xorg.libX11
    # libXcomposite.so.1
    xorg.libXcomposite
    # libXdamage.so.1
    xorg.libXdamage
    # libXext.so.6
    xorg.libXext
    # libXfixes.so.3
    xorg.libXfixes
    # libXrandr.so.2
    xorg.libXrandr
    # libgbm.so.1
    mesa
    # libexpat.so.1
    expat
    # libxcb.so.1
    xorg.libxcb
    # libxkbcommon.so.0
    libxkbcommon
    # libpango-1.0.so.0
    pango
    # libcairo.so.2
    cairo
    # libasound.so.2
    alsa-lib
    ######
   ....

```

---

<div class="post-metadata">

### Author: ![hnus](https://discourse.nixos.org/user_avatar/discourse.nixos.org/hnus/32/8304_2.png) [@hnus](https://discourse.nixos.org/u/hnus)
#### Post date: [March 19, 2023, 8:10pm UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/3 "2023-03-19T20:10:56Z")

</div>

It would be incredibly cool to be able to run playwright tests as part of `nix flake check`. The `testScript` attribute in `pkgs.nixosTest` is python code and playwright has python driver so it should be somehow possible no 🙂 ?

---

<div class="post-metadata">

### Author: ![teto](https://discourse.nixos.org/user_avatar/discourse.nixos.org/teto/32/182_2.png) [@teto](https://discourse.nixos.org/u/teto)
#### Post date: [April 27, 2023, 7:31pm UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/4 "2023-04-27T19:31:57Z")

</div>

I am new to playwright so I might miss something but here is what I found [Package request: playwright test · Issue #217693 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/issues/217693) , ie., for the tests I think you must use the typescript version of playwright ?

---

<div class="post-metadata">

### Author: ![aanderse](https://discourse.nixos.org/user_avatar/discourse.nixos.org/aanderse/32/1420_2.png) [@aanderse](https://discourse.nixos.org/u/aanderse)
#### Post date: [April 27, 2023, 9:55pm UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/5 "2023-04-27T21:55:00Z")

</div>

At work we’re using `python` with `playwright`, though not in NixOS tests (yet). No problems.

---

<div class="post-metadata">

### Author: ![teto](https://discourse.nixos.org/user_avatar/discourse.nixos.org/teto/32/182_2.png) [@teto](https://discourse.nixos.org/u/teto)
#### Post date: [April 27, 2023, 10:06pm UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/6 "2023-04-27T22:06:38Z")

</div>

but there is no `playwright test` command in hte python package:

```auto
➜ result/bin/playwright 
Usage: playwright [options] [command]

Options:
  -V, --version output the version number
  -h, --help display help for command

Commands:
  open [options] [url] open page in browser specified via -b, --browser
  codegen [options] [url] open page and generate code for user actions
  install [options] [browser...] ensure browsers necessary for this version of Playwright are installed
  install-deps [options] [browser...] install dependencies necessary to run browsers (will ask for sudo permissions)
  cr [options] [url] open page in Chromium
  ff [options] [url] open page in Firefox
  wk [options] [url] open page in WebKit
  screenshot [options] <url> <filename> capture a page screenshot
  pdf [options] <url> <filename> save page as pdf
  show-trace [options] [trace...] show trace viewer
  help [command] display help for command

```

what do you use it for ? do you write tests in python ? how do you launch them then ?

---

<div class="post-metadata">

### Author: ![aanderse](https://discourse.nixos.org/user_avatar/discourse.nixos.org/aanderse/32/1420_2.png) [@aanderse](https://discourse.nixos.org/u/aanderse)
#### Post date: [April 28, 2023, 12:14am UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/7 "2023-04-28T00:14:36Z")

</div>

`playwright` is used as a library in `python` with `pytest` and will spawn a browser based on its `python` API.

We have a `shell.nix` that looks like this:

```auto
let
  python' = python3.withPackages (p: with p; [
    lxml
    mixins
    playwright
    pytest
    pytest-playwright
    pytest-pytestrail
  ]);
in
mkShell {
  name = "pythonEnv";

  packages = [
    python'
  ];

  shellHook = ''
    export PLAYWRIGHT_BROWSERS_PATH=${playwright.browsers}
  '';
}

```

From the source directory you enter the shell and run `pytest` with some arguments and the `python` code runs.

---

<div class="post-metadata">

### Author: ![pbek](https://discourse.nixos.org/user_avatar/discourse.nixos.org/pbek/32/9122_2.png) [@pbek](https://discourse.nixos.org/u/pbek)
#### Post date: [April 28, 2023, 7:20am UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/8 "2023-04-28T07:20:32Z")

</div>

I currently use this `shell.nix` for JS:

```nix
{ pkgs ? import <nixpkgs> {} }:
  pkgs.mkShell {
    buildInputs = [
      pkgs.nodejs-18_x
      pkgs.playwright
    ];

    PLAYWRIGHT_BROWSERS_PATH="${pkgs.playwright-driver.browsers}";
  }

```

Note that there is no `playwright.browsers` anymore, now it’s `playwright-driver.browsers` (see [Build failure: playwright · Issue #215450 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/issues/215450#issuecomment-1526251592)).

I can then do a `playwright open nixos.org`, but I can’t run tests with npm or run a visual studio code instance for testing with the playwright extension. It always tells me to install the browsers with `npx playwright install`.

---

<div class="post-metadata">

### Author: ![teto](https://discourse.nixos.org/user_avatar/discourse.nixos.org/teto/32/182_2.png) [@teto](https://discourse.nixos.org/u/teto)
#### Post date: [April 28, 2023, 8:45am UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/9 "2023-04-28T08:45:07Z")

</div>

@pbek what if you try [playwright-test: init at 1.31.1 by teto · Pull Request #227071 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/pull/227071) ?

---

<div class="post-metadata">

### Author: ![pbek](https://discourse.nixos.org/user_avatar/discourse.nixos.org/pbek/32/9122_2.png) [@pbek](https://discourse.nixos.org/u/pbek)
#### Post date: [April 28, 2023, 10:48am UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/10 "2023-04-28T10:48:15Z")

</div>

Thank you, I’m on it!

---

<div class="post-metadata">

### Author: ![pbek](https://discourse.nixos.org/user_avatar/discourse.nixos.org/pbek/32/9122_2.png) [@pbek](https://discourse.nixos.org/u/pbek)
#### Post date: [November 3, 2023, 8:48am UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/11 "2023-11-03T08:48:30Z")

</div>

Currently, this `shell.nix` is working for me:

```nix
{ pkgs ? import <nixpkgs> {} }:
  pkgs.mkShell {
    # nativeBuildInputs is usually what you want -- tools you need to run
    nativeBuildInputs = with pkgs; [
      playwright-driver.browsers
    ];

    shellHook = ''
      export PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-driver.browsers}
      export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true
    '';
}

```

---

<div class="post-metadata">

### Author: ![jackdbd](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jackdbd/32/12315_2.png) [@jackdbd](https://discourse.nixos.org/u/jackdbd)
#### Post date: [January 10, 2024, 5:26pm UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/12 "2024-01-10T17:26:49Z")

</div>

It took me forever to figure this out, but finally I managed to get Playwright to work in a Node.js project.

## TL;DR:

- replace `playwright` with `playwright-core` in your dependencies
- set `executablePath` in you chromium launch options and point it to where it can find a chromium binary (run `which chromium` to figure this out)

## Full explanation

Let’s take this simple script `index.cjs` as an example.

```js
const { chromium } = require('playwright')

const main = async () => {
  const browser = await chromium.launch({
    headless: false
  })

  const ctx = await browser.newContext()
  const page = await ctx.newPage()
  await page.goto('https://www.reddit.com/r/NixOS/')
  await browser.close()
}

main()

```

If we try to execute the script with `node index.cjs`, we encounter an exception. It’s Playwright telling us that a bunch of shared objects are missing. To be more precise, when we are on any Linux distro it’s the [validateLinuxDependencies](https://github.com/microsoft/playwright/blob/19a4f15eb67fd82a0b78b12dd94e3564504f83f9/packages/playwright-core/src/server/registry/dependencies.ts#L188C23-L188C48) that throws this exception.

 ![playwright-dependenxies-nixos](https://discourse.nixos.org/uploads/default/original/2X/a/ae7c3b03afe8926bf9b830eae803bcc302b952cf.png)

By default, Playwright uses the **chromium revision it bundles with**. This is also what Puppeteer does.

### Why bundle a chromium revision?

The Playwright team (like the Puppeteer team) bundles a specific chromium revision so then they can focus on supporting only the specific chromium revision they bundle with (the chromium revision can be found in the [Playwright release notes](https://github.com/microsoft/playwright/blob/19a4f15eb67fd82a0b78b12dd94e3564504f83f9/docs/src/release-notes-js.md?plain=1#L158)).

### Where can we find the browsers used by Playwright?

As [they write in the documentation](https://playwright.dev/docs/browsers#managing-browser-binaries), on Linux all browsers bundled with Playwright are stored in `~/.cache/ms-playwright`.

### Double checking the required shared libraries

Now that we know where to find the browsers, we can double check which shared objects are required by the particular chromium revision used by Playwright:

```sh
ldd ~/.cache/ms-playwright/chromium-1091/chrome-linux/chrome

```

On my laptop (NixOS 24.05) I got this:

```sh
linux-vdso.so.1 (0x00007ffca03c5000)
libdl.so.2 => /nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-glibc-2.38-27/lib/libdl.so.2 (0x00007f2c90e98000)
libpthread.so.0 => /nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-glibc-2.38-27/lib/libpthread.so.0 (0x00007f2c90e93000)
libgobject-2.0.so.0 => not found
libglib-2.0.so.0 => not found
libnss3.so => not found
libnssutil3.so => not found
libsmime3.so => not found
libnspr4.so => not found
libdbus-1.so.3 => not found
libatk-1.0.so.0 => not found
libatk-bridge-2.0.so.0 => not found
libcups.so.2 => not found
libgio-2.0.so.0 => not found
libdrm.so.2 => not found
libexpat.so.1 => not found
libxcb.so.1 => not found
libxkbcommon.so.0 => not found
libatspi.so.0 => not found
libX11.so.6 => not found
libXcomposite.so.1 => not found
libXdamage.so.1 => not found
libXext.so.6 => not found
libXfixes.so.3 => not found
libXrandr.so.2 => not found
libgbm.so.1 => not found
libpango-1.0.so.0 => not found
libcairo.so.2 => not found
libasound.so.2 => not found
libm.so.6 => /nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-glibc-2.38-27/lib/libm.so.6 (0x00007f2c90da9000)
        libgcc_s.so.1 => /nix/store/ldrslljw4rg026nw06gyrdwl78k77vyq-xgcc-12.3.0-libgcc/lib/libgcc_s.so.1 (0x00007f2c90d88000)
libc.so.6 => /nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-glibc-2.38-27/lib/libc.so.6 (0x00007f2c81218000)
        /lib64/ld-linux-x86-64.so.2 => /nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-glibc-2.38-27/lib64/ld-linux-x86-64.so.2 (0x00007f2c90e9f000)

```

In fact, if we set `PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = true` in our nix shell and then try running `node index.cjs`, we bypass that nicely-formatted black box and get a more traditional stack trace. Here is the most relevant extract of the entire stack trace:

```sh
- <launched> pid=179437
- [pid=179437][err] Could not start dynamically linked executable: /home/jack/.cache/ms-playwright/chromium-1091/chrome-linux/chrome
- [pid=179437][err] NixOS cannot run dynamically linked executables intended for generic
- [pid=179437][err] linux environments out of the box. For more information, see:
- [pid=179437][err] https://nix.dev/permalink/stub-ld
- [pid=179437] <process did exit: exitCode=127, signal=null>
- [pid=179437] starting temporary directories cleanup

```

### 3 solutions and their pros and cons

Now that we have double-checked with `ldd` what `validateLinuxDependencies` already told us, we have a few options to make Playwright (and Nix) happy. I can think of at least three:

1. install all shared objects in one way or another. For example, if we know that a particular nixpkgs package includes a shared object, we can declare that package in our nix shell `packages`. For example, we can declare `pkgs.cairo` and `pkgs.pango` to obtain `libcairo.so.2` and `libpango-1.0.so.0`, respectively.
2. adopt the solution proposed by @pbek, namely add `pkgs.playwright-driver.browsers` to the `nativeBuildInputs` and set `export PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-driver.browsers}` in the shellHook (it doesn’t seem mandatory to set `export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = true` in the `shellHook`).
3. tell Playwright to use a version of chromium we explicitly specify, instead of the bundled one.

**Option 1** seems too complicated to me. In some cases it might be easy to figure out how to get the shared object from a package (e.g. `pkgs.cairo` =\> `libcairo.so.2`), but others are more challenging. Also, having to list all of these packages in the nix shell is annoying.

**Option 2** works, but it forces us to download and compile chromium (and maybe other browsers bundled with Playwright?). Downloading chromium is not a big deal, but compiling it takes forever (on my laptop it took an entire night).

**Option 3** works and, **as long as we have chromium on our machine** , doesn’t require us to compile chromium. Also, in [some cases](https://playwright.dev/docs/browsers#enterprise-policy) we might need to rely on features not provided by the chromium revision bundled with Playwright, so we would need to use a custom chromium anyway. Let’s go for this option then!

### Double checking the chromium revision installed via nixpkgs

I use Home Manager, and if I run `which chromium` I see that the chromium binary is at:

```sh
/home/jack/.nix-profile/bin/chromium

```

That location is actually a symlink, and if I run `ls -l /home/jack/.nix-profile/bin/` I see that on my laptop chromium is somewhere in the nix store:

```sh
/nix/store/8595809xjaq1a04djljzp3r3h9ham4z4-chromium-120.0.6099.129/bin/chromium

```

What’s the difference between the chromium revision used by Playwright and the chromium revision found in my nix store? The former is dynamically linked, the latter is statically linked. Let’s double check using `ldd`:

```sh
ldd $(which chromium)

```

We get: `not a dynamic executable`.

### Revisiting the JS script

Now that we have decided to **not** use the chromium revision bundled with Playwright, we can update the `index.cjs` script:

```js
const { chromium } = require('playwright-core')

const main = async () => {
  const browser = await chromium.launch({
    // tip: use `which chromium` to figure out where the chromium binary is
    executablePath: '/home/jack/.nix-profile/bin/chromium',
    headless: false
  })

  const ctx = await browser.newContext()
  const page = await ctx.newPage()
  await page.goto('https://www.reddit.com/r/NixOS/')
  await browser.close()
}

main()

```

Note: by declaring `playwright-core` instead of `playwright` in our `package.json`, we avoid downloading the chromium revision bundled with Playwright. Another way to avoid downloading chromium is to set [PLAYWRIGHT\_SKIP\_BROWSER\_DOWNLOAD=1](https://github.com/microsoft/playwright/issues/2905#issuecomment-660083858) before running `npm install`.

Finally, we can define a nix shell in this `flake.nix`:

```nix
{
  description = "Playwright demo";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
    # nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  };

  outputs = {
    nixpkgs,
    self,
    ...
  } @ inputs: let
    overlays = [
      (final: prev: {
        nodejs = prev.nodejs_20;
      })
    ];
    supportedSystems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
    forEachSupportedSystem = f:
      nixpkgs.lib.genAttrs supportedSystems (system:
        f {
          pkgs = import nixpkgs {inherit overlays system;};
        });
  in {
    devShells = forEachSupportedSystem ({pkgs}: {
      default = pkgs.mkShell {
        packages = with pkgs; [nodejs];

        shellHook = ''
          echo "welcome to this nix shell"
          echo "- Node.js $(node --version)"
          echo "- npm $(npm --version)"
          echo "- $(chromium --version)"
        '';
      };
    });
  };
}

```

We can also add an `.envrc` whose content is just:

```plaintext
use flake

```

Note 1: there is no need to set `PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = true` in this case, since there are no dynamic dependencies to check (because the chromium binary we specified in `executablePath` is a static executable).

Note 2: I’m still pretty new to Nix and haven’t quite figure out how to work with Node.js projects in a purely nix way, so for now I create nix shells which are **impure** and require to install npm dependencies by manually typing `npm install` the first time.

---

<div class="post-metadata">

### Author: ![ml21](https://discourse.nixos.org/user_avatar/discourse.nixos.org/ml21/32/12891_2.png) [@ml21](https://discourse.nixos.org/u/ml21)
#### Post date: [February 5, 2024, 5:28pm UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/13 "2024-02-05T17:28:20Z")

</div>

Thank you @jackdbd, your explanation very usefull for me.

For dotnet developers (like me), it is very convenient to use env variables instead of editing code:

```auto
❯ echo $PLAYWRIGHT_LAUNCH_OPTIONS_EXECUTABLE_PATH
/nix/store/g04zli5glz02jiknj701rb75wcc7xvcv-playwright-browsers-chromium/chromium-1091/chrome-linux/chrome

❯ dotnet test -- Playwright.LaunchOptions.ExecutablePath=$PLAYWRIGHT_LAUNCH_OPTIONS_EXECUTABLE_PATH

```

Simple flake.nix with dev env:

```auto
# run with
# nix develop .
{
  description = "dev env";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
  };

  outputs = { self, nixpkgs }: let
    system = "x86_64-linux";
    pkgs = import nixpkgs { inherit system; };
  in {
      devShells.${system}.default = pkgs.mkShell {
      packages = with pkgs; [
        nodejs
        dotnet-sdk_8
        playwright-driver.browsers
      ];

      PLAYWRIGHT_NODEJS_PATH = "${pkgs.nodejs}/bin/node";
      PLAYWRIGHT_LAUNCH_OPTIONS_EXECUTABLE_PATH = "${pkgs.playwright-driver.browsers}/chromium-1091/chrome-linux/chrome";

      shellHook = ''
        echo "dev env started"
        fish && echo "exit dev env" && exit
      '';
    };
  };
}

```

---

<div class="post-metadata">

### Author: ![Oudwins](https://discourse.nixos.org/user_avatar/discourse.nixos.org/oudwins/32/15993_2.png) [@Oudwins](https://discourse.nixos.org/u/Oudwins)
#### Post date: [March 11, 2024, 4:10pm UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/14 "2024-03-11T16:10:26Z")

</div>

> [@pbek](#):
>
> ```auto
> { pkgs ? import <nixpkgs> {} }:
> pkgs.mkShell {
> # nativeBuildInputs is usually what you want -- tools you need to run
> nativeBuildInputs = with pkgs; [
> playwright-driver.browsers
> ];
> 
> shellHook = ''
> export PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-driver.browsers}
> export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true
> '';
> }
> 
> ```

After trying @pbek 's suggestion when I run `npx playwright test` I still get the following error:  
Error: browserType.launch: Executable doesn’t exist at /nix/store/ahbg8nyn876ly0hpynidi987mhibqdnk-playwright-browsers-chromium/chromium-1105/chrome-linux/chrome

I get the same error even if I add on to the path as @jackdbd and ml21 suggested.

Is it currently working for anyone? Am I doing something wrong? Or is this just not working any more?

---

<div class="post-metadata">

### Author: ![pbek](https://discourse.nixos.org/user_avatar/discourse.nixos.org/pbek/32/9122_2.png) [@pbek](https://discourse.nixos.org/u/pbek)
#### Post date: [March 11, 2024, 6:34pm UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/15 "2024-03-11T18:34:29Z")

</div>

It’s important that your nix playwright and the playwright via NPM in your project are on the same version, otherwise the NPM playwright will try to access different browser versions. 😅

---

<div class="post-metadata">

### Author: ![feliciousx](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@feliciousx](https://discourse.nixos.org/u/feliciousx)
#### Post date: [March 11, 2024, 11:32pm UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/16 "2024-03-11T23:32:52Z")

</div>

i have a not-so-ideal setup that works

```auto
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/release-23.11";
    flake-utils.url = "github:numtide/flake-utils";
    flake-compat = {
      url = "github:edolstra/flake-compat";
      flake = false;
    };
  };

  outputs = { self, nixpkgs, flake-utils, flake-compat }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
        };
      in {
        devShells.default = pkgs.mkShell {
          nativeBuildInputs = [pkgs.bashInteractive];
          packages = pkgs.lib.attrVals [
            "nodejs_20"
            "playwright-test"
          ] pkgs;

          PLAYWRIGHT_BROWSERS_PATH="${pkgs.playwright-driver.browsers}";
        };
      });
}

```

then now i run `playwright test` directly on the cli instead of using `npx`

the only downside is that if `@playwright/test` in your `package.json` dependency, it will conflict

so I temporarily delete the `node_modules/@playwright/test` folder and playwright runs fine

the other caveat is the version mismatch between your `package.json`’s playwright vs what’s in nix

it’s ugly i know D:

---

<div class="post-metadata">

### Author: ![pbek](https://discourse.nixos.org/user_avatar/discourse.nixos.org/pbek/32/9122_2.png) [@pbek](https://discourse.nixos.org/u/pbek)
#### Post date: [March 12, 2024, 6:13am UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/17 "2024-03-12T06:13:55Z")

</div>

You can also pin the playwright version in the package.json lock file, but that’s ugly too, because everyone then needs to use your playwright version 😅

---

<div class="post-metadata">

### Author: ![Oudwins](https://discourse.nixos.org/user_avatar/discourse.nixos.org/oudwins/32/15993_2.png) [@Oudwins](https://discourse.nixos.org/u/Oudwins)
#### Post date: [March 12, 2024, 9:12am UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/18 "2024-03-12T09:12:14Z")

</div>

Omg… I figured it out, thank you. I am a dummy…

For those lost souls like me. Here is how you do that:

1. Check the version of playwright.drivers you are downloading (You can do so via de nixpkgs site)  

2. Pin that same version on the package manager you are using to install playwright

For npm

```json
    "@playwright/test": "1.38.0",

```

For dotnet

```xml
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.38.0" />

```

etc

Done, it should be working now!

---

<div class="post-metadata">

### Author: ![freelock](https://discourse.nixos.org/user_avatar/discourse.nixos.org/freelock/32/16126_2.png) [@freelock](https://discourse.nixos.org/u/freelock)
#### Post date: [March 14, 2024, 11:56pm UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/19 "2024-03-14T23:56:08Z")

</div>

This was a huge help! Finally got it working for a node app I’ve been fighting for a day.

I like the switch into fish here, that’s my preferred shell, and this worked fine with `nix develop`. But when I tried adding it with direnv to automatically load, it gets into a recursive loop, keeps respawning until I remove the .envrc file (somewhere else, because I can’t seem to interrupt this loop!)

What would need to change to make this work with direnv?

---

<div class="post-metadata">

### Author: ![freelock](https://discourse.nixos.org/user_avatar/discourse.nixos.org/freelock/32/16126_2.png) [@freelock](https://discourse.nixos.org/u/freelock)
#### Post date: [March 15, 2024, 12:01am UTC](https://discourse.nixos.org/t/running-playwright-tests/25655/20 "2024-03-15T00:01:32Z")

</div>

My working flake.nix:

```auto
{
  description = "dev env";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
  };

  outputs = { self, nixpkgs }: let
    system = "x86_64-linux";
    pkgs = import nixpkgs { inherit system; };
  in {
      devShells.${system}.default = pkgs.mkShell {
      packages = with pkgs; [
        nodejs
        playwright-driver.browsers
      ];

      PLAYWRIGHT_NODEJS_PATH = "${pkgs.nodejs}/bin/node";
      PLAYWRIGHT_BROWSERS_PATH = "${pkgs.playwright-driver.browsers}";
      PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = 1;

      shellHook = ''
        echo "dev env started"
        fish && echo "exit dev env" && exit
      '';
    };
  };
}

```

… with those extra environment flags, I was able to `npm install playwright-core@1.40.0 playwright-chromium@1.40.0` and then my node scripts started working!

Arrived here after my laptop was compiling Chromium all night, and was showing ~36000/55000 compiled late this morning when I finally killed it and found this thread… (I had tried forking nixpkgs and running the Playwright upgrade script to get to 1.43.2).

[Next page](https://discourse.nixos.org/t/running-playwright-tests/25655.md?page=2)
