group tests using .describe

This commit is contained in:
MarconLP 2023-04-15 23:21:00 +02:00
parent d3723a3e75
commit 141c3e385c
No known key found for this signature in database
GPG key ID: A08A9C8B623F5EA5
4 changed files with 92 additions and 75 deletions

View file

@ -7,7 +7,7 @@
"dev": "next dev",
"postinstall": "prisma generate",
"lint": "next lint",
"test:e2e": "npm run db-seed && playwright test --workers 1 --headed",
"test:e2e": "npm run db-seed && playwright test --headed",
"db-seed": "NODE_ENV=development prisma db seed",
"start": "next start"
},

View file

@ -1,10 +1,12 @@
import { test, expect } from "@playwright/test";
test("should show logged in state on landing page", async ({ page }) => {
await page.goto("http://localhost:3000/");
await expect(
page.locator(
"div.flex.flex-col.items-center.gap-2 > div > p > span:nth-child(1)"
)
).toContainText("Logged in as E2E Account");
test.describe("landing", () => {
test("should show logged in state on landing page", async ({ page }) => {
await page.goto("http://localhost:3000/");
await expect(
page.locator(
"div.flex.flex-col.items-center.gap-2 > div > p > span:nth-child(1)"
)
).toContainText("Logged in as E2E Account");
});
});

View file

@ -1,32 +1,41 @@
import { test, expect } from "@playwright/test";
test("should be able to view videos", async ({ page }) => {
await page.goto("http://localhost:3000/");
await page
.getByRole("link", { name: "Go to Videos → The entire videos collection" })
.click();
await expect(page).toHaveURL("http://localhost:3000/videos");
});
test("no videos should exist", async ({ page }) => {
await page.goto("http://localhost:3000/videos");
await expect(page.locator("div.flex-start > div > span")).toContainText(
"You do not have any recordings."
);
});
test("can upload video", async ({ page }) => {
await page.goto("http://localhost:3000/videos");
await page.getByText("New video").click();
await page
.getByText("Drop files to Attach, or browse")
.setInputFiles("tests/assets/example_video.webm");
await page.getByRole("button", { name: "Upload" }).click();
await expect(page).toHaveURL(/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/, {
timeout: 30000,
test.describe("videos", () => {
test("should be able to view videos", async ({ page }) => {
await page.goto("http://localhost:3000/");
await page
.getByRole("link", {
name: "Go to Videos → The entire videos collection",
})
.click();
await expect(page).toHaveURL("http://localhost:3000/videos");
});
await page.click('[href="/videos"]');
await page.getByText("example_video.webm").click();
await expect(page).toHaveURL(/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/);
test("no videos should exist", async ({ page }) => {
await page.goto("http://localhost:3000/videos");
await expect(page.locator("div.flex-start > div > span")).toContainText(
"You do not have any recordings."
);
});
test("can upload video", async ({ page }) => {
await page.goto("http://localhost:3000/videos");
await page.getByText("New video").click();
await page
.getByText("Drop files to Attach, or browse")
.setInputFiles("tests/assets/example_video.webm");
await page.getByRole("button", { name: "Upload" }).click();
await expect(page).toHaveURL(
/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/,
{
timeout: 30000,
}
);
await page.click('[href="/videos"]');
await page.getByText("example_video.webm").click();
await expect(page).toHaveURL(
/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/
);
});
});

View file

@ -1,44 +1,50 @@
import { expect, test } from "@playwright/test";
test("should be able to view video", async ({ page }) => {
await page.goto("http://localhost:3000/videos");
await page.locator("div.grid > a:nth-child(1)").click();
await expect(page).toHaveURL(/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/);
test.describe("video", () => {
test("should be able to view video", async ({ page }) => {
await page.goto("http://localhost:3000/videos");
await page.locator("div.grid > a:nth-child(1)").click();
await expect(page).toHaveURL(
/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/
);
const video = page.locator("video");
expect(video).toBeTruthy();
await video.evaluate((v: HTMLVideoElement) => v.play());
const isPlaying = await video.evaluate((v: HTMLVideoElement) => !v.paused);
expect(isPlaying).toBe(true);
await video.click();
const isPaused = await video.evaluate((v: HTMLVideoElement) => v.paused);
expect(isPaused).toBe(true);
});
test("should be able to rename video", async ({ page }) => {
const randomTitle = "Random title " + Math.random().toString();
await page.goto("http://localhost:3000/videos");
await page.locator("div.grid > a:nth-child(1)").click();
await expect(page).toHaveURL(/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/);
await page.locator("button > svg").click();
await page.getByText("Rename").click();
await page.click("#title");
await page.fill("#title", randomTitle);
await page.getByText("Save").click();
expect(
await page.locator("div > span.text-lg.font-medium").textContent()
).toBe(randomTitle);
});
test("should be able to share video", async ({ page }) => {
await page.goto("http://localhost:3000/videos");
await page.locator("div.grid > a:nth-child(1)").click();
await expect(page).toHaveURL(/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/);
await page.getByText("Share").click();
await page.locator('div.mt-6 > button[role="switch"]').click();
await page.waitForTimeout(5000);
const video = page.locator("video");
expect(video).toBeTruthy();
await video.evaluate((v: HTMLVideoElement) => v.play());
const isPlaying = await video.evaluate((v: HTMLVideoElement) => !v.paused);
expect(isPlaying).toBe(true);
await video.click();
const isPaused = await video.evaluate((v: HTMLVideoElement) => v.paused);
expect(isPaused).toBe(true);
});
test("should be able to rename video", async ({ page }) => {
const randomTitle = "Random title " + Math.random().toString();
await page.goto("http://localhost:3000/videos");
await page.locator("div.grid > a:nth-child(1)").click();
await expect(page).toHaveURL(
/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/
);
await page.locator("button > svg").click();
await page.getByText("Rename").click();
await page.click("#title");
await page.fill("#title", randomTitle);
await page.getByText("Save").click();
expect(
await page.locator("div > span.text-lg.font-medium").textContent()
).toBe(randomTitle);
});
test("should be able to share video", async ({ page }) => {
await page.goto("http://localhost:3000/videos");
await page.locator("div.grid > a:nth-child(1)").click();
await expect(page).toHaveURL(
/http:\/\/localhost:3000\/share\/[A-Za-z0-9]+/
);
await page.getByText("Share").click();
await page.locator('div.mt-6 > button[role="switch"]').click();
});
});