Installation

Check-up PlayWright in the list of the native Debian packages:

apt-cache search elpa* | grep playwright 2>&1

There is no one appropriate enough, thus, just follow this manual, but using a separate virtual environment beforehand:

cd ~/.local/
ls -la 2>&1
virtualenv ViPlay
ls -la 2>&1
total 24
drwx------  6 alioth alioth 4096 Mar 22 09:45 .
drwxr-xr-x 23 alioth alioth 4096 Mar 22 09:56 ..
drwx------ 29 alioth alioth 4096 Mar 22 08:57 share
drwx------  3 alioth alioth 4096 Dec  4 18:21 state
drwxr-xr-x  4 alioth alioth 4096 Dec 12 14:52 venv0.1
drwxr-xr-x  4 alioth alioth 4096 Mar 22 09:45 VirtSel
created virtual environment CPython3.11.2.final.0-64 in 138ms
  creator CPython3Posix(dest=/home/alioth/.local/ViPlay, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/alioth/.local/share/virtualenv)
    added seed packages: pip==23.0.1, setuptools==66.1.1, wheel==0.38.4
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
total 28
drwx------  7 alioth alioth 4096 Mar 22 10:23 .
drwxr-xr-x 23 alioth alioth 4096 Mar 22 09:56 ..
drwx------ 29 alioth alioth 4096 Mar 22 08:57 share
drwx------  3 alioth alioth 4096 Dec  4 18:21 state
drwxr-xr-x  4 alioth alioth 4096 Dec 12 14:52 venv0.1
drwxr-xr-x  4 alioth alioth 4096 Mar 22 10:23 ViPlay
drwxr-xr-x  4 alioth alioth 4096 Mar 22 09:45 VirtSel

Preparations:

First of all lets activate our new venv:

(pyvenv-activate "~/.local/ViPlay/")

Check up already installed packages:

pip list 2>&1
Package    Version
---------- -------
pip        23.0.1
setuptools 66.1.1
wheel      0.38.4

Further, following the official documentation:

pip install pytest-playwright 2>&1
Collecting pytest-playwright
  Downloading pytest_playwright-0.4.4-py3-none-any.whl (10 kB)
