-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixtures.ts
More file actions
80 lines (70 loc) · 2.49 KB
/
fixtures.ts
File metadata and controls
80 lines (70 loc) · 2.49 KB
1
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import {
test as base,
chromium,
Page,
type BrowserContext,
} from "@playwright/test";
import path from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
type ExtensionFixtures = {
context: BrowserContext;
newtab: Page;
};
export const getPreparedTab = async (context: BrowserContext) => {
const newtab = await context.newPage();
await newtab.goto("chrome://newtab");
await newtab.waitForSelector("#root > div > nav > svg");
await newtab.waitForSelector(".ProseMirror");
return newtab;
};
export const test = base.extend<ExtensionFixtures>({
context: async ({}, use) => {
const pathToExtension = path.join(__dirname, "../dist");
const context = await chromium.launchPersistentContext("", {
headless: false,
args: [
`--headless=new`,
`--disable-extensions-except=${pathToExtension}`,
`--load-extension=${pathToExtension}`,
],
});
await use(context);
await context.close();
},
newtab: async ({ context }, use) => {
const newtab = await getPreparedTab(context);
await use(newtab);
await newtab.close();
},
});
export { expect } from "@playwright/test";
import { Locator } from '@playwright/test';
/**
* Verifies that the Tiptap editor content contains the expected text.
*
* @param editorLocator - The Playwright locator for the editor element.
* @param expectedText - The text to verify is contained within the editor.
* @throws Error if the expected text is not found in the editor content.
*/
export async function contains(editorLocator: Locator, expectedText: string): Promise<void> {
const content = await editorLocator.innerText();
if (!content || !content.includes(expectedText)) {
throw new Error(`Expected text "${expectedText}" not found in editor content: "${content || ''}"`);
}
}
/**
* Verifies that the Tiptap editor content equals the expected text.
*
* @param editorLocator - The Playwright locator for the editor element.
* @param expectedText - The text to verify exactly matches the editor content.
* @throws Error if the editor content does not exactly match the expected text.
*/
export async function equals(editorLocator: Locator, expectedText: string): Promise<void> {
const content = await editorLocator.innerText();
if (content !== expectedText) {
throw new Error(`Editor content does not match. Expected: "${expectedText}", Found: "${content || ''}"`);
}
}