Skip to content

Commit

Permalink
test: add Playwright tests for browser functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ax-sh committed Dec 2, 2024
1 parent 26ac743 commit e59d3f3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
15 changes: 13 additions & 2 deletions api/core/core.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { describe, expect, it, test } from "bun:test";
const { chromium: playwright } = require("playwright-core");
const chromium = require("@sparticuz/chromium");

test("Check the page title of example.com", async (t) => {
const executablePath: string = await chromium.executablePath();
expect(executablePath).not.toBeEmpty();
const browser = await playwright.launch({
// args: chromium.args,
// executablePath: await chromium.executablePath(),
args: chromium.args,
// headless: chromium.headless,
// executablePath
});

const context = await browser.newContext();
Expand All @@ -16,3 +19,11 @@ test("Check the page title of example.com", async (t) => {

expect(pageTitle).toBe("Example Domain");
});

describe("PDF", () => {
it("should open browser", async () => {
const cloud = require("chrome-aws-lambda");
const executablePath = await cloud.executablePath;
expect(executablePath).toEqual(null);
});
});
2 changes: 1 addition & 1 deletion api/core/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./core";
export * from "./core";
23 changes: 23 additions & 0 deletions api/core/puppet.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { expect, test } from "@playwright/test";
test.describe("Playwright Browser Testing", () => {
test("should navigate to a page and check title", async ({ page }) => {
await page.goto("https://example.com");
const title = await page.title();
expect(title).toBe("Example Domain");
});

// test('should find an element and check its text', async ({ page }) => {
// await page.goto('https://example.com');
// const text = await page.locator('h1').innerText();
// expect(text).toBe('Example Domain');
// });
//
// test('should take a screenshot', async ({ page }) => {
// await page.goto('https://example.com');
// await page.screenshot({ path: 'screenshot.png' });
// // Optionally check the file existence
// const fs = await import('fs/promises');
// const exists = await fs.access('screenshot.png').then(() => true).catch(() => false);
// expect(exists).toBe(true);
// });
});
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions docs/ref.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://playwright.dev/docs/running-tests
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "module",
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@playwright/test": "^1.49.0",
"@types/bun": "latest"
},
"peerDependencies": {
Expand All @@ -12,7 +13,8 @@
"scripts": {
"dev": "ntl dev",
"format": "nr biome check --write",
"test": "bun test"
"test": "bun test",
"test:puppet": "nlx playwright test --headed puppet.test.ts"
},
"dependencies": {
"@netlify/functions": "^2.8.2",
Expand Down

0 comments on commit e59d3f3

Please sign in to comment.