fix flaky ffmpeg args e2e tests

The new tests clicked blindly to open Advanced and Output arguments, which could close a section that had just opened on its own for a pending change, and they clicked radios while the open animation was still running. Section and camera switches also raced the sidebar's 100ms optimistic switch and a camera form that looked the same on both cameras. The helpers now open a section only while it is collapsed, wait for collapsible animations to finish, wait for the FFmpeg form to unmount before switching back, and give Backyard its own input args so the test can tell which camera is on screen.
This commit is contained in:
Josh Hawkins
2026-12-02 16:29:32 -06:00
parent 6801150bc1
commit 974bca6e62
+58 -15
View File
@@ -10,6 +10,7 @@
import { readFileSync } from "node:fs"; import { readFileSync } from "node:fs";
import { resolve, dirname } from "node:path"; import { resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url"; import { fileURLToPath } from "node:url";
import type { Locator } from "@playwright/test";
import { test, expect, type FrigateApp } from "../../fixtures/frigate-test"; import { test, expect, type FrigateApp } from "../../fixtures/frigate-test";
import { import {
configFactory, configFactory,
@@ -586,14 +587,40 @@ const DEFAULT_MODE = "default";
const DEFAULTED_FIELDS = ["root_input_args", "root_output_args_record"]; const DEFAULTED_FIELDS = ["root_input_args", "root_output_args_record"];
const RECORD_SUB = "root_output_args_record_sub"; const RECORD_SUB = "root_output_args_record_sub";
const showOutputArgs = (app: FrigateApp) => // Sections also open on their own when a field inside them has a pending
app.page.getByText("Output arguments", { exact: true }).first().click(); // change, so a blind click can close one again. Clicks inside a section
// wait for its open animation to finish.
const expand = async (trigger: Locator) => {
await expect(async () => {
if ((await trigger.getAttribute("aria-expanded")) !== "true") {
await trigger.click();
}
await expect(trigger).toHaveAttribute("aria-expanded", "true", {
timeout: 1_000,
});
}).toPass();
await trigger.page().waitForFunction(() =>
document
.getAnimations()
.filter((animation) =>
(animation as CSSAnimation).animationName?.startsWith("collapsible"),
)
.every((animation) => animation.playState === "finished"),
);
};
const showOutputArgs = (app: FrigateApp) =>
expand(
app.page
.locator("[aria-expanded]")
.filter({ has: app.page.getByText("Output arguments", { exact: true }) }),
);
// A sidebar switch lands after a delay, so wait for the FFmpeg form before
// opening its sections.
const showGlobalArgs = async (app: FrigateApp) => { const showGlobalArgs = async (app: FrigateApp) => {
await app.page await expect(radio(app, "root_hwaccel_args", "auto")).toBeVisible();
.getByRole("button", { name: /Advanced/ }) await expand(app.page.getByRole("button", { name: /Advanced/ }).first());
.first()
.click();
await showOutputArgs(app); await showOutputArgs(app);
}; };
@@ -604,6 +631,14 @@ const switchSection = (app: FrigateApp, name: string) =>
}) })
.click(); .click();
// The sidebar commits a switch after a delay, and a second click before
// then cancels the first, so wait for the FFmpeg form to unmount.
const leaveFfmpegAndReturn = async (app: FrigateApp) => {
await switchSection(app, "Recording");
await expect(radio(app, "root_hwaccel_args", "auto")).toHaveCount(0);
await switchSection(app, "FFmpeg");
};
test.describe("ffmpeg default args @medium", () => { test.describe("ffmpeg default args @medium", () => {
test("global defaults show Default", async ({ frigateApp }) => { test("global defaults show Default", async ({ frigateApp }) => {
await openSettings(frigateApp, "/settings?page=globalFfmpeg"); await openSettings(frigateApp, "/settings?page=globalFfmpeg");
@@ -671,8 +706,7 @@ test.describe("ffmpeg default args @medium", () => {
await manualInput(frigateApp, field).fill("-x 1"); await manualInput(frigateApp, field).fill("-x 1");
await radio(frigateApp, field, DEFAULT_MODE).click(); await radio(frigateApp, field, DEFAULT_MODE).click();
} }
await switchSection(frigateApp, "Recording"); await leaveFfmpegAndReturn(frigateApp);
await switchSection(frigateApp, "FFmpeg");
await showGlobalArgs(frigateApp); await showGlobalArgs(frigateApp);
for (const field of DEFAULTED_FIELDS) { for (const field of DEFAULTED_FIELDS) {
@@ -693,8 +727,7 @@ test.describe("ffmpeg default args @medium", () => {
for (const field of DEFAULTED_FIELDS) { for (const field of DEFAULTED_FIELDS) {
await radio(frigateApp, field, DEFAULT_MODE).click(); await radio(frigateApp, field, DEFAULT_MODE).click();
} }
await switchSection(frigateApp, "Recording"); await leaveFfmpegAndReturn(frigateApp);
await switchSection(frigateApp, "FFmpeg");
await showGlobalArgs(frigateApp); await showGlobalArgs(frigateApp);
for (const field of DEFAULTED_FIELDS) { for (const field of DEFAULTED_FIELDS) {
await expect(radio(frigateApp, field, DEFAULT_MODE)).toBeChecked(); await expect(radio(frigateApp, field, DEFAULT_MODE)).toBeChecked();
@@ -748,24 +781,34 @@ test.describe("ffmpeg default args @medium", () => {
const capture = await openSettings( const capture = await openSettings(
frigateApp, frigateApp,
"/settings?page=cameraFfmpeg&camera=front_door", "/settings?page=cameraFfmpeg&camera=front_door",
{ ffmpeg: recordSub, cameras: { front_door: { ffmpeg: recordSub } } }, {
ffmpeg: recordSub,
cameras: {
front_door: { ffmpeg: recordSub },
backyard: { ffmpeg: { input_args: "-backyard 1" } },
},
},
); );
// Only Backyard has manual input args, which shows which camera's form
// is on screen.
const inputArgs = (mode: string) =>
radio(frigateApp, "root_input_args", mode);
const sameAsRecord = radio(frigateApp, RECORD_SUB, "inherit"); const sameAsRecord = radio(frigateApp, RECORD_SUB, "inherit");
await expect(inputArgs("inherit")).toBeChecked();
await showOutputArgs(frigateApp); await showOutputArgs(frigateApp);
await sameAsRecord.click(); await sameAsRecord.click();
await frigateApp.page await frigateApp.page
.getByRole("button", { name: "Select a camera" }) .getByRole("button", { name: "Select a camera" })
.click(); .click();
await frigateApp.page.getByRole("switch", { name: "Backyard" }).click(); await frigateApp.page.getByRole("switch", { name: "Backyard" }).click();
await expect(inputArgs("manual")).toBeChecked();
await frigateApp.page await frigateApp.page
.getByRole("button", { name: "Select a camera" }) .getByRole("button", { name: "Select a camera" })
.click(); .click();
await frigateApp.page.getByRole("switch", { name: "Front Door" }).click(); await frigateApp.page.getByRole("switch", { name: "Front Door" }).click();
await expect(radio(frigateApp, "root_input_args", "inherit")).toBeVisible(); await expect(inputArgs("inherit")).toBeChecked();
if (!(await sameAsRecord.isVisible())) { await showOutputArgs(frigateApp);
await showOutputArgs(frigateApp);
}
await expect(sameAsRecord).toBeChecked(); await expect(sameAsRecord).toBeChecked();
await save(frigateApp).click(); await save(frigateApp).click();