vuls: init at 0.27.0
[NixPkgs.git] / nixos / tests / playwright-python.nix
blob0a5deecbb508bb1f2ba6b6fb6161b5d4a85af661
1 import ./make-test-python.nix (
2   { pkgs, ... }:
3   {
4     name = "playwright-python";
6     meta = with pkgs.lib.maintainers; {
7       maintainers = [ phaer ];
8     };
10     nodes.machine =
11       { pkgs, ... }:
12       {
13         environment.variables = {
14           NIX_MANUAL_DOCROOT = "file://${pkgs.nix.doc}/share/doc/nix/manual/index.html";
15           PLAYWRIGHT_BROWSERS_PATH = pkgs.playwright-driver.browsers;
16         };
17         environment.systemPackages = [
18           (pkgs.writers.writePython3Bin "test_playwright"
19             {
20               libraries = [ pkgs.python3Packages.playwright ];
21             }
22             ''
23               import sys
24               from playwright.sync_api import sync_playwright
25               from playwright.sync_api import expect
27               browsers = {
28                 "chromium": ["--headless", "--disable-gpu"],
29                 "firefox": [],
30                 "webkit": []
31               }
32               if len(sys.argv) != 3 or sys.argv[1] not in browsers.keys():
33                   print(f"usage: {sys.argv[0]} [{'|'.join(browsers.keys())}] <url>")
34                   sys.exit(1)
35               browser_name = sys.argv[1]
36               url = sys.argv[2]
37               browser_args = browsers.get(browser_name)
38               print(f"Running test on {browser_name} {' '.join(browser_args)}")
39               with sync_playwright() as p:
40                   browser = getattr(p, browser_name).launch(args=browser_args)
41                   context = browser.new_context()
42                   page = context.new_page()
43                   page.goto(url)
44                   expect(page.get_by_text("Nix Reference Manual")).to_be_visible()
45             ''
46           )
47         ];
48       };
50     testScript = ''
51       # FIXME: Webkit segfaults
52       for browser in ["firefox", "chromium"]:
53           with subtest(f"Render Nix Manual in {browser}"):
54               machine.succeed(f"test_playwright {browser} $NIX_MANUAL_DOCROOT")
55     '';
57   }