@ricsam/isolate-playwright 0.0.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -43
- package/dist/cjs/index.cjs +737 -0
- package/dist/cjs/index.cjs.map +10 -0
- package/dist/cjs/package.json +5 -0
- package/dist/mjs/index.mjs +693 -0
- package/dist/mjs/index.mjs.map +10 -0
- package/dist/mjs/package.json +5 -0
- package/dist/types/index.d.ts +52 -0
- package/package.json +51 -6
package/README.md
CHANGED
|
@@ -1,45 +1,116 @@
|
|
|
1
1
|
# @ricsam/isolate-playwright
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
3
|
+
Playwright bridge for running browser tests in a V8 sandbox. Execute untrusted Playwright test code against a real browser page while keeping the test logic isolated.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import ivm from "isolated-vm";
|
|
7
|
+
import { chromium } from "playwright";
|
|
8
|
+
import { setupPlaywright, runPlaywrightTests } from "@ricsam/isolate-playwright";
|
|
9
|
+
|
|
10
|
+
// Create browser and page
|
|
11
|
+
const browser = await chromium.launch();
|
|
12
|
+
const page = await browser.newPage();
|
|
13
|
+
|
|
14
|
+
// Create isolate and context
|
|
15
|
+
const isolate = new ivm.Isolate();
|
|
16
|
+
const context = await isolate.createContext();
|
|
17
|
+
|
|
18
|
+
// Setup playwright bridge
|
|
19
|
+
const handle = await setupPlaywright(context, {
|
|
20
|
+
page,
|
|
21
|
+
timeout: 30000,
|
|
22
|
+
baseUrl: "https://example.com",
|
|
23
|
+
onNetworkRequest: (info) => console.log("Request:", info.url),
|
|
24
|
+
onNetworkResponse: (info) => console.log("Response:", info.status),
|
|
25
|
+
onConsoleLog: (level, ...args) => console.log(`[${level}]`, ...args),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Load and run untrusted test code
|
|
29
|
+
await context.eval(`
|
|
30
|
+
test("homepage loads correctly", async () => {
|
|
31
|
+
await page.goto("/");
|
|
32
|
+
const heading = page.getByRole("heading", { name: "Example Domain" });
|
|
33
|
+
await expect(heading).toBeVisible();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("can interact with elements", async () => {
|
|
37
|
+
const link = page.locator("a");
|
|
38
|
+
await expect(link).toBeVisible();
|
|
39
|
+
const text = await link.textContent();
|
|
40
|
+
expect(text).toContain("More information");
|
|
41
|
+
});
|
|
42
|
+
`);
|
|
43
|
+
|
|
44
|
+
// Run tests and get results
|
|
45
|
+
const results = await runPlaywrightTests(context);
|
|
46
|
+
console.log(`${results.passed}/${results.total} tests passed`);
|
|
47
|
+
|
|
48
|
+
// Cleanup
|
|
49
|
+
handle.dispose();
|
|
50
|
+
context.release();
|
|
51
|
+
isolate.dispose();
|
|
52
|
+
await browser.close();
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Injected Globals (in isolate):**
|
|
56
|
+
- `page` - Page object with navigation and locator methods
|
|
57
|
+
- `test(name, fn)` - Register a test
|
|
58
|
+
- `expect(actual)` - Assertion helper for locators and primitives
|
|
59
|
+
- `Locator` - Locator class for element interactions
|
|
60
|
+
|
|
61
|
+
**Page Methods:**
|
|
62
|
+
- `page.goto(url, options?)` - Navigate to URL
|
|
63
|
+
- `page.reload()` - Reload page
|
|
64
|
+
- `page.url()` - Get current URL (sync)
|
|
65
|
+
- `page.title()` - Get page title
|
|
66
|
+
- `page.content()` - Get page HTML
|
|
67
|
+
- `page.waitForSelector(selector, options?)` - Wait for element
|
|
68
|
+
- `page.waitForTimeout(ms)` - Wait for milliseconds
|
|
69
|
+
- `page.waitForLoadState(state?)` - Wait for load state
|
|
70
|
+
- `page.evaluate(script)` - Evaluate JS in browser context
|
|
71
|
+
- `page.locator(selector)` - Get locator by CSS selector
|
|
72
|
+
- `page.getByRole(role, options?)` - Get locator by ARIA role
|
|
73
|
+
- `page.getByText(text)` - Get locator by text content
|
|
74
|
+
- `page.getByLabel(label)` - Get locator by label
|
|
75
|
+
- `page.getByPlaceholder(text)` - Get locator by placeholder
|
|
76
|
+
- `page.getByTestId(id)` - Get locator by test ID
|
|
77
|
+
|
|
78
|
+
**Locator Methods:**
|
|
79
|
+
- `click()`, `dblclick()`, `hover()`, `focus()`
|
|
80
|
+
- `fill(text)`, `type(text)`, `clear()`, `press(key)`
|
|
81
|
+
- `check()`, `uncheck()`, `selectOption(value)`
|
|
82
|
+
- `textContent()`, `inputValue()`
|
|
83
|
+
- `isVisible()`, `isEnabled()`, `isChecked()`, `count()`
|
|
84
|
+
|
|
85
|
+
**Expect Matchers (for Locators):**
|
|
86
|
+
- `toBeVisible()`, `toBeEnabled()`, `toBeChecked()`
|
|
87
|
+
- `toContainText(text)`, `toHaveValue(value)`
|
|
88
|
+
- All matchers support `.not` modifier
|
|
89
|
+
|
|
90
|
+
**Expect Matchers (for Primitives):**
|
|
91
|
+
- `toBe(expected)`, `toEqual(expected)`
|
|
92
|
+
- `toBeTruthy()`, `toBeFalsy()`
|
|
93
|
+
- `toContain(item)`
|
|
94
|
+
|
|
95
|
+
**Handle Methods:**
|
|
96
|
+
- `dispose()` - Clean up event listeners
|
|
97
|
+
- `getConsoleLogs()` - Get captured browser console logs
|
|
98
|
+
- `getNetworkRequests()` - Get captured network requests
|
|
99
|
+
- `getNetworkResponses()` - Get captured network responses
|
|
100
|
+
- `clearCollected()` - Clear all collected data
|
|
101
|
+
|
|
102
|
+
**Test Results:**
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
interface PlaywrightExecutionResult {
|
|
106
|
+
passed: number;
|
|
107
|
+
failed: number;
|
|
108
|
+
total: number;
|
|
109
|
+
results: Array<{
|
|
110
|
+
name: string;
|
|
111
|
+
passed: boolean;
|
|
112
|
+
error?: string;
|
|
113
|
+
duration: number;
|
|
114
|
+
}>;
|
|
115
|
+
}
|
|
116
|
+
```
|