1.0.0 • Published 6 months ago

phaatak v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

phaatak

Introduction

phaatak is a Playwright-based package designed for handling multiple browser windows, tabs, contexts, and profiles. It extends Playwright's functionality by providing an intuitive function to manage sessions, automate tab switching, and persist user profiles across sessions.

Installation

To install phaatak, run:

npm install phaatak

Usage

1. Creating a New Context

import { test } from "@playwright/test";
import { createSession, stopBrowser } from "phaatak";

test("Creating a New Context, async () => {
    const [session, context] = await createSession("mySession");
});

2. Managing Multiple Tabs

test("Managing Multiple Tabs", async () => {
  const firstTab = await session.openTab("google", "https://www.google.com");
  const secondTab = await session.openTab("github", "https://github.com");
  await firstTab.bringToFront();
  await secondTab.bringToFront();
});

3. Handling New Windows

import { handleNewWindow } from "phaatak";
test("Handling New Windows", async () => {
  const windowPromise = handleNewWindow(sessionContext);
  await firstPage.getByTestId("newwindow").click();
  const newOpenedWindow: Page = await windowPromise;
  console.log("New window URL:", newOpenedWindow.url());
});

4. Saving and Loading Profiles

import { saveProfile } from "phaatak";
// after Login logic
await saveProfile("userProfileSession", "userProfileName");

const [restoredSession] = await createSession(
  "restoredSession",
  "userProfileName"
);
const restoredTab: Page = await restoredSession.openTab("dashboard", "URL");

5. Stop the Browser

test("Stop the Browser", async () => {
  await stopBrowser();
});

6. Close All The Tab

test("Close All The Tab", async () => {
  await session.closeAllTabs();
});

Reference

createSession(contextName: string, profileName?: string)

Creates a new session with an optional profile.

openTab(name: string, url?: string)

Open New Tab

handleNewWindow(context: BrowserContext)

Waits for a new window to open and returns it.

saveProfile(contextName: string, profileName: string)

Saves the session's state for later use.

stopBrowser()

Stops the browser and cleans up resources.

closeAllTabs()

Close all the tabs

phaatak-playwright-demo

For demo, visit the phaatak-playwright-demo repository.