diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 22bedb8d8269..3e0c0a712643 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -785,6 +785,7 @@ in { plasma6 = handleTest ./plasma6.nix {}; plasma5-systemd-start = handleTest ./plasma5-systemd-start.nix {}; plausible = handleTest ./plausible.nix {}; + playwright-python = handleTest ./playwright-python.nix {}; please = handleTest ./please.nix {}; pleroma = handleTestOn [ "x86_64-linux" "aarch64-linux" ] ./pleroma.nix {}; plikd = handleTest ./plikd.nix {}; diff --git a/nixos/tests/playwright-python.nix b/nixos/tests/playwright-python.nix new file mode 100644 index 000000000000..0a5deecbb508 --- /dev/null +++ b/nixos/tests/playwright-python.nix @@ -0,0 +1,58 @@ +import ./make-test-python.nix ( + { pkgs, ... }: + { + name = "playwright-python"; + + meta = with pkgs.lib.maintainers; { + maintainers = [ phaer ]; + }; + + nodes.machine = + { pkgs, ... }: + { + environment.variables = { + NIX_MANUAL_DOCROOT = "file://${pkgs.nix.doc}/share/doc/nix/manual/index.html"; + PLAYWRIGHT_BROWSERS_PATH = pkgs.playwright-driver.browsers; + }; + environment.systemPackages = [ + (pkgs.writers.writePython3Bin "test_playwright" + { + libraries = [ pkgs.python3Packages.playwright ]; + } + '' + import sys + from playwright.sync_api import sync_playwright + from playwright.sync_api import expect + + browsers = { + "chromium": ["--headless", "--disable-gpu"], + "firefox": [], + "webkit": [] + } + if len(sys.argv) != 3 or sys.argv[1] not in browsers.keys(): + print(f"usage: {sys.argv[0]} [{'|'.join(browsers.keys())}] ") + sys.exit(1) + browser_name = sys.argv[1] + url = sys.argv[2] + browser_args = browsers.get(browser_name) + print(f"Running test on {browser_name} {' '.join(browser_args)}") + with sync_playwright() as p: + browser = getattr(p, browser_name).launch(args=browser_args) + context = browser.new_context() + page = context.new_page() + page.goto(url) + expect(page.get_by_text("Nix Reference Manual")).to_be_visible() + '' + ) + ]; + }; + + testScript = '' + # FIXME: Webkit segfaults + for browser in ["firefox", "chromium"]: + with subtest(f"Render Nix Manual in {browser}"): + machine.succeed(f"test_playwright {browser} $NIX_MANUAL_DOCROOT") + ''; + + } +) diff --git a/pkgs/development/python-modules/playwright/default.nix b/pkgs/development/python-modules/playwright/default.nix index 811aa8ce8243..6ad0fe9b1dc6 100644 --- a/pkgs/development/python-modules/playwright/default.nix +++ b/pkgs/development/python-modules/playwright/default.nix @@ -12,6 +12,7 @@ setuptools, setuptools-scm, playwright-driver, + nixosTests, nodejs, }: @@ -93,10 +94,14 @@ buildPythonPackage rec { passthru = { inherit driver; - tests = { - driver = playwright-driver; - browsers = playwright-driver.browsers; - }; + tests = + { + driver = playwright-driver; + browsers = playwright-driver.browsers; + } + // lib.optionalAttrs stdenv.isLinux { + inherit (nixosTests) playwright-python; + }; updateScript = ./update.sh; };