Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve e2e tests flakiness #1115

Merged
merged 7 commits into from
Feb 21, 2025
Merged
18 changes: 16 additions & 2 deletions tests/helpers/instancePanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const startInstanceFromPanel = async (page: Page, instance: string) => {
});
const startButton = instanceDetailPanel.locator("css=button[title=Start]");
await startButton.click();
await page.waitForSelector(`text=Instance ${instance} started.`);
await checkInstanceStatus(page, instance, "Running");
};

export const stopInstanceFromPanel = async (page: Page, instance: string) => {
Expand All @@ -39,11 +39,12 @@ export const stopInstanceFromPanel = async (page: Page, instance: string) => {
await stopButton.click();
const confirmModal = page.locator("css=.p-modal");
await confirmModal.waitFor({ state: "visible" });
await page.getByText("Force stop").click();
const confirmStopButton = confirmModal.locator("css=button", {
hasText: "Stop",
});
await confirmStopButton.click();
await page.waitForSelector(`text=Instance ${instance} stopped.`);
await checkInstanceStatus(page, instance, "Stopped");
};

export const navigateToInstanceDetails = async (
Expand All @@ -62,3 +63,16 @@ export const navigateToInstanceDetails = async (
});
await expect(instanceDetailTitle).toBeVisible();
};

export const checkInstanceStatus = async (
page: Page,
instance: string,
status: string,
) => {
await page.waitForLoadState("networkidle");
await gotoURL(page, "/ui/");
await openInstancePanel(page, instance);
const sidePanel = page.getByLabel("Side panel");
const statusRow = sidePanel.getByRole("row", { name: "Status" });
await expect(statusRow.getByRole("cell", { name: status })).toBeVisible();
};
20 changes: 12 additions & 8 deletions tests/helpers/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,20 @@ export const createNetworkForward = async (page: Page, network: string) => {
await page.getByRole("link", { name: "Create forward" }).click();
await page.getByLabel("Listen address").fill(listenAddress);

let portInput = page.getByLabel("0 listen port");
let addressInput = page.getByLabel("0 target address");
await page.getByRole("button", { name: "Add port" }).click();
await page.getByLabel("0 listen port").click();
await page.keyboard.type("80");
await page.getByLabel("0 target address").click();
await page.keyboard.type(targetAddress);
await portInput.click();
await portInput.fill("80");
await addressInput.click();
await addressInput.fill(targetAddress);
await page.getByRole("button", { name: "Add port" }).click();
await page.getByLabel("1 listen port").click();
await page.keyboard.type("23,443-455");
await page.getByLabel("1 target address").click();
await page.keyboard.type(targetAddress);
portInput = page.getByLabel("1 listen port");
addressInput = page.getByLabel("1 target address");
await portInput.click();
await portInput.fill("23,443-455");
await addressInput.click();
await addressInput.fill(targetAddress);
await page.getByRole("button", { name: "Create" }).click();

await page.getByText(`Network forward ${listenAddress} created.`).click();
Expand Down
1 change: 1 addition & 0 deletions tests/helpers/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const randomProjectName = (): string => {

const openProjectCreationForm = async (page: Page) => {
await gotoURL(page, "/ui/");
await page.waitForLoadState("networkidle");
await page.getByRole("button", { name: "default" }).click();
await page.getByRole("button", { name: "Create project" }).click();
};
Expand Down
33 changes: 18 additions & 15 deletions tests/images.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@ test("search for custom image and create an instance from it", async ({
page,
}) => {
const customInstance = randomInstanceName();
const instance = randomInstanceName();
await createInstance(page, instance);
const imageAlias = await createImageFromInstance(page, instance);
const imageName = await getImageNameFromAlias(page, imageAlias);
await deleteInstance(page, instance);
let imageName: string = "";
try {
const instance = randomInstanceName();
await createInstance(page, instance);
const imageAlias = await createImageFromInstance(page, instance);
imageName = await getImageNameFromAlias(page, imageAlias);
await deleteInstance(page, instance);

await visitImages(page, "default");
await page.getByPlaceholder("Search").click();
await page.getByPlaceholder("Search").fill(imageAlias);
await page.getByRole("button", { name: "Create instance" }).first().click();
await page.getByLabel("Instance name").fill(customInstance);
await page.getByRole("button", { name: "Create", exact: true }).click();
await page.waitForSelector(`text=Created instance ${customInstance}.`);

await deleteInstance(page, customInstance);
await deleteImage(page, imageName);
await visitImages(page, "default");
await page.getByPlaceholder("Search").click();
await page.getByPlaceholder("Search").fill(imageAlias);
await page.getByRole("button", { name: "Create instance" }).first().click();
await page.getByLabel("Instance name").fill(customInstance);
await page.getByRole("button", { name: "Create", exact: true }).click();
await page.waitForSelector(`text=Created instance ${customInstance}.`);
} finally {
await deleteInstance(page, customInstance);
await deleteImage(page, imageName);
}
});

test("Export and Upload an image", async ({ page }) => {
Expand Down