Skip to content

Commit

Permalink
test: Add path handling in Playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ax-sh committed Dec 3, 2024
1 parent f2d4f75 commit 91be70a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions __test__/puppet.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { expect, test } from "@playwright/test";
import path from "node:path";
import { fileURLToPath } from "node:url";

// Construct __dirname equivalent for ES modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

test.describe("Playwright Browser Testing", () => {
test("should navigate to a page and check title", async ({ page }) => {
Expand All @@ -14,18 +20,19 @@ test.describe("Playwright Browser Testing", () => {
});

test("should take a screenshot", async ({ page }) => {
const screenshotLocalFilePath = path.join(__dirname, "screenshot.png");
await page.goto("https://example.com");
await page.screenshot({ path: "screenshot.png" });
await page.screenshot({ path: screenshotLocalFilePath });
// Optionally check the file existence
const fs = await import("node:fs/promises");
const exists = await fs
.access("screenshot.png")
.access(screenshotLocalFilePath)
.then(() => true)
.catch(() => false);
expect(exists).toBe(true);
});
test("should download a pdf", async ({ page }) => {
const pdfLocalFilePath = "output.pdf";
const pdfLocalFilePath = path.join(__dirname, "output.pdf");
const core = await import("../api/core");
let url: string;
url = "https://example.com";
Expand Down

0 comments on commit 91be70a

Please sign in to comment.