Collecting playwright>=1.18
  Downloading playwright-1.42.0-py3-none-manylinux1_x86_64.whl (37.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 37.3/37.3 MB 492.0 kB/s eta 0:00:00
Collecting pytest<9.0.0,>=6.2.4
  Downloading pytest-8.1.1-py3-none-any.whl (337 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 337.4/337.4 kB 505.6 kB/s eta 0:00:00
Collecting pytest-base-url<3.0.0,>=1.0.0
  Downloading pytest_base_url-2.1.0-py3-none-any.whl (5.3 kB)
Collecting python-slugify<9.0.0,>=6.0.0
  Downloading python_slugify-8.0.4-py2.py3-none-any.whl (10 kB)
Collecting greenlet==3.0.3
  Downloading greenlet-3.0.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (620 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 620.0/620.0 kB 353.6 kB/s eta 0:00:00
Collecting pyee==11.0.1
  Downloading pyee-11.0.1-py3-none-any.whl (15 kB)
Collecting typing-extensions
  Using cached typing_extensions-4.10.0-py3-none-any.whl (33 kB)
Collecting iniconfig
  Downloading iniconfig-2.0.0-py3-none-any.whl (5.9 kB)
Collecting packaging
  Using cached packaging-24.0-py3-none-any.whl (53 kB)
Collecting pluggy<2.0,>=1.4
  Downloading pluggy-1.4.0-py3-none-any.whl (20 kB)
Collecting requests>=2.9
  Using cached requests-2.31.0-py3-none-any.whl (62 kB)
Collecting text-unidecode>=1.3
  Downloading text_unidecode-1.3-py2.py3-none-any.whl (78 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 78.2/78.2 kB 425.7 kB/s eta 0:00:00
Collecting charset-normalizer<4,>=2
  Using cached charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (140 kB)
Collecting idna<4,>=2.5
  Using cached idna-3.6-py3-none-any.whl (61 kB)
Collecting urllib3<3,>=1.21.1
  Using cached urllib3-2.2.1-py3-none-any.whl (121 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2024.2.2-py3-none-any.whl (163 kB)
Installing collected packages: text-unidecode, urllib3, typing-extensions, python-slugify, pluggy, packaging, iniconfig, idna, greenlet, charset-normalizer, certifi, requests, pytest, pyee, pytest-base-url, playwright, pytest-playwright
Successfully installed certifi-2024.2.2 charset-normalizer-3.3.2 greenlet-3.0.3 idna-3.6 iniconfig-2.0.0 packaging-24.0 playwright-1.42.0 pluggy-1.4.0 pyee-11.0.1 pytest-8.1.1 pytest-base-url-2.1.0 pytest-playwright-0.4.4 python-slugify-8.0.4 requests-2.31.0 text-unidecode-1.3 typing-extensions-4.10.0 urllib3-2.2.1

Obviously that the list of packages has augmented:

pip list 2>&1
Package            Version
------------------ --------
certifi            2024.2.2
charset-normalizer 3.3.2
greenlet           3.0.3
idna               3.6
iniconfig          2.0.0
packaging          24.0
pip                23.0.1
playwright         1.42.0
pluggy             1.4.0
pyee               11.0.1
pytest             8.1.1
pytest-base-url    2.1.0
pytest-playwright  0.4.4
python-slugify     8.0.4
requests           2.31.0
setuptools         66.1.1
text-unidecode     1.3
typing_extensions  4.10.0
urllib3            2.2.1
wheel              0.38.4

Next procedure is a time-consuming one, so I suggest to do it in Bash with activated virtual environment, surely. It depends, but sometimes requires more than 10 minutes to be done.

(ViPlay) alioth@Dell:~/.local$ playwright install Downloading Chromium 123.0.6312.4 (playwright build v1105) from https://playwright.azureedge.net/builds/chromium/1105/chromium-linux.zip 154.7 MiB [====================] 100% 0.0s Chromium 123.0.6312.4 (playwright build v1105) downloaded to home/alioth.cache/ms-playwright/chromium-1105 Downloading FFMPEG playwright build v1009 from https://playwright.azureedge.net/builds/ffmpeg/1009/ffmpeg-linux.zip 2.6 MiB [====================] 100% 0.0s FFMPEG playwright build v1009 downloaded to home/alioth.cache/ms-playwright/ffmpeg-1009 Downloading Firefox 123.0 (playwright build v1440) from https://playwright.azureedge.net/builds/firefox/1440/firefox-debian-12.zip 84.7 MiB [====================] 100% 0.0s Firefox 123.0 (playwright build v1440) downloaded to home/alioth.cache/ms-playwright/firefox-1440 Downloading Webkit 17.4 (playwright build v1983) from https://playwright.azureedge.net/builds/webkit/1983/webkit-debian-12.zip 85.7 MiB [====================] 100% 0.0s Webkit 17.4 (playwright build v1983) downloaded to home/alioth.cache/ms-playwright/webkit-1983

playwright install
pip list 2>&1
Package            Version
------------------ --------
certifi            2024.2.2
charset-normalizer 3.3.2
greenlet           3.0.3
idna               3.6
iniconfig          2.0.0
packaging          24.0
pip                23.0.1
playwright         1.42.0
pluggy             1.4.0
pyee               11.0.1
pytest             8.1.1
pytest-base-url    2.1.0
pytest-playwright  0.4.4
python-slugify     8.0.4
requests           2.31.0
setuptools         66.1.1
text-unidecode     1.3
typing_extensions  4.10.0
urllib3            2.2.1
wheel              0.38.4

Testing

Lets create a separate folder to test up PlayWright in a proper way:

pwd 2>&1
cd ~ 2>&1
pwd 2>&1
mkdir -p playwright/tests 2>&1
ls playwright 2>&1
/home/alioth/Git/0--key/org-pub
/home/alioth
tests
ls ~/playwright 2>&1
tests

And the Python file with a couple of pytest s inside:

import re
from playwright.sync_api import Page, expect

def test_has_title(page: Page):
    page.goto("https://playwright.dev/")

    # Expect a title "to contain" a substring.
    expect(page).to_have_title(re.compile("Playwright"))

def test_get_started_link(page: Page):
    page.goto("https://playwright.dev/")

    # Click the get started link.
    page.get_by_role("link", name="Get started").click()

    # Expects page to have a heading with the name of Installation.
    expect(page.get_by_role("heading", name="Installation")).to_be_visible()

Check up is it all on its place:

ls ~/playwright/tests 2>&1
test_example.py

Launch the pytest up!

cd ~/playwright/
pwd 2>&1
pytest 2>&1
/home/alioth/playwright
============================= test session starts ==============================
platform linux -- Python 3.11.2, pytest-8.1.1, pluggy-1.4.0
rootdir: /home/alioth/playwright
plugins: base-url-2.1.0, playwright-0.4.4
collected 2 items

tests/test_example.py ..                                                 [100%]

============================== 2 passed in 3.34s ===============================

Conclusion

Tests are run in headless mode meaning no browser UI will open up when running the tests. Results of the tests and test logs will be shown in the terminal.

Now, the output says loud and clear that it works as expected even inside Emacs Babel environment.