1 import ./make-test-python.nix ({ lib, ... }:
5 meta.maintainers = with lib.maintainers; [ jnsgruk ];
8 machine = { self, pkgs, lib, ... }: {
10 scrutiny.enable = true;
11 scrutiny.collector.enable = true;
14 environment.systemPackages =
16 seleniumScript = pkgs.writers.writePython3Bin "selenium-script"
18 libraries = with pkgs.python3Packages; [ selenium ];
20 from selenium import webdriver
21 from selenium.webdriver.common.by import By
22 from selenium.webdriver.firefox.options import Options
23 from selenium.webdriver.support.ui import WebDriverWait
24 from selenium.webdriver.support import expected_conditions as EC
27 options.add_argument("--headless")
28 service = webdriver.FirefoxService(executable_path="${lib.getExe pkgs.geckodriver}") # noqa: E501
30 driver = webdriver.Firefox(options=options, service=service)
31 driver.implicitly_wait(10)
32 driver.get("http://localhost:8080/web/dashboard")
34 wait = WebDriverWait(driver, 10).until(
35 EC.text_to_be_present_in_element(
36 (By.TAG_NAME, "body"), "Drive health at a glance")
39 body_text = driver.find_element(By.TAG_NAME, "body").text
40 assert "Temperature history for each device" in body_text
45 with pkgs; [ curl firefox-unwrapped geckodriver seleniumScript ];
48 # This is the test code that will check if our service is running correctly:
52 # Wait for Scrutiny to be available
53 machine.wait_for_unit("scrutiny")
54 machine.wait_for_open_port(8080)
56 # Ensure the API responds as we expect
57 output = machine.succeed("curl localhost:8080/api/health")
58 assert output == '{"success":true}'
60 # Start the collector service to send some metrics
61 collect = machine.succeed("systemctl start scrutiny-collector.service")
63 # Ensure the application is actually rendered by the Javascript
64 machine.succeed("PYTHONUNBUFFERED=1 selenium-script")